#include "rcs_defs.hh"
#include "sokintrf.h"
#include "tcp_opts.hh"
#include "rcs_prnt.hh"
#include <errno.h>
#include <string.h>
Include dependency graph for tcp_opts.cc:
Go to the source code of this file.
Functions | |
int RCS_EXPORT | set_tcp_socket_options (int socket_fd) |
int RCS_EXPORT | make_tcp_socket_nonblocking (int socket_fd) |
int RCS_EXPORT | make_tcp_socket_blocking (int socket_fd) |
|
Definition at line 40 of file tcp_opts.cc. 00041 { 00042 if (socket_fd <= 0) 00043 { 00044 return -1; 00045 } 00046 int optval = 1; 00047 #if defined(_Windows) || !defined(MSDOS) && !defined(gnuwin32) 00048 if (dl_setsockopt (socket_fd, IPPROTO_TCP, TCP_NODELAY, 00049 (char *) &optval, sizeof (optval)) < 0) 00050 { 00051 rcs_print_error (" Can`t set a socket option.\n"); 00052 #ifndef UNDER_CE 00053 rcs_print_error ("errno = %d = %s\n", errno, strerror (errno)); 00054 #endif 00055 return -1; 00056 } 00057 #endif 00058 optval = 1; 00059 00060 #if !defined(MSDOS) || defined(_Windows) 00061 if (dl_setsockopt (socket_fd, SOL_SOCKET, SO_REUSEADDR, 00062 (char *) &optval, sizeof (optval)) < 0) 00063 { 00064 rcs_print_error (" Can`t set a socket option.\n"); 00065 #ifndef UNDER_CE 00066 rcs_print_error ("errno = %d = %s\n", errno, strerror (errno)); 00067 #endif 00068 return -1; 00069 } 00070 struct linger linger_opt; 00071 linger_opt.l_onoff = 0; 00072 linger_opt.l_linger = 0; 00073 if (dl_setsockopt (socket_fd, SOL_SOCKET, SO_LINGER, 00074 (char *) &linger_opt, sizeof (linger_opt)) < 0) 00075 { 00076 rcs_print_error (" Can`t set a socket option.\n"); 00077 #ifndef UNDER_CE 00078 rcs_print_error ("errno = %d = %s\n", errno, strerror (errno)); 00079 #endif 00080 return -1; 00081 } 00082 #endif 00083 00084 return 0; 00085 } |
|
Definition at line 89 of file tcp_opts.cc. 00090 { 00091 #ifdef _Windows 00092 unsigned long arg = 1; 00093 if (dl_ioctlsocket (socket_fd, FIONBIO, &arg) < 0) 00094 { 00095 rcs_print_error ("Can't set socket to non-blocking."); 00096 } 00097 #else 00098 #ifndef VXWORKS 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 return -1; 00104 } 00105 #else 00106 #ifdef O_NDELAY 00107 if (-1 == fcntl (socket_fd, F_SETFL, O_NDELAY)) 00108 { 00109 rcs_print_error ("Couldn's set flag for no delay on socket.\n"); 00110 return -1; 00111 } 00112 #endif 00113 #endif 00114 00115 #else 00116 // VXWORKS 00117 if (-1 == ioctl (socket_fd, FIONBIO, 1)) 00118 { 00119 rcs_print_error ("Couldn's set flag for non-blocking on socket.\n"); 00120 return -1; 00121 } 00122 #endif 00123 #endif 00124 return (0); 00125 } |
|
Definition at line 128 of file tcp_opts.cc. 00129 { 00130 #ifdef _Windows 00131 unsigned long arg = 0; 00132 if (dl_ioctlsocket (socket_fd, FIONBIO, &arg) < 0) 00133 { 00134 rcs_print_error ("Can't set socket to blocking."); 00135 } 00136 #else 00137 #ifdef VXWORKS 00138 if (-1 == ioctl (socket_fd, FIONBIO, 0)) 00139 { 00140 rcs_print_error ("Couldn's set flag for blocking on socket.: %d,%s\n", 00141 errno, strerror (errno)); 00142 return -1; 00143 } 00144 #else 00145 00146 #if defined(O_NONBLOCK) || defined(O_NDELAY) 00147 int val = fcntl (socket_fd, F_GETFL, 0); 00148 if (val < 0) 00149 { 00150 rcs_print_error ("fcntl error %d %s\n", errno, strerror (errno)); 00151 return -1; 00152 } 00153 #ifdef O_NONBLOCK 00154 val &= ~O_NONBLOCK; 00155 #endif 00156 #ifdef O_NDELAY 00157 val &= ~O_NDELAY; 00158 #endif 00159 if (fcntl (socket_fd, F_SETFL, val) < 0) 00160 { 00161 rcs_print_error ("Couldn's set flag for blocking on socket.: %d,%s\n", 00162 errno, strerror (errno)); 00163 return -1; 00164 } 00165 #endif 00166 #endif 00167 #endif 00168 return (0); 00169 } |