00001
00002
00003
00004
00005 #ifdef USE_PCNFS
00006 #undef USE_PCNFS
00007 #endif
00008
00009
00010 #include "rcs_defs.hh"
00011 #include "sokintrf.h"
00012 #include "udp_opts.hh"
00013 #include "rcs_prnt.hh"
00014
00015 #ifdef UNIX_LIKE_PLAT
00016 #ifdef qnx
00017 #include <fcntl.h>
00018 #else
00019 #include <sys/fcntl.h>
00020 #endif
00021 #include <errno.h>
00022 #include <string.h>
00023 #endif
00024
00025 #ifdef sunos5
00026 #include <sys/types.h>
00027 #include <fcntl.h>
00028 #endif
00029
00030 int
00031 set_udp_socket_options (int socket_fd)
00032 {
00033 if (socket_fd <= 0)
00034 {
00035 return -1;
00036 }
00037 int optval = 1;
00038 if (dl_setsockopt (socket_fd, SOL_SOCKET, SO_REUSEADDR,
00039 (char *) &optval, sizeof (optval)) < 0)
00040 {
00041 rcs_print_error (" Can`t set a socket option.\n");
00042 #ifndef UNDER_CE
00043 rcs_print_error ("errno = %d = %s\n", errno, strerror (errno));
00044 #endif
00045 return -1;;
00046 }
00047 #if 0
00048 if (-1 == fcntl (socket_fd, F_SETFL, O_NDELAY))
00049 {
00050 rcs_print_error ("Couldn's set flag for no delay on socket.\n");
00051 }
00052 #endif
00053 return (0);
00054 }
00055
00056
00057 int RCS_EXPORT
00058 make_udp_socket_nonblocking (int socket_fd)
00059 {
00060 #ifdef _Windows
00061 unsigned long long_arg = 1;
00062 if (dl_ioctlsocket (socket_fd, FIONBIO, &long_arg) < 0)
00063 {
00064 rcs_print_error ("Can't set socket to non-blocking.");
00065 }
00066 #else
00067 #ifndef VXWORKS
00068 #ifdef MSDOS
00069 int int_arg = 1;
00070 if (-1 == tk_ioctl (socket_fd, FIONBIO, &int_arg))
00071 {
00072 rcs_print_error ("Can't set socket to non-blocking. : %d %s\n",
00073 tk_geterrno (socket_fd), tk_sperror ());
00074 return -1;
00075 }
00076 #else
00077
00078
00079 #if defined(O_NDELAY) && !defined(O_NONBLOCK)
00080 if (-1 == fcntl (socket_fd, F_SETFL, O_NDELAY))
00081 {
00082 rcs_print_error ("Couldn's set flag for no delay on socket.\n");
00083 return -1;
00084 }
00085 #endif
00086 #ifdef O_NONBLOCK
00087 if (-1 == fcntl (socket_fd, F_SETFL, O_NONBLOCK))
00088 {
00089 rcs_print_error ("Couldn's set flag for non-blocking on socket.\n");
00090 return -1;
00091 }
00092 #endif
00093 #endif
00094 #else
00095
00096 if (-1 == ioctl (socket_fd, FIONBIO, 1))
00097 {
00098 rcs_print_error ("Couldn's set flag for non-blocking on socket.\n");
00099 return -1;
00100 }
00101 #endif
00102 #endif
00103 return (0);
00104 }
00105
00106
00107 int RCS_EXPORT
00108 make_udp_socket_blocking (int socket_fd)
00109 {
00110 #ifdef _Windows
00111 unsigned long long_arg = 0;
00112 if (dl_ioctlsocket (socket_fd, FIONBIO, &long_arg) < 0)
00113 {
00114 rcs_print_error ("Can't set socket to non-blocking.");
00115 }
00116 #else
00117 #ifndef VXWORKS
00118 #ifdef MSDOS
00119 int int_arg = 0;
00120 if (-1 == tk_ioctl (socket_fd, FIONBIO, &int_arg))
00121 {
00122 rcs_print_error ("Can't set socket to non-blocking. : %d %s\n",
00123 tk_geterrno (socket_fd), tk_sperror ());
00124 return -1;
00125 }
00126 #else
00127
00128
00129 #if defined(O_NONBLOCK) || defined(O_NDELAY)
00130 int val = fcntl (socket_fd, F_GETFL, 0);
00131 if (val < 0)
00132 {
00133 rcs_print_error ("fcntl error %d %s\n", errno, strerror (errno));
00134 return -1;
00135 }
00136 #ifdef O_NONBLOCK
00137 val &= ~O_NONBLOCK;
00138 #endif
00139 #ifdef O_NDELAY
00140 val &= ~O_NDELAY;
00141 #endif
00142 if (fcntl (socket_fd, F_SETFL, val) < 0)
00143 {
00144 rcs_print_error ("Couldn's set flag for blocking on socket.: %d,%s\n",
00145 errno, strerror (errno));
00146 return -1;
00147 }
00148 #endif
00149 #endif
00150
00151 #else
00152
00153 if (-1 == ioctl (socket_fd, FIONBIO, 0))
00154 {
00155 rcs_print_error ("Couldn's set flag for non-blocking on socket.\n");
00156 return -1;
00157 }
00158 #endif
00159 #endif
00160 return (0);
00161 }
00162
00163
00164
00165 int RCS_EXPORT
00166 make_udp_socket_broadcast (int socket_fd)
00167 {
00168 if (socket_fd <= 0)
00169 {
00170 return -1;
00171 }
00172 int optval = 1;
00173 if (dl_setsockopt (socket_fd, SOL_SOCKET, SO_BROADCAST,
00174 (char *) &optval, sizeof (optval)) < 0)
00175 {
00176 rcs_print_error ("setsockopt(%d,SOL_SOCKET,SO_\n");
00177 #ifndef UNDER_CE
00178 rcs_print_error ("errno = %d = %s\n", errno, strerror (errno));
00179 #endif
00180 return -1;;
00181 }
00182 return 0;
00183 }