39 #ifndef CURLPIPE_MULTIPLEX 43 #define CURLPIPE_MULTIPLEX 0 46 #define NUM_HANDLES 1000 64 void dump(
const char *text,
int num,
unsigned char *
ptr,
size_t size,
69 unsigned int width = 0x10;
75 fprintf(stderr,
"%d %s, %ld bytes (0x%lx)\n",
76 num, text, (
long)size, (
long)size);
80 fprintf(stderr,
"%4.4lx: ", (
long)i);
84 for(c = 0; c <
width; c++)
86 fprintf(stderr,
"%02x ", ptr[i + c]);
91 for(c = 0; (c <
width) && (i + c < size); c++) {
93 if(nohex && (i + c + 1 < size) && ptr[i + c] == 0x0D &&
94 ptr[i + c + 1] == 0x0A) {
99 (ptr[i + c] >= 0x20) && (ptr[i + c]<0x80)?ptr[i + c]:
'.');
101 if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D &&
102 ptr[i + c + 2] == 0x0A) {
103 i += (c + 3 -
width);
128 gettimeofday(&tv, NULL);
130 epoch_offset = time(NULL) - tv.
tv_sec;
133 secs = epoch_offset + tv.
tv_sec;
134 now = localtime(&secs);
135 snprintf(timebuf,
sizeof(timebuf),
"%02d:%02d:%02d.%06ld",
136 now->tm_hour, now->tm_min, now->tm_sec, (
long)tv.
tv_usec);
140 fprintf(stderr,
"%s [%d] Info: %s", timebuf, num, data);
146 text =
"=> Send header";
149 text =
"=> Send data";
152 text =
"=> Send SSL data";
155 text =
"<= Recv header";
158 text =
"<= Recv data";
161 text =
"<= Recv SSL data";
165 dump(text, num, (
unsigned char *)data, size, 1);
178 size_t retcode =
fread(ptr, size, nmemb, i->
in);
190 struct stat file_info;
193 snprintf(filename, 128,
"dl-%d", num);
194 out = fopen(filename,
"wb");
196 snprintf(url, 256,
"https://localhost:8443/upload-%d", num);
199 stat(upload, &file_info);
200 uploadsize = file_info.st_size;
202 indata[num].
in = fopen(upload,
"rb");
232 #if (CURLPIPE_MULTIPLEX > 0) 243 int main(
int argc,
char **argv)
249 const char *
filename =
"index.html";
268 setup(easy[i], i, filename);
292 long curl_timeo = -1;
303 if(curl_timeo >= 0) {
304 timeout.
tv_sec = curl_timeo / 1000;
308 timeout.
tv_usec = (curl_timeo % 1000) * 1000;
315 fprintf(stderr,
"curl_multi_fdset() failed, code %d.\n", mc);
331 struct timeval wait = { 0, 100 * 1000 };
332 rc = select(0, NULL, NULL, NULL, &wait);
338 rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
351 }
while(still_running);
CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *exc_fd_set, int *max_fd)
static void dump(const char *text, int num, unsigned char *ptr, size_t size, char nohex)
static int my_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp)
CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *curl_handle)
int stat(const char *path, struct stat *buffer)
CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, long *milliseconds)
UNITTEST_START char * ptr
#define curl_easy_setopt(handle, option, value)
int main(int argc, char **argv)
CURL_EXTERN CURLM * curl_multi_init(void)
static time_t epoch_offset
static CURLM * multi_handle
static int upload(CURL *curlhandle, const char *remotepath, const char *localpath, long timeout, long tries)
#define curl_multi_setopt(handle, opt, param)
static struct input indata[NUM_HANDLES]
CURL_EXTERN CURL * curl_easy_init(void)
#define CURLPIPE_MULTIPLEX
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
CURL_TYPEOF_CURL_OFF_T curl_off_t
static int hnd2num(CURL *hnd)
static CURL * easy[MAX_EASY_HANDLES]
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle)
static void * curl_hnd[NUM_HANDLES]
static void setup(CURL *hnd, int num, const char *upload)