From 63ff120ba53ad4e832e6ebd41ef7ab9f76038fa2 Mon Sep 17 00:00:00 2001 From: Joakim Soderberg Date: Mon, 11 Feb 2013 17:52:23 +0100 Subject: [PATCH] Fixed compilation on Windows. --- lib/client.c | 4 ++++ lib/libwebsockets.c | 18 +++++++++++++++--- lib/libwebsockets.h | 2 +- lib/server-handshake.c | 8 +++++++- lib/server.c | 1 + libwebsockets-api-doc.html | 4 ---- test-server/test-fraggle.c | 6 +++--- test-server/test-server.c | 6 +++--- 8 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/client.c b/lib/client.c index aa70bfe..c3fb2e8 100644 --- a/lib/client.c +++ b/lib/client.c @@ -841,7 +841,11 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context, /* prepare the expected server accept response */ +#ifdef WIN32 + n = _snprintf(buf, sizeof(buf), "%s%s", key_b64, magic_websocket_guid); +#else n = snprintf(buf, sizeof(buf), "%s%s", key_b64, magic_websocket_guid); +#endif buf[sizeof(buf) - 1] = '\0'; SHA1((unsigned char *)buf, n, (unsigned char *)hash); diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 3889fdf..c905d83 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -24,6 +24,7 @@ #ifdef WIN32 #include #include +#include #else #ifdef LWS_BUILTIN_GETIFADDRS #include @@ -572,7 +573,18 @@ int lws_set_socket_options(struct libwebsocket_context *context, int fd) * didn't find a way to set these per-socket, need to * tune kernel systemwide values */ - +#elif WIN32 + { + DWORD dwBytesRet; + struct tcp_keepalive alive; + alive.onoff = TRUE; + alive.keepalivetime = context->ka_time; + alive.keepaliveinterval = context->ka_interval; + + if (WSAIoctl(fd, SIO_KEEPALIVE_VALS, &alive, sizeof(alive), + NULL, 0, &dwBytesRet, NULL, NULL)) + return 1; + } #else /* set the keepalive conditions we want on it too */ optval = context->ka_time; @@ -2053,10 +2065,10 @@ libwebsocket_create_context(struct lws_context_creation_info *info) bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; - if (info->interface == NULL) + if (info->iface == NULL) serv_addr.sin_addr.s_addr = INADDR_ANY; else - interface_to_sa(info->interface, &serv_addr, + interface_to_sa(info->iface, &serv_addr, sizeof(serv_addr)); serv_addr.sin_port = htons(info->port); diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index ffa4896..d3b5215 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -771,7 +771,7 @@ struct libwebsocket_extension { struct lws_context_creation_info { int port; - const char *interface; + const char *iface; struct libwebsocket_protocols *protocols; struct libwebsocket_extension *extensions; const char *ssl_cert_filepath; diff --git a/lib/server-handshake.c b/lib/server-handshake.c index 2feca06..ba52037 100644 --- a/lib/server-handshake.c +++ b/lib/server-handshake.c @@ -56,7 +56,13 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi) goto bail; } - n = snprintf((char *)context->service_buffer, + // TODO: Use a truly platform independent snprintf implementation isntead! http://www.ijs.si/software/snprintf/ maybe? + #ifdef WIN32 + n = _snprintf( + #else + n = snprintf( + #endif + (char *)context->service_buffer, sizeof(context->service_buffer), "%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11", lws_hdr_simple_ptr(wsi, WSI_TOKEN_KEY)); diff --git a/lib/server.c b/lib/server.c index 1b10a86..3e81290 100644 --- a/lib/server.c +++ b/lib/server.c @@ -374,3 +374,4 @@ int lws_server_socket_service(struct libwebsocket_context *context, } return 0; } + diff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html index 5b05c36..a07df43 100644 --- a/libwebsockets-api-doc.html +++ b/libwebsockets-api-doc.html @@ -971,7 +971,6 @@ all sessions, etc, if it wants

struct lws_context_creation_info -

struct lws_context_creation_info {
    int port;
-    const char * interface;
    struct libwebsocket_protocols * protocols;
    struct libwebsocket_extension * extensions;
    const char * ssl_cert_filepath;
@@ -991,9 +990,6 @@ all sessions, etc, if it wants
Port to listen on... you can use 0 to suppress listening on any port, that's what you want if you are not running a websocket server at all but just using it as a client -
interface -
NULL to bind the listen socket to all interfaces, or the -interface name, eg, "eth2"
protocols
Array of structures listing supported protocols and a protocol- specific callback for each one. The list is ended with an diff --git a/test-server/test-fraggle.c b/test-server/test-fraggle.c index cfd0f7a..5137711 100644 --- a/test-server/test-fraggle.c +++ b/test-server/test-fraggle.c @@ -244,7 +244,7 @@ int main(int argc, char **argv) struct libwebsocket_context *context; int opts = 0; char interface_name[128] = ""; - const char *interface = NULL; + const char *iface = NULL; struct libwebsocket *wsi; const char *address; int server_port = port; @@ -274,7 +274,7 @@ int main(int argc, char **argv) case 'i': strncpy(interface_name, optarg, sizeof interface_name); interface_name[(sizeof interface_name) - 1] = '\0'; - interface = interface_name; + iface = interface_name; break; case 'c': client = 1; @@ -298,7 +298,7 @@ int main(int argc, char **argv) } info.port = server_port; - info.interface = interface; + info.iface = iface; info.protocols = protocols; #ifndef LWS_NO_EXTENSIONS info.extensions = libwebsocket_internal_extensions; diff --git a/test-server/test-server.c b/test-server/test-server.c index 388303e..862124d 100644 --- a/test-server/test-server.c +++ b/test-server/test-server.c @@ -506,7 +506,7 @@ int main(int argc, char **argv) struct libwebsocket_context *context; int opts = 0; char interface_name[128] = ""; - const char *interface = NULL; + const char *iface = NULL; #ifndef WIN32 int syslog_options = LOG_PID | LOG_PERROR; #endif @@ -546,7 +546,7 @@ int main(int argc, char **argv) case 'i': strncpy(interface_name, optarg, sizeof interface_name); interface_name[(sizeof interface_name) - 1] = '\0'; - interface = interface_name; + iface = interface_name; break; case 'c': close_testing = 1; @@ -598,7 +598,7 @@ int main(int argc, char **argv) } #endif - info.interface = interface; + info.iface = iface; info.protocols = protocols; #ifndef LWS_NO_EXTENSIONS info.extensions = libwebsocket_internal_extensions; -- 2.7.4