Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

sws.c: improve proxy mode torture testing support - followup to 18c6c8a

  • Loading branch information...
commit b15024be4d768a4ea4345bbfb768dcf5fbcd01a7 1 parent 2140184
yangtse authored January 16, 2012

Showing 1 changed file with 41 additions and 31 deletions. Show diff stats Hide diff stats

  1. 72  tests/server/sws.c
72  tests/server/sws.c
@@ -1184,8 +1184,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
1184 1184
   const char *op_br = "";
1185 1185
   const char *cl_br = "";
1186 1186
 #ifdef TCP_NODELAY
1187  
-  curl_socklen_t flag = 1;
1188  
-  int level = IPPROTO_TCP;
  1187
+  curl_socklen_t flag;
1189 1188
 #endif
1190 1189
 
1191 1190
 #ifdef ENABLE_IPV6
@@ -1218,9 +1217,12 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
1218 1217
 
1219 1218
 #ifdef TCP_NODELAY
1220 1219
   /* Disable the Nagle algorithm */
1221  
-  if(setsockopt(serverfd, level, TCP_NODELAY,
1222  
-                (void *)&flag, sizeof(flag)) < 0)
  1220
+  flag = 1;
  1221
+  if(0 != setsockopt(serverfd, IPPROTO_TCP, TCP_NODELAY,
  1222
+                     (void *)&flag, sizeof(flag)))
1223 1223
     logmsg("====> TCP_NODELAY for server conection failed");
  1224
+  else
  1225
+    logmsg("TCP_NODELAY set for server conection");
1224 1226
 #endif
1225 1227
 
1226 1228
 #ifdef ENABLE_IPV6
@@ -1304,8 +1306,7 @@ static void http_connect(curl_socket_t *infdp,
1304 1306
   bool poll_client_wr[2] = { TRUE, TRUE };
1305 1307
   bool poll_server_wr[2] = { TRUE, TRUE };
1306 1308
 #ifdef TCP_NODELAY
1307  
-  curl_socklen_t flag = 1;
1308  
-  int level = IPPROTO_TCP;
  1309
+  curl_socklen_t flag;
1309 1310
 #endif
1310 1311
   bool primary = FALSE;
1311 1312
   bool secondary = FALSE;
@@ -1319,7 +1320,7 @@ static void http_connect(curl_socket_t *infdp,
1319 1320
   /* Sleep here to make sure the client reads CONNECT response's
1320 1321
      'end of headers' separate from the server data that follows.
1321 1322
      This is done to prevent triggering libcurl known bug #39. */
1322  
-  for(loop = 2; loop && !got_exit_signal; loop--)
  1323
+  for(loop = 2; (loop > 0) && !got_exit_signal; loop--)
1323 1324
     wait_ms(250);
1324 1325
   if(got_exit_signal)
1325 1326
     goto http_connect_cleanup;
@@ -1417,29 +1418,37 @@ static void http_connect(curl_socket_t *infdp,
1417 1418
           logmsg("====> Client connect DATA");
1418 1419
 #ifdef TCP_NODELAY
1419 1420
           /* Disable the Nagle algorithm */
1420  
-          if(setsockopt(datafd, level, TCP_NODELAY,
1421  
-                        (void *)&flag, sizeof(flag)) < 0)
1422  
-            logmsg("====> TCP_NODELAY for client conection failed");
  1421
+          flag = 1;
  1422
+          if(0 != setsockopt(datafd, IPPROTO_TCP, TCP_NODELAY,
  1423
+                             (void *)&flag, sizeof(flag)))
  1424
+            logmsg("====> TCP_NODELAY for client DATA conection failed");
  1425
+          else
  1426
+            logmsg("TCP_NODELAY set for client DATA conection");
1423 1427
 #endif
1424 1428
           req2.pipelining = FALSE;
1425 1429
           err = get_request(datafd, &req2);
1426 1430
           if(!err) {
1427 1431
             err = send_doc(datafd, &req2);
1428 1432
             if(!err && (req2.testno == DOCNUMBER_CONNECT)) {
1429  
-              /* connect to the server */
1430  
-              serverfd[DATA] = connect_to(ipaddr, req2.connect_port);
1431  
-              if(serverfd[DATA] != CURL_SOCKET_BAD) {
1432  
-                /* secondary tunnel established, now we have two connections */
1433  
-                poll_client_rd[DATA] = TRUE;
1434  
-                poll_client_wr[DATA] = TRUE;
1435  
-                poll_server_rd[DATA] = TRUE;
1436  
-                poll_server_wr[DATA] = TRUE;
1437  
-                max_tunnel_idx = DATA;
1438  
-                secondary = TRUE;
1439  
-                toc[DATA] = 0;
1440  
-                tos[DATA] = 0;
1441  
-                clientfd[DATA] = datafd;
1442  
-                datafd = CURL_SOCKET_BAD;
  1433
+              /* sleep to prevent triggering libcurl known bug #39. */
  1434
+              for(loop = 2; (loop > 0) && !got_exit_signal; loop--)
  1435
+                wait_ms(250);
  1436
+              if(!got_exit_signal) {
  1437
+                /* connect to the server */
  1438
+                serverfd[DATA] = connect_to(ipaddr, req2.connect_port);
  1439
+                if(serverfd[DATA] != CURL_SOCKET_BAD) {
  1440
+                  /* secondary tunnel established, now we have two connections */
  1441
+                  poll_client_rd[DATA] = TRUE;
  1442
+                  poll_client_wr[DATA] = TRUE;
  1443
+                  poll_server_rd[DATA] = TRUE;
  1444
+                  poll_server_wr[DATA] = TRUE;
  1445
+                  max_tunnel_idx = DATA;
  1446
+                  secondary = TRUE;
  1447
+                  toc[DATA] = 0;
  1448
+                  tos[DATA] = 0;
  1449
+                  clientfd[DATA] = datafd;
  1450
+                  datafd = CURL_SOCKET_BAD;
  1451
+                }
1443 1452
               }
1444 1453
             }
1445 1454
           }
@@ -1542,7 +1551,7 @@ static void http_connect(curl_socket_t *infdp,
1542 1551
 
1543 1552
       /* endpoint read/write disabling, endpoint closing and tunnel teardown */
1544 1553
       for(i = 0; i <= max_tunnel_idx; i++) {
1545  
-        for(loop = 2; loop; loop--) {
  1554
+        for(loop = 2; loop > 0; loop--) {
1546 1555
           /* loop twice to satisfy condition interdependencies without
1547 1556
              having to await select timeout or another socket event */
1548 1557
           if(clientfd[i] != CURL_SOCKET_BAD) {
@@ -1580,7 +1589,7 @@ static void http_connect(curl_socket_t *infdp,
1580 1589
 
1581 1590
       /* socket clearing */
1582 1591
       for(i = 0; i <= max_tunnel_idx; i++) {
1583  
-        for(loop = 2; loop; loop--) {
  1592
+        for(loop = 2; loop > 0; loop--) {
1584 1593
           if(clientfd[i] != CURL_SOCKET_BAD) {
1585 1594
             if(!poll_client_wr[i] && !poll_client_rd[i]) {
1586 1595
               logmsg("[%s] CLOSING client socket", data_or_ctrl(i));
@@ -1791,8 +1800,8 @@ int main(int argc, char *argv[])
1791 1800
   }
1792 1801
 
1793 1802
   flag = 1;
1794  
-  if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
1795  
-            (void *)&flag, sizeof(flag))) {
  1803
+  if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
  1804
+                     (void *)&flag, sizeof(flag))) {
1796 1805
     error = SOCKERRNO;
1797 1806
     logmsg("setsockopt(SO_REUSEADDR) failed with error: (%d) %s",
1798 1807
            error, strerror(error));
@@ -1891,10 +1900,11 @@ int main(int argc, char *argv[])
1891 1900
      * response in many small segments to torture the clients more.
1892 1901
      */
1893 1902
     flag = 1;
1894  
-    if (setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
1895  
-                   (void *)&flag, sizeof(flag)) == -1) {
  1903
+    if(0 != setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
  1904
+                       (void *)&flag, sizeof(flag)))
1896 1905
       logmsg("====> TCP_NODELAY failed");
1897  
-    }
  1906
+    else
  1907
+      logmsg("TCP_NODELAY set");
1898 1908
 #endif
1899 1909
 
1900 1910
     /* initialization of httprequest struct is done in get_request(), but due

0 notes on commit b15024b

Please sign in to comment.
Something went wrong with that request. Please try again.