~ubuntu-branches/ubuntu/precise/curl/precise-proposed

« back to all changes in this revision

Viewing changes to tests/libtest/lib582.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2011-11-25 17:30:45 UTC
  • mfrom: (3.4.23 sid)
  • Revision ID: package-import@ubuntu.com-20111125173045-2l3ni88jv16kath0
Tags: 7.22.0-3ubuntu1
* Merge from Debian unstable, remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.
  - Add new libcurl3-udeb package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 ***************************************************************************/
22
22
#include "test.h"
23
23
 
24
 
#include <sys/types.h>
25
 
#include <sys/stat.h>
26
24
#include <fcntl.h>
27
25
 
28
26
#include "testutil.h"
33
31
 
34
32
struct Sockets
35
33
{
36
 
  curl_socket_t* sockets;
37
 
  int count;
 
34
  curl_socket_t *sockets;
 
35
  int count;      /* number of sockets actually stored in array */
 
36
  int max_count;  /* max number of sockets that fit in allocated array */
38
37
};
39
38
 
40
39
struct ReadWriteSockets
54
53
 
55
54
  for (i = 0; i < sockets->count; ++i) {
56
55
    if (sockets->sockets[i] == fd) {
57
 
      memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
58
 
              sizeof(curl_socket_t) * (sockets->count - i - 1));
 
56
      if (i < sockets->count - 1)
 
57
        memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
 
58
              sizeof(curl_socket_t) * (sockets->count - (i + 1)));
59
59
      --sockets->count;
60
60
    }
61
61
  }
72
72
   */
73
73
  fprintf(stderr, "Add socket fd %d for %s\n", (int) fd, what);
74
74
  removeFd(sockets, fd, 0);
75
 
  sockets->sockets = realloc(sockets->sockets,
76
 
        sizeof(curl_socket_t) * (sockets->count + 1));
 
75
  /*
 
76
   * Allocate array storage when required.
 
77
   */
 
78
  if(!sockets->sockets) {
 
79
    sockets->sockets = malloc(sizeof(curl_socket_t) * 20U);
 
80
    if(!sockets->sockets)
 
81
      return;
 
82
    sockets->max_count = 20;
 
83
  }
 
84
  else if(sockets->count + 1 > sockets->max_count) {
 
85
    curl_socket_t *oldptr = sockets->sockets;
 
86
    sockets->sockets = realloc(oldptr, sizeof(curl_socket_t) *
 
87
                               (sockets->max_count + 20));
 
88
    if(!sockets->sockets) {
 
89
      /* cleanup in test_cleanup */
 
90
      sockets->sockets = oldptr;
 
91
      return;
 
92
    }
 
93
    sockets->max_count += 20;
 
94
  }
 
95
  /*
 
96
   * Add file descriptor to array.
 
97
   */
77
98
  sockets->sockets[sockets->count] = fd;
78
99
  ++sockets->count;
79
100
}
177
198
  }
178
199
}
179
200
 
180
 
static void notifyCurl(CURL* curl, curl_socket_t s, int evBitmask,
181
 
                       const char* info)
 
201
static void notifyCurl(CURLM *curl, curl_socket_t s, int evBitmask,
 
202
                       const char *info)
182
203
{
183
204
  int numhandles = 0;
184
205
  CURLMcode result = curl_multi_socket_action(curl, s, evBitmask, &numhandles);
185
 
  if (result != CURLM_OK && result != CURLM_CALL_MULTI_PERFORM)
186
 
  {
 
206
  if (result != CURLM_OK) {
187
207
    fprintf(stderr, "Curl error on %s: %i (%s)\n",
188
208
            info, result, curl_multi_strerror(result));
189
209
  }
192
212
/**
193
213
 * Invoke curl when a file descriptor is set.
194
214
 */
195
 
static void checkFdSet(CURL* curl, struct Sockets* sockets, fd_set* fdset,
196
 
                       int evBitmask, const char* name)
 
215
static void checkFdSet(CURLM *curl, struct Sockets *sockets, fd_set *fdset,
 
216
                       int evBitmask, const char *name)
197
217
{
198
218
  int i;
199
 
  for (i = 0; i < sockets->count; ++i)
200
 
  {
201
 
    if (FD_ISSET(sockets->sockets[i], fdset))
202
 
    {
 
219
  for (i = 0; i < sockets->count; ++i) {
 
220
    if (FD_ISSET(sockets->sockets[i], fdset)) {
203
221
      notifyCurl(curl, sockets->sockets[i], evBitmask, name);
204
222
    }
205
223
  }
216
234
  CURLM *m = NULL;
217
235
  struct timeval ml_start;
218
236
  char ml_timedout = FALSE;
219
 
  struct ReadWriteSockets sockets = {{0, 0}, {0, 0}};
 
237
  struct ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}};
220
238
  struct timeval timeout = {-1, 0};
221
239
  int success = 0;
222
240
 
369
387
  }
370
388
 
371
389
  fclose(hd_src); /* close the local file */
372
 
  if (sockets.read.sockets != 0)
 
390
  if (sockets.read.sockets)
373
391
    free(sockets.read.sockets);
374
 
  if (sockets.write.sockets != 0)
 
392
  if (sockets.write.sockets)
375
393
    free(sockets.write.sockets);
376
394
 
377
395
  curl_global_cleanup();