doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lib504.c
Go to the documentation of this file.
1 #include "test.h"
2 
3 #include <sys/time.h>
4 #include <sys/types.h>
5 
6 /*
7  * Source code in here hugely as reported in bug report 651464 by
8  * Christopher R. Palmer.
9  *
10  * Use multi interface to get document over proxy with bad port number.
11  * This caused the interface to "hang" in libcurl 7.10.2.
12  */
13 int test(char *URL)
14 {
15  CURL *c;
16  int ret=0;
17  CURLM *m;
18  fd_set rd, wr, exc;
19  CURLMcode res;
20  int running;
21  int max_fd;
22  int rc;
23 
25  c = curl_easy_init();
26 
27  /* the point here being that there must not run anything on the given
28  proxy port */
29  curl_easy_setopt(c, CURLOPT_PROXY, arg2);
30  curl_easy_setopt(c, CURLOPT_URL, URL);
31  curl_easy_setopt(c, CURLOPT_VERBOSE, 1);
32 
33  m = curl_multi_init();
34 
35  res = curl_multi_add_handle(m, c);
36  if(res && (res != CURLM_CALL_MULTI_PERFORM))
37  return 1; /* major failure */
38  do {
39  struct timeval interval;
40 
41  interval.tv_sec = 1;
42  interval.tv_usec = 0;
43 
44  fprintf(stderr, "curl_multi_perform()\n");
45 
46  do {
47  res = curl_multi_perform(m, &running);
48  } while (res == CURLM_CALL_MULTI_PERFORM);
49  if(!running) {
50  /* This is where this code is expected to reach */
51  int numleft;
52  CURLMsg *msg = curl_multi_info_read(m, &numleft);
53  fprintf(stderr, "Expected: not running\n");
54  if(msg && !numleft)
55  ret = 100; /* this is where we should be */
56  else
57  ret = 99; /* not correct */
58  break;
59  }
60  fprintf(stderr, "running == %d, res == %d\n", running, res);
61 
62  if (res != CURLM_OK) {
63  ret = 2;
64  break;
65  }
66 
67  FD_ZERO(&rd);
68  FD_ZERO(&wr);
69  FD_ZERO(&exc);
70  max_fd = 0;
71 
72  fprintf(stderr, "curl_multi_fdset()\n");
73  if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
74  fprintf(stderr, "unexpected failured of fdset.\n");
75  ret = 3;
76  break;
77  }
78  rc = select(max_fd+1, &rd, &wr, &exc, &interval);
79  fprintf(stderr, "select returned %d\n", rc);
80 
81  } while(rc);
82 
86 
87  return ret;
88 }
89 
CURLcode curl_global_init(long flags)
Globally initializes cURL given a bitwise set of the different features to initialize.
Definition: easy.c:147
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)
Definition: multi.c:231
long tv_sec
Definition: timeval.h:37
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:5286
long tv_usec
Definition: timeval.h:38
const GLubyte * c
Definition: glext.h:4677
CURLMcode curl_multi_remove_handle(CURLM *multi_handle, CURL *curl_handle)
Definition: multi.c:182
#define select(args...)
Definition: amigaos.h:39
CURLM * curl_multi_init(void)
Definition: multi.c:114
CURLMcode curl_multi_cleanup(CURLM *multi_handle)
Definition: multi.c:583
CURLMcode
Definition: multi.h:78
CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
Definition: multi.c:306
void CURLM
Definition: multi.h:76
Definition: multi.h:80
void CURL
Definition: types.h:25
GLuint res
Definition: glext.h:5385
CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *curl_handle)
Definition: multi.c:134
Definition: multi.h:95
#define CURL_GLOBAL_ALL
Definition: curl.h:1153
void curl_easy_cleanup(CURL *curl)
Definition: easy.c:288
CURL * curl_easy_init(void)
Definition: easy.c:195
CURLMsg * curl_multi_info_read(CURLM *multi_handle, int *msgs_in_queue)
Definition: multi.c:614
int test(char *URL)
Definition: lib504.c:13