nonblock.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023 #include "curl_setup.h"
00024 
00025 #ifdef HAVE_SYS_IOCTL_H
00026 #include <sys/ioctl.h>
00027 #endif
00028 #ifdef HAVE_FCNTL_H
00029 #include <fcntl.h>
00030 #endif
00031 
00032 #if (defined(HAVE_IOCTL_FIONBIO) && defined(NETWARE))
00033 #include <sys/filio.h>
00034 #endif
00035 #ifdef __VMS
00036 #include <in.h>
00037 #include <inet.h>
00038 #endif
00039 
00040 #include "nonblock.h"
00041 
00042 /*
00043  * curlx_nonblock() set the given socket to either blocking or non-blocking
00044  * mode based on the 'nonblock' boolean argument. This function is highly
00045  * portable.
00046  */
00047 int curlx_nonblock(curl_socket_t sockfd,    /* operate on this */
00048                    int nonblock   /* TRUE or FALSE */)
00049 {
00050 #if defined(USE_BLOCKING_SOCKETS)
00051 
00052   return 0; /* returns success */
00053 
00054 #elif defined(HAVE_FCNTL_O_NONBLOCK)
00055 
00056   /* most recent unix versions */
00057   int flags;
00058   flags = sfcntl(sockfd, F_GETFL, 0);
00059   if(nonblock)
00060     return sfcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
00061   else
00062     return sfcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
00063 
00064 #elif defined(HAVE_IOCTL_FIONBIO)
00065 
00066   /* older unix versions */
00067   int flags = nonblock ? 1 : 0;
00068   return ioctl(sockfd, FIONBIO, &flags);
00069 
00070 #elif defined(HAVE_IOCTLSOCKET_FIONBIO)
00071 
00072   /* Windows */
00073   unsigned long flags = nonblock ? 1UL : 0UL;
00074   return ioctlsocket(sockfd, FIONBIO, &flags);
00075 
00076 #elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO)
00077 
00078   /* Amiga */
00079   long flags = nonblock ? 1L : 0L;
00080   return IoctlSocket(sockfd, FIONBIO, (char *)&flags);
00081 
00082 #elif defined(HAVE_SETSOCKOPT_SO_NONBLOCK)
00083 
00084   /* BeOS */
00085   long b = nonblock ? 1L : 0L;
00086   return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
00087 
00088 #else
00089 #  error "no non-blocking method was found/used/set"
00090 #endif
00091 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05