bjh 99/10/18 04:32:14
Modified: src/lib/apr/network_io/os2 sockopt.c Log: OS/2: Use unix version of sockopt.c Revision Changes Path 1.5 +1 -128 apache-2.0/src/lib/apr/network_io/os2/sockopt.c Index: sockopt.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockopt.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- sockopt.c 1999/10/10 20:34:56 1.4 +++ sockopt.c 1999/10/18 11:32:13 1.5 @@ -53,131 +53,4 @@ * */ -#include "networkio.h" -#include "apr_network_io.h" -#include "apr_general.h" -#include "apr_lib.h" -#include <errno.h> -#include <string.h> -#include <sys/socket.h> -#include <netinet/tcp.h> -#include <netinet/in.h> -#include <unistd.h> -#include <fcntl.h> -#include <netdb.h> - -int soblock(int sd) -{ - int fd_flags; - - fd_flags = fcntl(sd, F_GETFL, 0); -#if defined(O_NONBLOCK) - fd_flags &= ~O_NONBLOCK; -#elif defined(O_NDELAY) - fd_flags &= ~O_NDELAY; -#elif defined(FNDELAY) - fd_flags &= ~O_FNDELAY; -#else - /* XXXX: this breaks things, but an alternative isn't obvious...*/ - return -1; -#endif - if (fcntl(sd, F_SETFL, fd_flags) == -1) { - return errno; - } - return APR_SUCCESS; -} - -ap_status_t sononblock(int sd) -{ - int fd_flags; - - fd_flags = fcntl(sd, F_GETFL, 0); -#if defined(O_NONBLOCK) - fd_flags |= O_NONBLOCK; -#elif defined(O_NDELAY) - fd_flags |= O_NDELAY; -#eli f defined(FNDELAY) - fd_flags |= O_FNDELAY; -#else - /* XXXX: this breaks things, but an alternative isn't obvious...*/ - return -1; -#endif - if (fcntl(sd, F_SETFL, fd_flags) == -1) { - return errno; - } - return APR_SUCCESS; -} - - -ap_status_t ap_setsocketopt(struct socket_t *sock, ap_int32_t opt, ap_int32_t on) -{ - int one; - struct linger li; - ap_status_t stat; - - if (on) - one = 1; - else - one = 0; - - if (opt & APR_SO_KEEPALIVE) { - if (setsockopt(sock->socketdes, SOL_SOCKET, SO_KEEPALIVE, (void *)&one, sizeof(int)) == -1) { - return errno; - } - } - if (opt & APR_SO_DEBUG) { - if (setsockopt(sock->socketdes, SOL_SOCKET, SO_DEBUG, (void *)&one, sizeof(int)) == -1) { - return errno; - } - } - if (opt & APR_SO_REUSEADDR) { - if (setsockopt(sock->socketdes, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(int)) == -1) { - return errno; - } - } - if (opt & APR_SO_NONBLOCK) { - if (on) { - if ((stat = soblock(sock->socketdes)) != APR_SUCCESS) - return stat; - } - else { - if ((stat = sononblock(sock->socketdes)) != APR_SUCCESS) - return stat; - } - } - if (opt & APR_SO_LINGER) { - li.l_onoff = on; - li.l_linger = MAX_SECS_TO_LINGER; - if (setsockopt(sock->socketdes, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(struct linger)) == -1) { - return errno; - } - } - return APR_SUCCESS; -} - -ap_status_t ap_gethostname(char *buf, int len, ap_context_t *cont) -{ - if (gethostname(buf, len) == -1) - return errno; - else - return APR_SUCCESS; -} - -ap_status_t ap_get_remote_hostname(char **name, struct socket_t *sock) -{ - struct hostent *hptr; - - hptr = gethostbyaddr((char *)&(sock->addr->sin_addr), - sizeof(struct in_addr), AF_INET); - if (hptr != NULL) { - *name = ap_pstrdup(sock->cntxt, hptr->h_name); - if (*name) { - return APR_SUCCESS; - } - return APR_ENOMEM; - } - /* XXX - Is this threadsafe? - manoj */ - return h_errno; -} - - +#include "../unix/sockopt.c"