diff --git a/src/httpserver/http_tcp_server.c b/src/httpserver/http_tcp_server.c index 0c25e226e..0bc91ccdb 100644 --- a/src/httpserver/http_tcp_server.c +++ b/src/httpserver/http_tcp_server.c @@ -1,3 +1,8 @@ +#if PLATFORM_XR809 +#define LWIP_COMPAT_SOCKETS 1 +#define LWIP_POSIX_SOCKETS_IO_NAMES 1 +#endif + #include "../new_common.h" #include "ctype.h" #include "lwip/sockets.h" @@ -5,18 +10,26 @@ #include "lwip/inet.h" #include "../logging/logging.h" #include "new_http.h" + #if PLATFORM_XR809 #define kNoErr 0 //! No error occurred. typedef void *beken_thread_arg_t; typedef int OSStatus; +#define close lwip_close + static OS_Thread_t g_http_thread; #else #include "str_pub.h" #endif + +#if PLATFORM_XR809 +#define DISABLE_SEPARATE_THREAD_FOR_EACH_TCP_CLIENT 1 +#endif + static void tcp_server_thread( beken_thread_arg_t arg ); static void tcp_client_thread( beken_thread_arg_t arg ); @@ -113,11 +126,15 @@ exit: os_free( reply ); close( fd );; +#if DISABLE_SEPARATE_THREAD_FOR_EACH_TCP_CLIENT + +#else #if PLATFORM_XR809 OS_ThreadDelete( NULL ); #else rtos_delete_thread( NULL ); #endif +#endif } /* TCP server listener thread */ @@ -152,16 +169,25 @@ static void tcp_server_thread( beken_thread_arg_t arg ) client_fd = accept( tcp_listen_fd, (struct sockaddr *) &client_addr, &sockaddr_t_size ); if ( client_fd >= 0 ) { +#if PLATFORM_XR809 + OS_Thread_t clientThreadUnused ; +#endif os_strcpy( client_ip_str, inet_ntoa( client_addr.sin_addr ) ); ADDLOG_DEBUG(LOG_FEATURE_HTTP, "TCP Client %s:%d connected, fd: %d", client_ip_str, client_addr.sin_port, client_fd ); +#if DISABLE_SEPARATE_THREAD_FOR_EACH_TCP_CLIENT + // Use main server thread (blocking all other clients) + // right now, I am getting OS_ThreadCreate everytime on XR809 platform + tcp_client_thread(client_fd); +#else + // Create separate thread for client if ( kNoErr != #if PLATFORM_XR809 - OS_ThreadCreate(&g_http_thread, + OS_ThreadCreate(&clientThreadUnused, "TCP Clients", tcp_client_thread, client_fd, OS_THREAD_PRIO_CONSOLE, - 0x800) + 0x400) #else rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY, @@ -173,9 +199,11 @@ static void tcp_server_thread( beken_thread_arg_t arg ) #endif ) { + ADDLOG_DEBUG(LOG_FEATURE_HTTP, "TCP Client %s:%d thread creation failed! fd: %d", client_ip_str, client_addr.sin_port, client_fd ); close( client_fd ); client_fd = -1; } +#endif } } } diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index 4c5ca9788..bccc9ea35 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -2,6 +2,7 @@ #include "../new_common.h" #include "ctype.h" +#include "lwip/sockets.h" #if WINDOWS //#include #include @@ -10,7 +11,6 @@ #include #else -#include "lwip/sockets.h" #include "str_pub.h" #endif #include "new_http.h" @@ -742,7 +742,13 @@ int HTTP_ProcessPacket(http_request_t *request) { } else { now = rem; } +#if PLATFORM_XR809 + res = 0; + now = 0; + rem = 0; +#else res = tuya_hal_flash_read (nowOfs, buffer,now); +#endif for(i = 0; i < now; i++) { sprintf(tmpA,"%02X ",buffer[i]); poststr(request,tmpA); @@ -1103,6 +1109,8 @@ int HTTP_ProcessPacket(http_request_t *request) { poststr(request,tmpB); #if WINDOWS +#elif PLATFORM_XR809 + #else otarequest(tmpA); #endif diff --git a/src/new_common.h b/src/new_common.h index afc8303de..1f84226c2 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -27,6 +27,14 @@ typedef int bool; typedef unsigned char u8; typedef unsigned char uint8_t; typedef unsigned int uint32_t; + +#define ASSERT +#define os_strcpy strcpy +#define os_malloc malloc +#define os_free free +#define os_memset memset + +#define rtos_delay_milliseconds OS_ThreadSleep #include #include