diff --git a/os/Xtrans.c b/os/Xtrans.c index 9c9c851b7e..5dd8729543 100644 --- a/os/Xtrans.c +++ b/os/Xtrans.c @@ -117,13 +117,6 @@ Xtransport_table Xtransports[] = { #define NUMTRANS (sizeof(Xtransports)/sizeof(Xtransport_table)) - -#ifdef WIN32 -#define ioctl ioctlsocket -#endif - - - /* * These are a few utility function used by the public interface functions. */ @@ -564,7 +557,7 @@ int _XSERVTransNonBlock(XtransConnInfo ciptr) { int arg; arg = 1; - ret = ioctl (fd, FIOSNBIO, &arg); + ret = ossock_ioctl (fd, FIOSNBIO, &arg); } #else #if defined(WIN32) @@ -572,7 +565,7 @@ int _XSERVTransNonBlock(XtransConnInfo ciptr) u_long arg_ret = 1; /* IBM TCP/IP understands this option too well: it causes _XSERVTransRead to fail * eventually with EWOULDBLOCK */ - ret = ioctl (fd, FIONBIO, &arg_ret); + ret = ossock_ioctl (fd, FIONBIO, &arg_ret); } #else ret = fcntl (fd, F_GETFL, 0); diff --git a/os/Xtranssock.c b/os/Xtranssock.c index b608630ddf..455356f1a3 100644 --- a/os/Xtranssock.c +++ b/os/Xtranssock.c @@ -74,6 +74,8 @@ from the copyright holders. #include #endif +#include "os/ossock.h" + #ifndef WIN32 #if defined(TCPCONN) || defined(UNIXCONN) @@ -1178,15 +1180,7 @@ static int _XSERVTransSocketBytesReadable ( { prmsg (2,"SocketBytesReadable(%p,%d,%p)\n", (void *) ciptr, ciptr->fd, (void *) pend); -#ifdef WIN32 - { - int ret = ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend); - if (ret == SOCKET_ERROR) errno = WSAGetLastError(); - return ret; - } -#else - return ioctl (ciptr->fd, FIONREAD, (char *) pend); -#endif /* WIN32 */ + return ossock_ioctl (ciptr->fd, FIONREAD, pend); } #if XTRANS_SEND_FDS diff --git a/os/ossock.c b/os/ossock.c index 3100b63126..22dfaed2e3 100644 --- a/os/ossock.c +++ b/os/ossock.c @@ -6,6 +6,8 @@ #ifdef WIN32 #include +#else +#include #endif #include "os/ossock.h" @@ -18,3 +20,15 @@ void ossock_init(void) WSAStartup(0x0202, &wsadata); #endif } + +int ossock_ioctl(int fd, unsigned long request, void *arg) +{ +#ifdef WIN32 + int ret = ioctlsocket(fd, request, arg); + if (ret == SOCKET_ERROR) + ret = WSAGetLastError(); + return ret; +#else + return ioctl(fd, request,arg); +#endif +} diff --git a/os/ossock.h b/os/ossock.h index c62575693b..1faeb0b545 100644 --- a/os/ossock.h +++ b/os/ossock.h @@ -5,9 +5,16 @@ #ifndef _XSERVER_OS_OSSOCK_H_ #define _XSERVER_OS_OSSOCK_H_ +#include + /* * os specific initialization of the socket layer */ void ossock_init(void); +/* + * os specific socket ioctl function + */ +int ossock_ioctl(int fd, unsigned long request, void *arg); + #endif /* _XSERVER_OS_OSSOCK_H_ */