Fixed compilation on Windows. 77/3077/1
authorJoakim Soderberg <joakim.soderberg@gmail.com>
Mon, 11 Feb 2013 16:52:23 +0000 (17:52 +0100)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:34 +0000 (13:01 -0800)
lib/client.c
lib/libwebsockets.c
lib/libwebsockets.h
lib/server-handshake.c
lib/server.c
libwebsockets-api-doc.html
test-server/test-fraggle.c
test-server/test-server.c

index aa70bfe..c3fb2e8 100644 (file)
@@ -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);
 
index 3889fdf..c905d83 100644 (file)
@@ -24,6 +24,7 @@
 #ifdef WIN32
 #include <tchar.h>
 #include <io.h>
+#include <mstcpip.h>
 #else
 #ifdef LWS_BUILTIN_GETIFADDRS
 #include <getifaddrs.h>
@@ -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);
 
index ffa4896..d3b5215 100644 (file)
@@ -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;
index 2feca06..ba52037 100644 (file)
@@ -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));
index 1b10a86..3e81290 100644 (file)
@@ -374,3 +374,4 @@ int lws_server_socket_service(struct libwebsocket_context *context,
        }
        return 0;
 }
+
index 5b05c36..a07df43 100644 (file)
@@ -971,7 +971,6 @@ all sessions, etc, if it wants
 <h2>struct lws_context_creation_info - </h2>
 <b>struct lws_context_creation_info</b> {<br>
 &nbsp; &nbsp; <i>int</i> <b>port</b>;<br>
-&nbsp; &nbsp; <i>const char *</i> <b>interface</b>;<br>
 &nbsp; &nbsp; <i>struct libwebsocket_protocols *</i> <b>protocols</b>;<br>
 &nbsp; &nbsp; <i>struct libwebsocket_extension *</i> <b>extensions</b>;<br>
 &nbsp; &nbsp; <i>const char *</i> <b>ssl_cert_filepath</b>;<br>
@@ -991,9 +990,6 @@ all sessions, etc, if it wants
 <dd>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
-<dt><b>interface</b>
-<dd>NULL to bind the listen socket to all interfaces, or the
-interface name, eg, "eth2"
 <dt><b>protocols</b>
 <dd>Array of structures listing supported protocols and a protocol-
 specific callback for each one.  The list is ended with an
index cfd0f7a..5137711 100644 (file)
@@ -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;
index 388303e..862124d 100644 (file)
@@ -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;