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 "testutil.h"
00025 #include "warnless.h"
00026 #include "memdebug.h"
00027
00028 #define TEST_HANG_TIMEOUT 60 * 1000
00029
00030 char const testData[] = ".abc\0xyz";
00031 off_t const testDataSize = sizeof(testData) - 1;
00032
00033 int test(char *URL)
00034 {
00035 CURL *easy;
00036 CURLM *multi_handle;
00037 int still_running;
00038 CURLMsg *msg;
00039 int msgs_left;
00040
00041
00042 easy = curl_easy_init();
00043
00044
00045 multi_handle = curl_multi_init();
00046
00047
00048 curl_multi_add_handle(multi_handle, easy);
00049
00050
00051 curl_easy_setopt(easy, CURLOPT_URL, URL);
00052 curl_easy_setopt(easy, CURLOPT_POSTFIELDSIZE_LARGE,
00053 (curl_off_t)testDataSize);
00054 curl_easy_setopt(easy, CURLOPT_POSTFIELDS, testData);
00055
00056
00057 curl_multi_perform(multi_handle, &still_running);
00058
00059 do {
00060 struct timeval timeout;
00061 int rc;
00062 CURLMcode mc;
00063
00064 fd_set fdread;
00065 fd_set fdwrite;
00066 fd_set fdexcep;
00067 int maxfd = -1;
00068
00069 long curl_timeo = -1;
00070
00071 FD_ZERO(&fdread);
00072 FD_ZERO(&fdwrite);
00073 FD_ZERO(&fdexcep);
00074
00075
00076 timeout.tv_sec = 1;
00077 timeout.tv_usec = 0;
00078
00079 curl_multi_timeout(multi_handle, &curl_timeo);
00080 if(curl_timeo >= 0) {
00081 timeout.tv_sec = curl_timeo / 1000;
00082 if(timeout.tv_sec > 1)
00083 timeout.tv_sec = 1;
00084 else
00085 timeout.tv_usec = (curl_timeo % 1000) * 1000;
00086 }
00087
00088
00089 mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
00090
00091 if(mc != CURLM_OK) {
00092 fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
00093 break;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 if(maxfd == -1) {
00103 #ifdef _WIN32
00104 Sleep(100);
00105 rc = 0;
00106 #else
00107
00108 struct timeval wait = { 0, 100 * 1000 };
00109 rc = select(0, NULL, NULL, NULL, &wait);
00110 #endif
00111 }
00112 else {
00113
00114
00115 rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00116 }
00117
00118 switch(rc) {
00119 case -1:
00120
00121 break;
00122 case 0:
00123 default:
00124 curl_multi_perform(multi_handle, &still_running);
00125 break;
00126 }
00127 } while(still_running);
00128
00129
00130 while((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
00131 if(msg->msg == CURLMSG_DONE) {
00132 printf("HTTP transfer completed with status %d\n", msg->data.result);
00133 break;
00134 }
00135 }
00136
00137 curl_multi_cleanup(multi_handle);
00138
00139
00140 curl_easy_cleanup(easy);
00141
00142 return 0;
00143 }
00144