~ubuntu-branches/ubuntu/lucid/curl/lucid-201101212007

« back to all changes in this revision

Viewing changes to tests/libtest/lib507.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-16 15:16:54 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20070516151654-x9nkigtr2j0i8d0v
Tags: upstream-7.16.2
ImportĀ upstreamĀ versionĀ 7.16.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *                                  _   _ ____  _
 
3
 *  Project                     ___| | | |  _ \| |
 
4
 *                             / __| | | | |_) | |
 
5
 *                            | (__| |_| |  _ <| |___
 
6
 *                             \___|\___/|_| \_\_____|
 
7
 *
 
8
 * $Id: lib507.c,v 1.16 2007-03-10 00:19:05 yangtse Exp $
 
9
 */
 
10
 
1
11
#include "test.h"
2
12
 
 
13
#include "testutil.h"
 
14
 
 
15
#define MAIN_LOOP_HANG_TIMEOUT     90 * 1000
 
16
#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
 
17
 
3
18
int test(char *URL)
4
19
{
5
20
  CURL* curls;
7
22
  int still_running;
8
23
  int i = -1;
9
24
  CURLMsg *msg;
10
 
 
11
 
  multi = curl_multi_init();
12
 
 
13
 
  curls=curl_easy_init();
 
25
  CURLMcode res;
 
26
  struct timeval ml_start;
 
27
  struct timeval mp_start;
 
28
  char ml_timedout = FALSE;
 
29
  char mp_timedout = FALSE;
 
30
 
 
31
  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
 
32
    fprintf(stderr, "curl_global_init() failed\n");
 
33
    return TEST_ERR_MAJOR_BAD;
 
34
  }
 
35
 
 
36
  if ((multi = curl_multi_init()) == NULL) {
 
37
    fprintf(stderr, "curl_multi_init() failed\n");
 
38
    curl_global_cleanup();
 
39
    return TEST_ERR_MAJOR_BAD;
 
40
  }
 
41
 
 
42
  if ((curls = curl_easy_init()) == NULL) {
 
43
    fprintf(stderr, "curl_easy_init() failed\n");
 
44
    curl_multi_cleanup(multi);
 
45
    curl_global_cleanup();
 
46
    return TEST_ERR_MAJOR_BAD;
 
47
  }
 
48
 
14
49
  curl_easy_setopt(curls, CURLOPT_URL, URL);
15
 
  curl_multi_add_handle(multi, curls);
16
 
 
17
 
  while ( CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi, &still_running) );
18
 
  while(still_running) {
 
50
 
 
51
  if ((res = curl_multi_add_handle(multi, curls)) != CURLM_OK) {
 
52
    fprintf(stderr, "curl_multi_add_handle() failed, "
 
53
            "with code %d\n", res);
 
54
    curl_easy_cleanup(curls);
 
55
    curl_multi_cleanup(multi);
 
56
    curl_global_cleanup();
 
57
    return TEST_ERR_MAJOR_BAD;
 
58
  }
 
59
 
 
60
  mp_timedout = FALSE;
 
61
  mp_start = tutil_tvnow();
 
62
 
 
63
  do {
 
64
    res = curl_multi_perform(multi, &still_running);
 
65
    if (tutil_tvdiff(tutil_tvnow(), mp_start) > 
 
66
        MULTI_PERFORM_HANG_TIMEOUT) {
 
67
      mp_timedout = TRUE;
 
68
      break;
 
69
    }
 
70
  } while (res == CURLM_CALL_MULTI_PERFORM);
 
71
 
 
72
  ml_timedout = FALSE;
 
73
  ml_start = tutil_tvnow();
 
74
 
 
75
  while ((!ml_timedout) && (!mp_timedout) && (still_running)) {
19
76
    struct timeval timeout;
20
77
    int rc;
21
78
    fd_set fdread;
22
79
    fd_set fdwrite;
23
80
    fd_set fdexcep;
24
81
    int maxfd;
 
82
 
25
83
    FD_ZERO(&fdread);
26
84
    FD_ZERO(&fdwrite);
27
85
    FD_ZERO(&fdexcep);
28
86
    timeout.tv_sec = 1;
29
87
    timeout.tv_usec = 0;
 
88
 
 
89
    if (tutil_tvdiff(tutil_tvnow(), ml_start) > 
 
90
        MAIN_LOOP_HANG_TIMEOUT) {
 
91
      ml_timedout = TRUE;
 
92
      break;
 
93
    }
 
94
 
30
95
    curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
31
 
    rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
 
96
    rc = select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
32
97
    switch(rc) {
33
98
      case -1:
34
99
        break;
35
100
      case 0:
36
101
      default:
37
 
        while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi, &still_running));
 
102
        mp_timedout = FALSE;
 
103
        mp_start = tutil_tvnow();
 
104
        do {
 
105
          res = curl_multi_perform(multi, &still_running);
 
106
          if (tutil_tvdiff(tutil_tvnow(), mp_start) > 
 
107
              MULTI_PERFORM_HANG_TIMEOUT) {
 
108
            mp_timedout = TRUE;
 
109
            break;
 
110
          }
 
111
        } while (res == CURLM_CALL_MULTI_PERFORM);
38
112
        break;
39
113
    }
40
114
  }
41
 
  msg = curl_multi_info_read(multi, &still_running);
42
 
  if(msg)
43
 
    /* this should now contain a result code from the easy handle,
44
 
       get it */
45
 
    i = msg->data.result;
 
115
  if (ml_timedout || mp_timedout) {
 
116
    if (ml_timedout) fprintf(stderr, "ml_timedout\n");
 
117
    if (mp_timedout) fprintf(stderr, "mp_timedout\n");
 
118
    fprintf(stderr, "ABORTING TEST, since it seems "
 
119
            "that it would have run forever.\n");
 
120
    i = TEST_ERR_RUNS_FOREVER;
 
121
  }
 
122
  else {
 
123
    msg = curl_multi_info_read(multi, &still_running);
 
124
    if(msg)
 
125
      /* this should now contain a result code from the easy handle,
 
126
         get it */
 
127
      i = msg->data.result;
 
128
  }
46
129
 
47
130
  curl_multi_cleanup(multi);
48
131
  curl_easy_cleanup(curls);
 
132
  curl_global_cleanup();
49
133
 
50
134
  return i; /* return the final return code */
51
135
}