Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

stcpopts.cc

Go to the documentation of this file.
00001 
00002 
00003 // This is neccessary to avoid muliple definitions of fd_set, etc when both
00004 // RPC via PCNFS and Windows Sockets are to be available
00005 #ifdef USE_PCNFS
00006 #undef USE_PCNFS
00007 #endif
00008 
00009 #include "rcs_defs.hh"          /* _Windows, EXTERN_C_STD_HEADERS */
00010 #include "stcpopts.hh"
00011 #include "rcs_prnt.hh"          /* rcs_print_error()  */
00012 #include "sokintrf.h"           // all the socket defs
00013 
00014 #ifdef EXTERN_C_STD_HEADERS
00015 extern "C"
00016 {
00017 #endif
00018 
00019 #include <string.h>             /* strerror() */
00020 #ifdef CenterLine
00021   char *strerror (int errnum);
00022 #endif
00023 #include <errno.h>              /* errno */
00024 
00025 #ifndef VXWORKS
00026 #include <fcntl.h>              /* fcntl(), O_NDELAY, F_SETFL */
00027 #endif
00028 
00029 
00030 #ifdef UNIX_LIKE_PLAT
00031 #include <netinet/tcp.h>        // TCP_NODELAY
00032 #endif
00033 
00034 #ifdef VXWORKS
00035 #include <netinet/tcp.h>        // TCP_NODELAY
00036 #endif
00037 
00038 #ifdef EXTERN_C_STD_HEADERS
00039 }
00040 #endif
00041 
00042 int stcp_nonblocking = 1;
00043 
00044 int RCS_EXPORT
00045 set_stcp_socket_options (int socket_fd)
00046 {
00047   if (socket_fd <= 0)
00048     {
00049       return -1;
00050     }
00051   int optval = 1;
00052 #if defined(_Windows) || !defined(MSDOS)
00053   if (dl_setsockopt (socket_fd, IPPROTO_TCP, TCP_NODELAY,
00054                      (char *) &optval, sizeof (optval)) < 0)
00055     {
00056       rcs_print_error (" Can`t set a socket option.\n");
00057       rcs_print_error ("errno = %d = %s\n", errno, strerror (errno));
00058       return -1;
00059     }
00060 #endif
00061   optval = 1;
00062 
00063 #if !defined(MSDOS) || defined(_Windows)
00064   if (dl_setsockopt (socket_fd, SOL_SOCKET, SO_REUSEADDR,
00065                      (char *) &optval, sizeof (optval)) < 0)
00066     {
00067       rcs_print_error (" Can`t set a socket option.\n");
00068       rcs_print_error ("errno = %d = %s\n", errno, strerror (errno));
00069       return -1;
00070     }
00071   struct linger linger_opt;
00072   linger_opt.l_onoff = 0;
00073   linger_opt.l_linger = 0;
00074   if (dl_setsockopt (socket_fd, SOL_SOCKET, SO_LINGER,
00075                      (char *) &linger_opt, sizeof (linger_opt)) < 0)
00076     {
00077       rcs_print_error (" Can`t set a socket option.\n");
00078       rcs_print_error ("errno = %d = %s\n", errno, strerror (errno));
00079       return -1;
00080     }
00081 #endif
00082 
00083   if (stcp_nonblocking)
00084     {
00085 #ifdef _Windows
00086       unsigned long arg = 1;
00087       if (dl_ioctlsocket (socket_fd, FIONBIO, &arg) < 0)
00088         {
00089           rcs_print_error ("Can't set  socket to non-blocking.");
00090         }
00091 #else
00092 #ifndef VXWORKS
00093 #if defined(O_NDELAY) && !defined(O_NONBLOCK)
00094       if (-1 == fcntl (socket_fd, F_SETFL, O_NDELAY))
00095         {
00096           rcs_print_error ("Couldn's set flag for no delay on socket.\n");
00097         }
00098 #endif
00099 #ifdef O_NONBLOCK
00100       if (-1 == fcntl (socket_fd, F_SETFL, O_NONBLOCK))
00101         {
00102           rcs_print_error ("Couldn's set flag for non-blocking on socket.\n");
00103         }
00104 #endif
00105 #endif
00106 #endif
00107     }
00108   return (0);
00109 }

Generated on Sun Dec 2 15:56:52 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001