~ubuntu-branches/ubuntu/maverick/curl/maverick

« back to all changes in this revision

Viewing changes to lib/connect.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2009-12-11 19:33:21 UTC
  • mfrom: (3.4.2 squeeze) (40.1.2 curl)
  • Revision ID: james.westby@ubuntu.com-20091211193321-tenukopudyznzbjj
* Merge with Debian testing.  Remaining changes:
  - Keep build deps in main:
    - Drop build dependencies: stunnel, libdb4.6-dev, libssh2-1-dev
    - Add build-dependency on openssh-server
    - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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: connect.c,v 1.219 2009-05-07 20:02:51 bagder Exp $
 
21
 * $Id: connect.c,v 1.223 2009-10-01 07:59:45 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
177
177
  return timeout_ms;
178
178
}
179
179
 
180
 
 
181
 
/*
182
 
 * Curl_nonblock() set the given socket to either blocking or non-blocking
183
 
 * mode based on the 'nonblock' boolean argument. This function is highly
184
 
 * portable.
185
 
 */
186
 
int Curl_nonblock(curl_socket_t sockfd,    /* operate on this */
187
 
                  int nonblock   /* TRUE or FALSE */)
188
 
{
189
 
#if defined(USE_BLOCKING_SOCKETS)
190
 
 
191
 
  return 0; /* returns success */
192
 
 
193
 
#elif defined(HAVE_FCNTL_O_NONBLOCK)
194
 
 
195
 
  /* most recent unix versions */
196
 
  int flags;
197
 
  flags = fcntl(sockfd, F_GETFL, 0);
198
 
  if(FALSE != nonblock)
199
 
    return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
200
 
  else
201
 
    return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
202
 
 
203
 
#elif defined(HAVE_IOCTL_FIONBIO)
204
 
 
205
 
  /* older unix versions */
206
 
  int flags;
207
 
  flags = nonblock;
208
 
  return ioctl(sockfd, FIONBIO, &flags);
209
 
 
210
 
#elif defined(HAVE_IOCTLSOCKET_FIONBIO)
211
 
 
212
 
  /* Windows */
213
 
  unsigned long flags;
214
 
  flags = nonblock;
215
 
  return ioctlsocket(sockfd, FIONBIO, &flags);
216
 
 
217
 
#elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO)
218
 
 
219
 
  /* Amiga */
220
 
  return IoctlSocket(sockfd, FIONBIO, (long)nonblock);
221
 
 
222
 
#elif defined(HAVE_SETSOCKOPT_SO_NONBLOCK)
223
 
 
224
 
  /* BeOS */
225
 
  long b = nonblock ? 1 : 0;
226
 
  return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
227
 
 
228
 
#else
229
 
#  error "no non-blocking method was found/used/set"
230
 
#endif
231
 
}
232
 
 
233
180
/*
234
181
 * waitconnect() waits for a TCP connect on the given socket for the specified
235
182
 * number if milliseconds. It returns:
330
277
       * hostname or ip address.
331
278
       */
332
279
      if(setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
333
 
                    dev, strlen(dev)+1) != 0) {
 
280
                    dev, (curl_socklen_t)strlen(dev)+1) != 0) {
334
281
        error = SOCKERRNO;
335
282
        infof(data, "SO_BINDTODEVICE %s failed with errno %d: %s;"
336
283
              " will do regular bind\n",
555
502
      /* store the new socket descriptor */
556
503
      conn->sock[sockindex] = sockfd;
557
504
      conn->ip_addr = ai;
558
 
      break;
 
505
      return FALSE;
559
506
    }
560
507
    ai = ai->ai_next;
561
508
  }
717
664
void Curl_sndbufset(curl_socket_t sockfd)
718
665
{
719
666
  int val = CURL_MAX_WRITE_SIZE + 32;
 
667
  int curval = 0;
 
668
  int curlen = sizeof(curval);
 
669
 
 
670
  if (getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char *)&curval, &curlen) == 0)
 
671
    if (curval > val)
 
672
      return;
 
673
 
720
674
  setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (const char *)&val, sizeof(val));
721
675
}
722
676
#endif
846
800
  }
847
801
 
848
802
  /* set socket non-blocking */
849
 
  Curl_nonblock(sockfd, TRUE);
 
803
  curlx_nonblock(sockfd, TRUE);
850
804
 
851
805
  /* Connect TCP sockets, bind UDP */
852
806
  if(conn->socktype == SOCK_STREAM)