diff --git a/src/httpserver/http_tcp_server.c b/src/httpserver/http_tcp_server.c index 9a300e60d..8cc83d4a0 100644 --- a/src/httpserver/http_tcp_server.c +++ b/src/httpserver/http_tcp_server.c @@ -27,11 +27,19 @@ void start_tcp_http() } } + +int sendfn(int fd, char * data, int len){ + if (fd){ + return send( fd, data, len, 0 ); + } + return -1; +} + static void tcp_client_thread( beken_thread_arg_t arg ) { OSStatus err = kNoErr; int fd = (int) arg; - int len = 0; + int lenrx = 0; //fd_set readfds, errfds, readfds2; char *buf = NULL; char *reply = NULL; @@ -47,9 +55,9 @@ static void tcp_client_thread( beken_thread_arg_t arg ) while ( 1 ) { - len = recv( fd, buf, 1024, 0 ); + lenrx = recv( fd, buf, 1024, 0 ); - if ( len <= 0 ) + if ( lenrx <= 0 ) { os_printf( "TCP Client is disconnected, fd: %d", fd ); goto exit; @@ -57,9 +65,16 @@ static void tcp_client_thread( beken_thread_arg_t arg ) //addLog( "TCP received string %s\n",buf ); // returns length to be sent if any - len = HTTP_ProcessPacket(buf, reply, replyBufferSize); - addLog( "TCP sending reply len %i\n",len ); - len = send( fd, reply, len, 0 ); + buf[lenrx] = 0; + int lenret = HTTP_ProcessPacket(buf, reply, replyBufferSize, sendfn, fd); + addLog( "TCP sending reply len %i\n",lenret ); + while(lenret){ + int len = lenret; + if (len > 1024) len = 1024; + send( fd, reply, len, 0 ); + reply += len; + lenret -= len; + } rtos_delay_milliseconds(10); close(fd); diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index f46fcf588..557b0b02e 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -210,7 +210,8 @@ const char *htmlPinRoleNames[] = { "LED", "LED_n", "PWM", - "e", + "Wifi LED", + "Wifi LED_n", "e", "e", }; @@ -262,7 +263,7 @@ void HTTP_AddBuildFooter(char *outbuf, int outBufSize) { strcat_safe(outbuf,"
",outBufSize); strcat_safe(outbuf,g_build_str,outBufSize); } -int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize) { +int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize, http_send_fn sendpart, int socket) { int i, j; char tmpA[128]; char tmpB[64]; @@ -688,6 +689,10 @@ int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize) { } } } + if (sendpart){ + sendpart(socket, outbuf, strlen(outbuf)); + outbuf[0] = 0; + } if(iChangedRequested>0) { PIN_SaveToFlash(); sprintf(tmpA, "Pins update - %i reqs, %i changed!

",iChangedRequested,iChanged); @@ -703,6 +708,10 @@ int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize) { strcat(outbuf,tmpA); sprintf(tmpA, ""); if(ch == 0) { @@ -720,6 +733,10 @@ int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize) { sprintf(tmpA, "",i,tmpB); strcat(outbuf,tmpA); strcat(outbuf,"
"); + if (sendpart){ + sendpart(socket, outbuf, strlen(outbuf)); + outbuf[0] = 0; + } } strcat(outbuf,""); @@ -868,5 +885,6 @@ int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize) { HTTP_AddBuildFooter(outbuf,outBufSize); strcat(outbuf,htmlEnd); } + i = strlen(outbuf); return i; } \ No newline at end of file diff --git a/src/httpserver/new_http.h b/src/httpserver/new_http.h index 0b6b8a31c..4806fc90b 100644 --- a/src/httpserver/new_http.h +++ b/src/httpserver/new_http.h @@ -7,7 +7,9 @@ extern const char htmlHeader[]; extern const char htmlEnd[]; extern const char htmlReturnToMenu[]; -int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize); +typedef int (*http_send_fn)(int fd, const char *payload, int len); + +int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize, http_send_fn send, int socket); void http_setup(char *o, const char *type);