aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_add_conn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_add_conn.c')
-rw-r--r--src/testcurl/test_add_conn.c94
1 files changed, 47 insertions, 47 deletions
diff --git a/src/testcurl/test_add_conn.c b/src/testcurl/test_add_conn.c
index 085d5e69..b50b6a86 100644
--- a/src/testcurl/test_add_conn.c
+++ b/src/testcurl/test_add_conn.c
@@ -79,20 +79,19 @@
79 79
80/* Cleanup test: max number of concurrent daemons depending on maximum number 80/* Cleanup test: max number of concurrent daemons depending on maximum number
81 * of open FDs. */ 81 * of open FDs. */
82#define CLEANUP_MAX_DAEMONS(max_fds) ( ((max_fds) < 10) ? 0 : \ 82#define CLEANUP_MAX_DAEMONS(max_fds) (unsigned int) \
83 ( (((max_fds) - 10) / \ 83 ( ((max_fds) < 10) ? \
84 (CLEANUP_NUM_REQS_PER_DAEMON * 5 \ 84 0 : ( (((max_fds) - 10) / (CLEANUP_NUM_REQS_PER_DAEMON * 5 + 3)) ) )
85 + 3)) ) )
86 85
87#define EXPECTED_URI_BASE_PATH "/hello_world" 86#define EXPECTED_URI_BASE_PATH "/hello_world"
88#define EXPECTED_URI_QUERY "a=%26&b=c" 87#define EXPECTED_URI_QUERY "a=%26&b=c"
89#define EXPECTED_URI_FULL_PATH EXPECTED_URI_BASE_PATH "?" EXPECTED_URI_QUERY 88#define EXPECTED_URI_FULL_PATH EXPECTED_URI_BASE_PATH "?" EXPECTED_URI_QUERY
90 89
91/* Global parameters */ 90/* Global parameters */
92static int oneone; /**< Use HTTP/1.1 instead of HTTP/1.0 */ 91static int oneone; /**< Use HTTP/1.1 instead of HTTP/1.0 */
93static int no_listen; /**< Start MHD daemons without listen socket */ 92static int no_listen; /**< Start MHD daemons without listen socket */
94static int global_port; /**< MHD daemons listen port number */ 93static uint16_t global_port; /**< MHD daemons listen port number */
95static int cleanup_test; /**< Test for final cleanup */ 94static int cleanup_test; /**< Test for final cleanup */
96static int slow_reply = 0; /**< Slowdown MHD replies */ 95static int slow_reply = 0; /**< Slowdown MHD replies */
97static int ignore_response_errors = 0; /**< Do not fail test if CURL 96static int ignore_response_errors = 0; /**< Do not fail test if CURL
98 returns error */ 97 returns error */
@@ -255,11 +254,11 @@ _externalErrorExit_func (const char *errDesc, const char *funcName, int lineNum)
255 254
256 255
257/* Static const value, indicates that result value was not set yet */ 256/* Static const value, indicates that result value was not set yet */
258static const int eMarker = 0xCE; 257static const unsigned int eMarker = 0xCE;
259 258
260 259
261static MHD_socket 260static MHD_socket
262createListeningSocket (int *pport) 261createListeningSocket (uint16_t *pport)
263{ 262{
264 MHD_socket skt; 263 MHD_socket skt;
265 struct sockaddr_in sin; 264 struct sockaddr_in sin;
@@ -300,7 +299,7 @@ createListeningSocket (int *pport)
300 if (AF_INET != sin.sin_family) 299 if (AF_INET != sin.sin_family)
301 externalErrorExitDesc ("getsockname() returned wrong socket family"); 300 externalErrorExitDesc ("getsockname() returned wrong socket family");
302 301
303 *pport = (int) ntohs (sin.sin_port); 302 *pport = ntohs (sin.sin_port);
304 } 303 }
305 304
306 return skt; 305 return skt;
@@ -338,14 +337,14 @@ struct addConnParam
338 337
339 MHD_socket clent_sk; 338 MHD_socket clent_sk;
340 /* Non-zero indicate error */ 339 /* Non-zero indicate error */
341 volatile int result; 340 volatile unsigned int result;
342 341
343#ifdef HAVE_PTHREAD_H 342#ifdef HAVE_PTHREAD_H
344 pthread_t addConnThread; 343 pthread_t addConnThread;
345#endif /* HAVE_PTHREAD_H */ 344#endif /* HAVE_PTHREAD_H */
346}; 345};
347 346
348static int 347static unsigned int
349doAcceptAndAddConnInThread (struct addConnParam *p) 348doAcceptAndAddConnInThread (struct addConnParam *p)
350{ 349{
351 struct sockaddr addr; 350 struct sockaddr addr;
@@ -386,7 +385,7 @@ startThreadAddConn (struct addConnParam *param)
386} 385}
387 386
388 387
389static int 388static unsigned int
390finishThreadAddConn (struct addConnParam *param) 389finishThreadAddConn (struct addConnParam *param)
391{ 390{
392 struct addConnParam *result; 391 struct addConnParam *result;
@@ -413,10 +412,10 @@ struct curlQueryParams
413 const char *queryPath; 412 const char *queryPath;
414 413
415 /* Destination port for CURL query */ 414 /* Destination port for CURL query */
416 int queryPort; 415 uint16_t queryPort;
417 416
418 /* CURL query result error flag */ 417 /* CURL query result error flag */
419 volatile int queryError; 418 volatile unsigned int queryError;
420 419
421#ifdef HAVE_PTHREAD_H 420#ifdef HAVE_PTHREAD_H
422 pthread_t queryThread; 421 pthread_t queryThread;
@@ -424,7 +423,7 @@ struct curlQueryParams
424}; 423};
425 424
426static CURL * 425static CURL *
427curlEasyInitForTest (const char *queryPath, int port, struct CBC *pcbc) 426curlEasyInitForTest (const char *queryPath, uint16_t port, struct CBC *pcbc)
428{ 427{
429 CURL *c; 428 CURL *c;
430 429
@@ -458,7 +457,7 @@ curlEasyInitForTest (const char *queryPath, int port, struct CBC *pcbc)
458} 457}
459 458
460 459
461static int 460static unsigned int
462doCurlQueryInThread (struct curlQueryParams *p) 461doCurlQueryInThread (struct curlQueryParams *p)
463{ 462{
464 CURL *c; 463 CURL *c;
@@ -539,7 +538,7 @@ startThreadCurlQuery (struct curlQueryParams *param)
539} 538}
540 539
541 540
542static int 541static unsigned int
543finishThreadCurlQuery (struct curlQueryParams *param) 542finishThreadCurlQuery (struct curlQueryParams *param)
544{ 543{
545 struct curlQueryParams *result; 544 struct curlQueryParams *result;
@@ -558,13 +557,13 @@ finishThreadCurlQuery (struct curlQueryParams *param)
558 557
559 558
560/* Perform test queries and shut down MHD daemon */ 559/* Perform test queries and shut down MHD daemon */
561static int 560static unsigned int
562performTestQueries (struct MHD_Daemon *d, int d_port) 561performTestQueries (struct MHD_Daemon *d, uint16_t d_port)
563{ 562{
564 struct curlQueryParams qParam; 563 struct curlQueryParams qParam;
565 struct addConnParam aParam; 564 struct addConnParam aParam;
566 int a_port; /* Additional listening socket port */ 565 uint16_t a_port; /* Additional listening socket port */
567 int ret = 0; /* Return value */ 566 unsigned int ret = 0; /* Return value */
568 567
569 qParam.queryPath = "http://127.0.0.1" EXPECTED_URI_FULL_PATH; 568 qParam.queryPath = "http://127.0.0.1" EXPECTED_URI_FULL_PATH;
570 a_port = 0; /* auto-assign */ 569 a_port = 0; /* auto-assign */
@@ -603,16 +602,16 @@ performTestQueries (struct MHD_Daemon *d, int d_port)
603 602
604 603
605/* Perform test for cleanup and shutdown MHD daemon */ 604/* Perform test for cleanup and shutdown MHD daemon */
606static int 605static unsigned int
607performTestCleanup (struct MHD_Daemon *d, int num_queries) 606performTestCleanup (struct MHD_Daemon *d, unsigned int num_queries)
608{ 607{
609 struct curlQueryParams *qParamList; 608 struct curlQueryParams *qParamList;
610 struct addConnParam aParam; 609 struct addConnParam aParam;
611 MHD_socket lstn_sk; /* Additional listening socket */ 610 MHD_socket lstn_sk; /* Additional listening socket */
612 MHD_socket *clntSkList; 611 MHD_socket *clntSkList;
613 int a_port; /* Additional listening socket port */ 612 uint16_t a_port; /* Additional listening socket port */
614 int i; 613 unsigned int i;
615 int ret = 0; /* Return value */ 614 unsigned int ret = 0; /* Return value */
616 615
617 a_port = 0; /* auto-assign */ 616 a_port = 0; /* auto-assign */
618 617
@@ -703,7 +702,7 @@ enum testMhdPollType
703static unsigned int 702static unsigned int
704testNumThreadsForPool (enum testMhdPollType pollType) 703testNumThreadsForPool (enum testMhdPollType pollType)
705{ 704{
706 int numThreads = MHD_CPU_COUNT; 705 unsigned int numThreads = MHD_CPU_COUNT;
707 if (! cleanup_test) 706 if (! cleanup_test)
708 return numThreads; /* No practical limit for non-cleanup test */ 707 return numThreads; /* No practical limit for non-cleanup test */
709 if (CLEANUP_MAX_DAEMONS (sys_max_fds) < numThreads) 708 if (CLEANUP_MAX_DAEMONS (sys_max_fds) < numThreads)
@@ -720,7 +719,7 @@ testNumThreadsForPool (enum testMhdPollType pollType)
720 719
721static struct MHD_Daemon * 720static struct MHD_Daemon *
722startTestMhdDaemon (enum testMhdThreadsType thrType, 721startTestMhdDaemon (enum testMhdThreadsType thrType,
723 enum testMhdPollType pollType, int *pport) 722 enum testMhdPollType pollType, uint16_t *pport)
724{ 723{
725 struct MHD_Daemon *d; 724 struct MHD_Daemon *d;
726 const union MHD_DaemonInfo *dinfo; 725 const union MHD_DaemonInfo *dinfo;
@@ -738,7 +737,7 @@ startTestMhdDaemon (enum testMhdThreadsType thrType,
738 } 737 }
739 738
740 if (testMhdThreadInternalPool != thrType) 739 if (testMhdThreadInternalPool != thrType)
741 d = MHD_start_daemon (((int) thrType) | ((int) pollType) 740 d = MHD_start_daemon (((unsigned int) thrType) | ((unsigned int) pollType)
742 | (thrType == testMhdThreadExternal ? 741 | (thrType == testMhdThreadExternal ?
743 0 : MHD_USE_ITC) 742 0 : MHD_USE_ITC)
744 | (no_listen ? MHD_USE_NO_LISTEN_SOCKET : 0) 743 | (no_listen ? MHD_USE_NO_LISTEN_SOCKET : 0)
@@ -748,7 +747,8 @@ startTestMhdDaemon (enum testMhdThreadsType thrType,
748 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, 747 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
749 MHD_OPTION_END); 748 MHD_OPTION_END);
750 else 749 else
751 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | ((int) pollType) 750 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD
751 | ((unsigned int) pollType)
752 | MHD_USE_ITC 752 | MHD_USE_ITC
753 | (no_listen ? MHD_USE_NO_LISTEN_SOCKET : 0) 753 | (no_listen ? MHD_USE_NO_LISTEN_SOCKET : 0)
754 | MHD_USE_ERROR_LOG, 754 | MHD_USE_ERROR_LOG,
@@ -773,7 +773,7 @@ startTestMhdDaemon (enum testMhdThreadsType thrType,
773 fprintf (stderr, "MHD_get_daemon_info() failed.\n"); 773 fprintf (stderr, "MHD_get_daemon_info() failed.\n");
774 abort (); 774 abort ();
775 } 775 }
776 *pport = (int) dinfo->port; 776 *pport = dinfo->port;
777 } 777 }
778 778
779 return d; 779 return d;
@@ -783,7 +783,7 @@ startTestMhdDaemon (enum testMhdThreadsType thrType,
783/* Test runners */ 783/* Test runners */
784 784
785 785
786static int 786static unsigned int
787testExternalGet (void) 787testExternalGet (void)
788{ 788{
789 struct MHD_Daemon *d; 789 struct MHD_Daemon *d;
@@ -796,10 +796,10 @@ testExternalGet (void)
796 CURLM *multi; 796 CURLM *multi;
797 time_t start; 797 time_t start;
798 struct timeval tv; 798 struct timeval tv;
799 int d_port = global_port; /* Daemon's port */ 799 uint16_t d_port = global_port; /* Daemon's port */
800 int a_port = 0; /* Additional listening socket port */ 800 uint16_t a_port = 0; /* Additional listening socket port */
801 struct addConnParam aParam; 801 struct addConnParam aParam;
802 int ret = 0; /* Return value of the test */ 802 unsigned int ret = 0; /* Return value of the test */
803 const int c_no_listen = no_listen; /* Local const value to mute analyzer */ 803 const int c_no_listen = no_listen; /* Local const value to mute analyzer */
804 804
805 d = startTestMhdDaemon (testMhdThreadExternal, testMhdPollBySelect, &d_port); 805 d = startTestMhdDaemon (testMhdThreadExternal, testMhdPollBySelect, &d_port);
@@ -993,11 +993,11 @@ testExternalGet (void)
993 993
994 994
995#ifdef HAVE_PTHREAD_H 995#ifdef HAVE_PTHREAD_H
996static int 996static unsigned int
997testInternalGet (enum testMhdPollType pollType) 997testInternalGet (enum testMhdPollType pollType)
998{ 998{
999 struct MHD_Daemon *d; 999 struct MHD_Daemon *d;
1000 int d_port = global_port; /* Daemon's port */ 1000 uint16_t d_port = global_port; /* Daemon's port */
1001 1001
1002 d = startTestMhdDaemon (testMhdThreadInternal, pollType, 1002 d = startTestMhdDaemon (testMhdThreadInternal, pollType,
1003 &d_port); 1003 &d_port);
@@ -1008,11 +1008,11 @@ testInternalGet (enum testMhdPollType pollType)
1008} 1008}
1009 1009
1010 1010
1011static int 1011static unsigned int
1012testMultithreadedGet (enum testMhdPollType pollType) 1012testMultithreadedGet (enum testMhdPollType pollType)
1013{ 1013{
1014 struct MHD_Daemon *d; 1014 struct MHD_Daemon *d;
1015 int d_port = global_port; /* Daemon's port */ 1015 uint16_t d_port = global_port; /* Daemon's port */
1016 1016
1017 d = startTestMhdDaemon (testMhdThreadInternalPerConnection, pollType, 1017 d = startTestMhdDaemon (testMhdThreadInternalPerConnection, pollType,
1018 &d_port); 1018 &d_port);
@@ -1025,11 +1025,11 @@ testMultithreadedGet (enum testMhdPollType pollType)
1025} 1025}
1026 1026
1027 1027
1028static int 1028static unsigned int
1029testMultithreadedPoolGet (enum testMhdPollType pollType) 1029testMultithreadedPoolGet (enum testMhdPollType pollType)
1030{ 1030{
1031 struct MHD_Daemon *d; 1031 struct MHD_Daemon *d;
1032 int d_port = global_port; /* Daemon's port */ 1032 uint16_t d_port = global_port; /* Daemon's port */
1033 1033
1034 d = startTestMhdDaemon (testMhdThreadInternalPool, pollType, 1034 d = startTestMhdDaemon (testMhdThreadInternalPool, pollType,
1035 &d_port); 1035 &d_port);
@@ -1041,17 +1041,17 @@ testMultithreadedPoolGet (enum testMhdPollType pollType)
1041} 1041}
1042 1042
1043 1043
1044static int 1044static unsigned int
1045testStopRace (enum testMhdPollType pollType) 1045testStopRace (enum testMhdPollType pollType)
1046{ 1046{
1047 struct MHD_Daemon *d; 1047 struct MHD_Daemon *d;
1048 int d_port = global_port; /* Daemon's port */ 1048 uint16_t d_port = global_port; /* Daemon's port */
1049 int a_port = 0; /* Additional listening socket port */ 1049 uint16_t a_port = 0; /* Additional listening socket port */
1050 struct sockaddr_in sin; 1050 struct sockaddr_in sin;
1051 MHD_socket fd1; 1051 MHD_socket fd1;
1052 MHD_socket fd2; 1052 MHD_socket fd2;
1053 struct addConnParam aParam; 1053 struct addConnParam aParam;
1054 int ret = 0; /* Return value of the test */ 1054 unsigned int ret = 0; /* Return value of the test */
1055 1055
1056 d = startTestMhdDaemon (testMhdThreadInternal, pollType, 1056 d = startTestMhdDaemon (testMhdThreadInternal, pollType,
1057 &d_port); 1057 &d_port);