浏览代码

Get civetweb to compile for strict C again

bel 11 年之前
父节点
当前提交
b53fd004c6
共有 2 个文件被更改,包括 23 次插入17 次删除
  1. 8 2
      src/civetweb.c
  2. 15 15
      test/unit_test.c

+ 8 - 2
src/civetweb.c

@@ -6445,6 +6445,7 @@ struct mg_connection *mg_download(const char *host, int port, int use_ssl,
     return conn;
 }
 
+#if defined(USE_WEBSOCKET)
 static void* websocket_client_thread(void *data)
 {
     struct mg_connection* conn = (struct mg_connection*)data;
@@ -6454,13 +6455,17 @@ static void* websocket_client_thread(void *data)
 
     return NULL;
 }
+#endif
 
 struct mg_connection *mg_websocket_client_connect(const char *host, int port, int use_ssl,
                                                char *error_buffer, size_t error_buffer_size,
                                                const char *path, const char *origin, websocket_data_func data_func)
 {
+    struct mg_connection* conn = NULL;
+
+#if defined(USE_WEBSOCKET)
     static const char *magic = "x3JJHMbDL1EzLkh9GBhXDw==";
-    static const char *handshake_req;
+    static const char *handshake_req;    
 
     if(origin != NULL)
     {
@@ -6485,7 +6490,7 @@ struct mg_connection *mg_websocket_client_connect(const char *host, int port, in
     }
 
     /* Establish the client connection and request upgrade */
-    struct mg_connection* conn = mg_download(host, port, use_ssl,
+    conn = mg_download(host, port, use_ssl,
                              error_buffer, error_buffer_size,
                              handshake_req, path, host, magic, origin);
 
@@ -6510,6 +6515,7 @@ struct mg_connection *mg_websocket_client_connect(const char *host, int port, in
         conn = NULL;
         DEBUG_TRACE("Websocket client connect thread could not be started\r\n");
     }
+#endif
 
     return conn;
 }

+ 15 - 15
test/unit_test.c

@@ -535,41 +535,41 @@ static void test_mg_websocket_client_connect(int use_ssl) {
     char ebuf[100];
     int port = HTTP_PORT;
 
-    if(use_ssl) { port = HTTPS_PORT; }
+    if (use_ssl) { port = HTTPS_PORT; }
 
-    //Try to connect to our own server
-    //TODO: These do not work right now
-
-    //Invalid port test
-    /*conn = mg_client_websocket_connect("localhost", 0, use_ssl,
+    /* Try to connect to our own server */
+    
+    #if 0 /* TODO: These do not work right now */
+    /* Invalid port test */    
+    conn = mg_client_websocket_connect("localhost", 0, use_ssl,
                              ebuf, sizeof(ebuf),
                              "/", "http://localhost",websocket_data_handler);
     ASSERT(conn == NULL);
-
-    //Should succeed, the default civetweb sever should complete the handshake
+        
+    /* Should succeed, the default civetweb sever should complete the handshake */
     conn = mg_client_websocket_connect("localhost", port, use_ssl,
                              ebuf, sizeof(ebuf),
                              "/", "http://localhost",websocket_data_handler);
-    ASSERT(conn != NULL);*/
-
+    ASSERT(conn != NULL);
+    #endif
 
-    //Try an external server test
+    /* Try an external server test */
     port = 80;
-    if(use_ssl) { port = 443; }
+    if (use_ssl) { port = 443; }
 
-    //Not a websocket server path
+    /* Not a websocket server path */
     conn = mg_websocket_client_connect("websocket.org", port, use_ssl,
                              ebuf, sizeof(ebuf),
                              "/", "http://websocket.org",websocket_data_handler);
     ASSERT(conn == NULL);
 
-    //Invalid port test
+    /* Invalid port test */
     conn = mg_websocket_client_connect("echo.websocket.org", 0, use_ssl,
                              ebuf, sizeof(ebuf),
                              "/", "http://websocket.org",websocket_data_handler);
     ASSERT(conn == NULL);
 
-    //Should succeed, echo.websocket.org echos the data back
+    /* Should succeed, echo.websocket.org echos the data back */
     conn = mg_websocket_client_connect("echo.websocket.org", port, use_ssl,
                              ebuf, sizeof(ebuf),
                              "/", "http://websocket.org",websocket_data_handler);