00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "test.h"
00032 #include "testutil.h"
00033 #include "warnless.h"
00034 #include "memdebug.h"
00035
00036 #define TEST_HANG_TIMEOUT 60 * 1000
00037
00038 #define UPLOADTHIS "this is the blurb we want to upload\n"
00039
00040 static size_t readcallback(void *ptr,
00041 size_t size,
00042 size_t nmemb,
00043 void *clientp)
00044 {
00045 int *counter = (int *)clientp;
00046
00047 if(*counter) {
00048
00049 fprintf(stderr, "READ ALREADY DONE!\n");
00050 return 0;
00051 }
00052 (*counter)++;
00053
00054 if(size * nmemb > strlen(UPLOADTHIS)) {
00055 fprintf(stderr, "READ!\n");
00056 strcpy(ptr, UPLOADTHIS);
00057 return strlen(UPLOADTHIS);
00058 }
00059 fprintf(stderr, "READ NOT FINE!\n");
00060 return 0;
00061 }
00062 static curlioerr ioctlcallback(CURL *handle,
00063 int cmd,
00064 void *clientp)
00065 {
00066 int *counter = (int *)clientp;
00067 (void)handle;
00068 if(cmd == CURLIOCMD_RESTARTREAD) {
00069 fprintf(stderr, "REWIND!\n");
00070 *counter = 0;
00071 }
00072 return CURLIOE_OK;
00073 }
00074
00075
00076 int test(char *URL)
00077 {
00078 int res = 0;
00079 CURL *curl = NULL;
00080 int counter=0;
00081 CURLM *m = NULL;
00082 int running=1;
00083
00084 start_test_timing();
00085
00086 global_init(CURL_GLOBAL_ALL);
00087
00088 easy_init(curl);
00089
00090 easy_setopt(curl, CURLOPT_URL, URL);
00091 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
00092 easy_setopt(curl, CURLOPT_HEADER, 1L);
00093
00094
00095 easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
00096 easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
00097 easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
00098 easy_setopt(curl, CURLOPT_READDATA, &counter);
00099
00100
00101 easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
00102
00103 easy_setopt(curl, CURLOPT_POST, 1L);
00104 #ifdef CURL_DOES_CONVERSIONS
00105
00106 easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00107 #endif
00108 easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
00109 easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
00110 easy_setopt(curl, CURLOPT_PROXYAUTH,
00111 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
00112
00113 multi_init(m);
00114
00115 multi_add_handle(m, curl);
00116
00117 while(running) {
00118 struct timeval timeout;
00119 fd_set fdread, fdwrite, fdexcep;
00120 int maxfd = -99;
00121
00122 timeout.tv_sec = 0;
00123 timeout.tv_usec = 100000L;
00124
00125 multi_perform(m, &running);
00126
00127 abort_on_test_timeout();
00128
00129 #ifdef TPF
00130 sleep(1);
00131 #endif
00132
00133 if(!running)
00134 break;
00135
00136 FD_ZERO(&fdread);
00137 FD_ZERO(&fdwrite);
00138 FD_ZERO(&fdexcep);
00139
00140 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
00141
00142
00143
00144 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00145
00146 abort_on_test_timeout();
00147 }
00148
00149 test_cleanup:
00150
00151
00152
00153 curl_multi_remove_handle(m, curl);
00154 curl_multi_cleanup(m);
00155 curl_easy_cleanup(curl);
00156 curl_global_cleanup();
00157
00158 return res;
00159 }
00160