Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "test.h"
00023
00024 #include <fcntl.h>
00025
00026 #include "testutil.h"
00027 #include "warnless.h"
00028 #include "memdebug.h"
00029
00030 #define TEST_HANG_TIMEOUT 30 * 1000
00031
00032
00033
00034 #define MAX_BLOCKED_TIME_US 500000
00035
00036
00037 static int elapsed(struct timeval *before,
00038 struct timeval *after)
00039 {
00040 ssize_t result;
00041
00042 result = (after->tv_sec - before->tv_sec) * 1000000 +
00043 after->tv_usec - before->tv_usec;
00044 if(result < 0)
00045 result = 0;
00046
00047 return curlx_sztosi(result);
00048 }
00049
00050
00051 int test(char *URL)
00052 {
00053 CURL *handle = NULL;
00054 CURLM *mhandle = NULL;
00055 int res = 0;
00056 int still_running = 0;
00057
00058 start_test_timing();
00059
00060 global_init(CURL_GLOBAL_ALL);
00061
00062 easy_init(handle);
00063
00064 easy_setopt(handle, CURLOPT_URL, URL);
00065 easy_setopt(handle, CURLOPT_VERBOSE, 1L);
00066
00067 multi_init(mhandle);
00068
00069 multi_add_handle(mhandle, handle);
00070
00071 multi_perform(mhandle, &still_running);
00072
00073 abort_on_test_timeout();
00074
00075 while(still_running) {
00076 struct timeval timeout;
00077 fd_set fdread;
00078 fd_set fdwrite;
00079 fd_set fdexcep;
00080 int maxfd = -99;
00081 struct timeval before;
00082 struct timeval after;
00083 int e;
00084
00085 timeout.tv_sec = 0;
00086 timeout.tv_usec = 100000L;
00087
00088 FD_ZERO(&fdread);
00089 FD_ZERO(&fdwrite);
00090 FD_ZERO(&fdexcep);
00091
00092 multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
00093
00094
00095
00096 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00097
00098 abort_on_test_timeout();
00099
00100 fprintf(stderr, "ping\n");
00101 before = tutil_tvnow();
00102
00103 multi_perform(mhandle, &still_running);
00104
00105 abort_on_test_timeout();
00106
00107 after = tutil_tvnow();
00108 e = elapsed(&before, &after);
00109 fprintf(stderr, "pong = %d\n", e);
00110
00111 if(e > MAX_BLOCKED_TIME_US) {
00112 res = 100;
00113 break;
00114 }
00115 }
00116
00117 test_cleanup:
00118
00119
00120
00121 curl_multi_cleanup(mhandle);
00122 curl_easy_cleanup(handle);
00123 curl_global_cleanup();
00124
00125 return res;
00126 }