fix memory leak; increase send buffer

pull/7/head
Thorsten von Eicken 10 years ago
parent b816dbc497
commit c7c1d510ef
  1. 2
      Makefile
  2. 14
      httpd/httpd.c
  3. 4
      user/cgi.c

@ -59,7 +59,7 @@ DATE := $(shell date '+%F %T')
BRANCH := $(shell git describe --tags) BRANCH := $(shell git describe --tags)
SHA := $(shell if git diff --quiet HEAD; then git rev-parse --short HEAD | cut -d"/" -f 3; \ SHA := $(shell if git diff --quiet HEAD; then git rev-parse --short HEAD | cut -d"/" -f 3; \
else echo "development"; fi) else echo "development"; fi)
VERSION ?="esp-link $(BRANCH) - $(DATE) - \#$(SHA)" VERSION ?=esp-link $(BRANCH) - $(DATE) - $(SHA)
# --------------- esphttpd config options --------------- # --------------- esphttpd config options ---------------

@ -23,7 +23,7 @@ Esp8266 http server - core routines
//Max post buffer len //Max post buffer len
#define MAX_POST 1024 #define MAX_POST 1024
//Max send buffer len //Max send buffer len
#define MAX_SENDBUFF_LEN 2048 #define MAX_SENDBUFF_LEN 2600
//This gets set at init time. //This gets set at init time.
@ -235,7 +235,10 @@ int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) {
//Returns 1 for success, 0 for out-of-memory. //Returns 1 for success, 0 for out-of-memory.
int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len) { int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len) {
if (len<0) len=strlen(data); if (len<0) len=strlen(data);
if (conn->priv->sendBuffLen+len>MAX_SENDBUFF_LEN) return 0; if (conn->priv->sendBuffLen+len>MAX_SENDBUFF_LEN) {
os_printf("ERROR! httpdSend full (%d of %d)\n", conn->priv->sendBuffLen, MAX_SENDBUFF_LEN);
return 0;
}
os_memcpy(conn->priv->sendBuff+conn->priv->sendBuffLen, data, len); os_memcpy(conn->priv->sendBuff+conn->priv->sendBuffLen, data, len);
conn->priv->sendBuffLen+=len; conn->priv->sendBuffLen+=len;
return 1; return 1;
@ -244,7 +247,10 @@ int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len)
//Helper function to send any data in conn->priv->sendBuff //Helper function to send any data in conn->priv->sendBuff
static void ICACHE_FLASH_ATTR xmitSendBuff(HttpdConnData *conn) { static void ICACHE_FLASH_ATTR xmitSendBuff(HttpdConnData *conn) {
if (conn->priv->sendBuffLen!=0) { if (conn->priv->sendBuffLen!=0) {
espconn_sent(conn->conn, (uint8_t*)conn->priv->sendBuff, conn->priv->sendBuffLen); sint8 status = espconn_sent(conn->conn, (uint8_t*)conn->priv->sendBuff, conn->priv->sendBuffLen);
if (status != 0) {
os_printf("ERROR! espconn_sent returned %d\n", status);
}
conn->priv->sendBuffLen=0; conn->priv->sendBuffLen=0;
} }
} }
@ -517,6 +523,8 @@ static void ICACHE_FLASH_ATTR httpdConnectCb(void *arg) {
espconn_regist_reconcb(conn, httpdReconCb); espconn_regist_reconcb(conn, httpdReconCb);
espconn_regist_disconcb(conn, httpdDisconCb); espconn_regist_disconcb(conn, httpdDisconCb);
espconn_regist_sentcb(conn, httpdSentCb); espconn_regist_sentcb(conn, httpdSentCb);
espconn_set_opt(conn, ESPCONN_REUSEADDR|ESPCONN_NODELAY);
} }
//Httpd initialization routine. Call this to kick off webserver functionality. //Httpd initialization routine. Call this to kick off webserver functionality.

@ -101,6 +101,8 @@ int ICACHE_FLASH_ATTR printNav(char *buff) {
" <li class=\"pure-menu-item\"><a href=\"%s\" class=\"pure-menu-link\">%s</a></li>", " <li class=\"pure-menu-item\"><a href=\"%s\" class=\"pure-menu-link\">%s</a></li>",
navLinks[i][1], navLinks[i][0]); navLinks[i][1], navLinks[i][0]);
} }
len += os_sprintf(buff+len, " <li class=\"pure-menu-item\">%dKB</li>",
system_get_free_heap_size()/1024);
//os_printf("nav(%d): %s\n", len, buff); //os_printf("nav(%d): %s\n", len, buff);
return len; return len;
} }
@ -110,7 +112,6 @@ void ICACHE_FLASH_ATTR printHead(HttpdConnData *connData) {
struct EspFsFile *file = espFsOpen("/head.tpl"); struct EspFsFile *file = espFsOpen("/head.tpl");
if (file == NULL) { if (file == NULL) {
espFsClose(file);
os_printf("Header file 'head.tpl' not found\n"); os_printf("Header file 'head.tpl' not found\n");
return; return;
} }
@ -136,6 +137,7 @@ void ICACHE_FLASH_ATTR printHead(HttpdConnData *connData) {
httpdSend(connData, buff, len); httpdSend(connData, buff, len);
} }
} }
espFsClose(file);
} }
#define TOKEN(x) (os_strcmp(token, x) == 0) #define TOKEN(x) (os_strcmp(token, x) == 0)

Loading…
Cancel
Save