From 442ae80b874868efbcd930f217b43df24e383ee4 Mon Sep 17 00:00:00 2001 From: Ondraco Date: Mon, 29 Feb 2016 18:48:55 +0800 Subject: [PATCH] wince minor adaptations https://github.com/warmcat/libwebsockets/issues/444 --- lib/libwebsockets.c | 10 ++++++++++ lib/libwebsockets.h | 9 +++++++++ lib/lws-plat-win.c | 10 +++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index cb2b09b..056921e 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -20,7 +20,11 @@ */ #include "private-libwebsockets.h" + +#ifdef LWS_HAVE_SYS_TYPES_H #include +#endif + #if defined(WIN32) || defined(_WIN32) #else #include @@ -340,6 +344,9 @@ just_kill_connection: if (n) lwsl_debug("closing: shutdown ret %d\n", LWS_ERRNO); +// This causes problems with disconnection when the events are half closing connection +// FD_READ | FD_CLOSE (33) +#ifndef _WIN32_WCE /* libuv: no event available to guarantee completion */ if (!LWS_LIBUV_ENABLED(context)) { @@ -349,6 +356,7 @@ just_kill_connection: context->timeout_secs); return; } +#endif } #endif @@ -987,12 +995,14 @@ lwsl_timestamp(int level, char *p, int len) #endif int n; +#ifndef _WIN32_WCE #ifdef WIN32 ptm = localtime(&o_now); #else if (localtime_r(&o_now, &tm)) ptm = &tm; #endif +#endif p[0] = '\0'; for (n = 0; n < LLL_COUNT; n++) { if (level != (1 << n)) diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 6bb4a80..f38fc56 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -114,9 +114,18 @@ struct sockaddr_in; #include #include #include +#ifndef _WIN32_WCE #include +#else +#define _O_RDONLY 0x0000 +#define O_RDONLY _O_RDONLY +#endif +#ifdef _WIN32_WCE +#define strcasecmp _stricmp +#else #define strcasecmp stricmp +#endif #define getdtablesize() 30000 #define LWS_INLINE __inline diff --git a/lib/lws-plat-win.c b/lib/lws-plat-win.c index 6d731fc..428ae7c 100644 --- a/lib/lws-plat-win.c +++ b/lib/lws-plat-win.c @@ -271,7 +271,10 @@ lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd) u_long optl = 1; DWORD dwBytesRet; struct tcp_keepalive alive; + int protonbr; +#ifndef _WIN32_WCE struct protoent *tcp_proto; +#endif if (context->ka_time) { /* enable keepalive on this socket */ @@ -291,13 +294,18 @@ lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd) /* Disable Nagle */ optval = 1; +#ifndef _WIN32_WCE tcp_proto = getprotobyname("TCP"); if (!tcp_proto) { lwsl_err("getprotobyname() failed with error %d\n", LWS_ERRNO); return 1; } + protonbr = tcp_proto->p_proto; +#else + protonbr = 6; +#endif - setsockopt(fd, tcp_proto->p_proto, TCP_NODELAY, (const char *)&optval, optlen); + setsockopt(fd, protonbr, TCP_NODELAY, (const char *)&optval, optlen); /* We are nonblocking... */ ioctlsocket(fd, FIONBIO, &optl); -- 2.7.4