~ubuntu-branches/ubuntu/intrepid/curl/intrepid

« back to all changes in this revision

Viewing changes to lib/hostares.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-16 15:16:54 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070516151654-jo48r81zempo1qav
Tags: 7.16.2-3ubuntu1
* Merge with Debian; remaining changes:
  - Drop the stunnel build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: hostares.c,v 1.24 2006-07-25 13:49:50 yangtse Exp $
 
21
 * $Id: hostares.c,v 1.29 2007-03-27 18:15:26 yangtse Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
28
28
#ifdef NEED_MALLOC_H
29
29
#include <malloc.h>
30
30
#endif
31
 
#ifdef HAVE_SYS_TYPES_H
32
 
#include <sys/types.h>
33
 
#endif
34
31
#ifdef HAVE_SYS_SOCKET_H
35
32
#include <sys/socket.h>
36
33
#endif
75
72
#include "share.h"
76
73
#include "strerror.h"
77
74
#include "url.h"
78
 
#include "connect.h" /* for the Curl_sockerrno() proto */
 
75
#include "multiif.h"
 
76
#include "connect.h"
 
77
#include "select.h"
79
78
 
80
79
#define _MPRINTF_REPLACE /* use our functions only */
81
80
#include <curl/mprintf.h>
109
108
                        int numsocks)
110
109
 
111
110
{
 
111
  struct timeval maxtime;
 
112
  struct timeval timeout;
112
113
  int max = ares_getsock(conn->data->state.areschannel,
113
114
                         (int *)socks, numsocks);
114
115
 
 
116
 
 
117
  maxtime.tv_sec = CURL_TIMEOUT_RESOLVE;
 
118
  maxtime.tv_usec = 0;
 
119
 
 
120
  ares_timeout(conn->data->state.areschannel, &maxtime, &timeout);
 
121
 
 
122
  Curl_expire(conn->data,
 
123
              (timeout.tv_sec * 1000) + (timeout.tv_usec/1000) );
 
124
 
115
125
  return max;
116
126
}
117
127
 
135
145
 
136
146
  nfds = ares_fds(data->state.areschannel, &read_fds, &write_fds);
137
147
 
138
 
  (void)select(nfds, &read_fds, &write_fds, NULL,
139
 
               (struct timeval *)&tv);
 
148
  (void)Curl_select(nfds, &read_fds, &write_fds, NULL,
 
149
                    (struct timeval *)&tv);
140
150
 
141
151
  /* Call ares_process() unconditonally here, even if we simply timed out
142
152
     above, as otherwise the ares name resolve won't timeout! */
171
181
{
172
182
  CURLcode rc=CURLE_OK;
173
183
  struct SessionHandle *data = conn->data;
174
 
  long timeout = CURL_TIMEOUT_RESOLVE; /* default name resolve timeout */
 
184
  long timeout;
175
185
 
176
186
  /* now, see if there's a connect timeout or a regular timeout to
177
187
     use instead of the default one */
179
189
    timeout = conn->data->set.connecttimeout;
180
190
  else if(conn->data->set.timeout)
181
191
    timeout = conn->data->set.timeout;
182
 
 
183
 
  /* We convert the number of seconds into number of milliseconds here: */
184
 
  if(timeout < 2147483)
185
 
    /* maximum amount of seconds that can be multiplied with 1000 and
186
 
       still fit within 31 bits */
187
 
    timeout *= 1000;
188
192
  else
189
 
    timeout = 0x7fffffff; /* ridiculous amount of time anyway */
 
193
    timeout = CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve timeout */
190
194
 
191
195
  /* Wait for the name resolve query to complete. */
192
196
  while (1) {
207
211
      /* no file descriptors means we're done waiting */
208
212
      break;
209
213
    tvp = ares_timeout(data->state.areschannel, &store, &tv);
210
 
    count = select(nfds, &read_fds, &write_fds, NULL, tvp);
211
 
    if (count < 0 && Curl_sockerrno() != EINVAL)
 
214
    count = Curl_select(nfds, &read_fds, &write_fds, NULL, tvp);
 
215
    if ((count < 0) && (SOCKERRNO != EINVAL))
212
216
      break;
213
217
 
214
218
    ares_process(data->state.areschannel, &read_fds, &write_fds);