make sendBuffer static part of connData

master
Ondřej Hruška 2 years ago
parent 5b343dd687
commit 38eb26f9fa
  1. 2
      spritehttpd/include/httpd-types.h
  2. 27
      spritehttpd/src/httpd.c

@ -89,7 +89,7 @@ struct HttpdPriv {
char head[HTTPD_MAX_HEAD_LEN]; char head[HTTPD_MAX_HEAD_LEN];
char corsToken[HTTPD_MAX_CORS_TOKEN_LEN]; char corsToken[HTTPD_MAX_CORS_TOKEN_LEN];
size_t headPos; size_t headPos;
uint8_t *sendBuff; uint8_t sendBuff[HTTPD_MAX_SENDBUFF_LEN];
size_t sendBuffLen; size_t sendBuffLen;
char *chunkHdr; char *chunkHdr;
HttpdSendBacklogItem *sendBacklog; HttpdSendBacklogItem *sendBacklog;

@ -488,8 +488,6 @@ void httpdContinue(HttpdConnData *conn)
{ {
httpdPlatLock(); httpdPlatLock();
uint8_t *sendBuff;
if (conn == NULL) { return; } if (conn == NULL) { return; }
if (conn->priv.sendBacklog != NULL) { if (conn->priv.sendBacklog != NULL) {
@ -516,13 +514,6 @@ void httpdContinue(HttpdConnData *conn)
return; return;
} }
sendBuff = httpdMalloc(HTTPD_MAX_SENDBUFF_LEN);
if (sendBuff == NULL) {
http_error("Malloc of sendBuff failed!");
httpdPlatUnlock();
return;
}
conn->priv.sendBuff = sendBuff;
conn->priv.sendBuffLen = 0; conn->priv.sendBuffLen = 0;
httpd_cgi_state r = conn->cgi(conn); //Execute cgi fn. httpd_cgi_state r = conn->cgi(conn); //Execute cgi fn.
if (r == HTTPD_CGI_DONE) { if (r == HTTPD_CGI_DONE) {
@ -533,7 +524,6 @@ void httpdContinue(HttpdConnData *conn)
httpdCgiIsDone(conn); httpdCgiIsDone(conn);
} }
httpdFlushSendBuffer(conn); httpdFlushSendBuffer(conn);
httpdFree(sendBuff);
httpdPlatUnlock(); httpdPlatUnlock();
} }
@ -732,12 +722,6 @@ static void httpdParseHeader(char *h, HttpdConnData *conn)
void httpdConnSendStart(HttpdConnData *conn) void httpdConnSendStart(HttpdConnData *conn)
{ {
httpdPlatLock(); httpdPlatLock();
uint8_t *sendBuff = httpdMalloc(HTTPD_MAX_SENDBUFF_LEN);
if (sendBuff == NULL) {
http_error("Malloc sendBuff failed!");
return;
}
conn->priv.sendBuff = sendBuff;
conn->priv.sendBuffLen = 0; conn->priv.sendBuffLen = 0;
} }
@ -745,8 +729,6 @@ void httpdConnSendStart(HttpdConnData *conn)
void httpdConnSendFinish(HttpdConnData *conn) void httpdConnSendFinish(HttpdConnData *conn)
{ {
if (conn->conn) { httpdFlushSendBuffer(conn); } if (conn->conn) { httpdFlushSendBuffer(conn); }
httpdFree(conn->priv.sendBuff);
conn->priv.sendBuff = NULL;
httpdPlatUnlock(); httpdPlatUnlock();
} }
@ -764,14 +746,6 @@ void httpdRecvCb(ConnTypePtr rconn, httpd_ipaddr_t remIp, uint16_t remPort, uint
return; return;
} }
uint8_t *sendBuff = httpdMalloc(HTTPD_MAX_SENDBUFF_LEN);
if (sendBuff == NULL) {
http_error("Malloc sendBuff failed!");
httpdPlatUnlock();
return;
}
conn->priv.sendBuff = sendBuff;
conn->priv.sendBuffLen = 0; conn->priv.sendBuffLen = 0;
conn->priv.corsToken[0] = 0; conn->priv.corsToken[0] = 0;
@ -853,7 +827,6 @@ void httpdRecvCb(ConnTypePtr rconn, httpd_ipaddr_t remIp, uint16_t remPort, uint
if (conn->conn) { if (conn->conn) {
httpdFlushSendBuffer(conn); httpdFlushSendBuffer(conn);
} }
httpdFree(sendBuff);
httpdPlatUnlock(); httpdPlatUnlock();
} }

Loading…
Cancel
Save