? extras/Mesa/mms-config ? lib/xtrans/Xtranswin32.c Index: config/cf/cygwin.cf =================================================================== RCS file: /cvs/xorg/xc/config/cf/cygwin.cf,v retrieving revision 1.16 diff -u -r1.16 cygwin.cf --- config/cf/cygwin.cf 30 Oct 2004 01:41:46 -0000 1.16 +++ config/cf/cygwin.cf 9 Nov 2004 16:18:05 -0000 @@ -242,7 +242,7 @@ -D_X86_ -D__CYGWIN__ -D_XOPEN_SOURCE \ -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE \ -D_SVID_SOURCE -D_GNU_SOURCE -DFD_SETSIZE=256 \ - -DXResExtension + -DXResExtension -DWINSOCK2XWIN #define XawI18nDefines -DHAS_WCHAR_H -DHAS_WCTYPE_H \ -DHAS_ISW_FUNCS -DNO_WIDEC_H #define StandardCppOptions -traditional @@ -306,6 +306,9 @@ #ifndef BuildXWinXF86Config # define BuildXWinXF86Config NO #endif +#ifndef BuildLBX +# define BuildLBX NO +#endif /* XWin specific build flags - 1st order dependency */ #if BuildXWinMultiWindowExtWM && !defined(BuildWindowsWMLibrary) @@ -377,7 +380,8 @@ #define XkbServerDefines -DXKB_ALWAYS_USES_SOFT_REPEAT #define ServerExtraDefines -DGCCUSESGAS XWinServerDefines \ AllocateLocalDefines -#define ConnectionFlags -DTCPCONN -DUNIXCONN +/* #define ConnectionFlags -DTCPCONN -DUNIXCONN */ +#define ConnectionFlags -DTCPCONN #define ExtraLibraries #define InstUidFlags -m 4711 #define UseRgbTxt YES @@ -423,7 +427,7 @@ /* Server build rules */ #ifndef XnestServer -# define XnestServer YES +# define XnestServer NO #endif #ifndef XprtServer # define XprtServer NO @@ -434,6 +438,9 @@ #ifndef XWinServer # define XWinServer YES #endif +#if BuildFonts +# define BuildFonts YES +#endif /* We need libX11 and libXext for the XWin Server */ #if XWinServer Index: include/Imakefile =================================================================== RCS file: /cvs/xorg/xc/include/Imakefile,v retrieving revision 1.3 diff -u -r1.3 Imakefile --- include/Imakefile 9 Aug 2004 22:37:21 -0000 1.3 +++ include/Imakefile 9 Nov 2004 16:19:11 -0000 @@ -17,7 +17,7 @@ SUBDIRS = bitmaps extensions fonts $(GLXDIR) $(DPSDIR) -#ifdef Win32Architecture +#if defined(Win32Architecture) || defined(XWinServer) EXTRA_HEADERS = Xw32defs.h Xwinsock.h #endif Index: include/Xos.h =================================================================== RCS file: /cvs/xorg/xc/include/Xos.h,v retrieving revision 1.2 diff -u -r1.2 Xos.h --- include/Xos.h 23 Apr 2004 18:43:05 -0000 1.2 +++ include/Xos.h 9 Nov 2004 16:19:11 -0000 @@ -154,7 +154,7 @@ #endif #ifdef WIN32 #include -#else +#elif !defined(__USE_W32_SOCKETS) #include #endif #else /* X_NOT_POSIX */ @@ -209,9 +209,9 @@ #undef _POSIX_SOURCE #include #define _POSIX_SOURCE -#elif defined(WIN32) +#elif defined(WIN32) || defined(__USE_W32_SOCKETS) #include -#if !defined(_WINSOCKAPI_) && !defined(_WILLWINSOCK_) +#if !defined(_WINSOCKAPI_) && !defined(_WILLWINSOCK_) && !defined(__USE_W32_SOCKETS) struct timeval { long tv_sec; /* seconds */ long tv_usec; /* and microseconds */ @@ -245,7 +245,7 @@ #if defined(_XOPEN_XPG4) || defined(_XOPEN_UNIX) /* _XOPEN_UNIX is XPG4.2 */ #define X_GETTIMEOFDAY(t) gettimeofday(t, (struct timezone*)0) #else -#if defined(SVR4) || defined(VMS) || defined(WIN32) +#if defined(SVR4) || defined(VMS) || defined(WIN32) || defined(__USE_W32_SOCKETS) #define X_GETTIMEOFDAY(t) gettimeofday(t) #else #define X_GETTIMEOFDAY(t) gettimeofday(t, (struct timezone*)0) Index: include/Xos_r.h =================================================================== RCS file: /cvs/xorg/xc/include/Xos_r.h,v retrieving revision 1.2 diff -u -r1.2 Xos_r.h --- include/Xos_r.h 23 Apr 2004 18:43:05 -0000 1.2 +++ include/Xos_r.h 9 Nov 2004 16:19:12 -0000 @@ -405,7 +405,7 @@ #undef XTHREADS_NEEDS_BYNAMEPARAMS #if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) \ - && !defined(WIN32) + && !defined(WIN32) && !defined(__USE_W32_SOCKETS) # include # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_NETDBAPI) # define XOS_USE_MTSAFE_NETDBAPI 1 Index: include/Xpoll.h =================================================================== RCS file: /cvs/xorg/xc/include/Xpoll.h,v retrieving revision 1.4 diff -u -r1.4 Xpoll.h --- include/Xpoll.h 25 Jun 2004 09:15:35 -0000 1.4 +++ include/Xpoll.h 9 Nov 2004 16:19:12 -0000 @@ -32,7 +32,7 @@ #ifndef _XPOLL_H_ #define _XPOLL_H_ -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) #ifndef USE_POLL @@ -163,9 +163,13 @@ #ifndef FD_SETSIZE #define FD_SETSIZE XFD_SETSIZE #endif +#ifndef NBBY +#define NBBY 8 /* number of bits in a byte */ +#endif #include -#define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t) +//#define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t) +#define Select(n,r,w,x,t) win32Select(n,r,w,x,t) #define XFD_SETCOUNT(p) (((fd_set FAR *)(p))->fd_count) #define XFD_FD(p,i) (((fd_set FAR *)(p))->fd_array[i]) Index: include/Xwinsock.h =================================================================== RCS file: /cvs/xorg/xc/include/Xwinsock.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 Xwinsock.h --- include/Xwinsock.h 14 Nov 2003 16:48:42 -0000 1.1.1.1 +++ include/Xwinsock.h 9 Nov 2004 16:19:14 -0000 @@ -34,12 +34,24 @@ * in the whole Windows API... */ +#if defined(WINSOCK2XWIN) +#if defined(XFree86Server) +#undef XFree86Server +#define __XFree86Server +#endif +#define INT32 wINT32 +#define BYTE wBYTE +#endif #define BOOL wBOOL +#define ATOM wATOM #undef Status #define Status wStatus -#define ATOM wATOM #define FreeResource wFreeResource +#if defined(__USE_W32_SOCKETS) +#include +#else #include +#endif #undef Status #define Status int #undef BOOL @@ -48,3 +60,12 @@ #undef CreateWindowA #undef RT_FONT #undef RT_CURSOR +#if defined(__USE_W32_SOCKETS) +#undef WIN32 +#if defined(__XFree86Server) +#undef __XFree86Server +#define XFree86Server +#undef BYTE +#endif +#undef INT32 +#endif Index: lib/X11/Imakefile =================================================================== RCS file: /cvs/xorg/xc/lib/X11/Imakefile,v retrieving revision 1.7 diff -u -r1.7 Imakefile --- lib/X11/Imakefile 1 Sep 2004 01:04:33 -0000 1.7 +++ lib/X11/Imakefile 9 Nov 2004 16:19:21 -0000 @@ -52,8 +52,11 @@ #ifdef cygwinArchitecture EXCLUDE_SYMBOL = -Wl,--exclude-symbol,XdmcpWrap:_XdmcpWrapperToOddParity #endif +#if defined(XWinServer) && XWinServer +XWINLIBS = -lws2_32 +#endif -REQUIREDLIBS=$(REQUIREDX11LIBS) $(REQUIREDI18NLIBS) $(EXCLUDE_SYMBOL) +REQUIREDLIBS=$(REQUIREDX11LIBS) $(REQUIREDI18NLIBS) $(EXCLUDE_SYMBOL) $(XWINLIBS) #if defined(MacIIArchitecture) || defined(SequentArchitecture) || defined(i386ScoArchitecture) XBSDLIB = /**/ Index: lib/xtrans/Xtrans.c =================================================================== RCS file: /cvs/xorg/xc/lib/xtrans/Xtrans.c,v retrieving revision 1.3 diff -u -r1.3 Xtrans.c --- lib/xtrans/Xtrans.c 17 Jul 2004 01:13:31 -0000 1.3 +++ lib/xtrans/Xtrans.c 9 Nov 2004 16:19:29 -0000 @@ -128,7 +128,7 @@ #define NUMTRANS (sizeof(Xtransports)/sizeof(Xtransport_table)) -#ifdef WIN32 +#if defined(WIN32) || defined(__USE_W32_SOCKETS) #define ioctl ioctlsocket #endif @@ -423,7 +423,7 @@ PRMSG (2,"Open(%d,%s)\n", type, address, 0); -#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN)) +#if (defined(WIN32) || defined(__USE_W32_SOCKETS)) && (defined(TCPCONN) || defined(DNETCONN)) if (TRANS(WSAStartup)()) { PRMSG (1,"Open: WSAStartup failed\n", 0, 0, 0); @@ -724,7 +724,7 @@ ret = ioctl (fd, FIOSNBIO, &arg); } #else -#if (defined(AIXV3) || defined(uniosu) || defined(WIN32) || defined(__UNIXOS2__) || defined(__QNX__)) && defined(FIONBIO) +#if (defined(AIXV3) || defined(uniosu) || defined(WIN32) || defined(__UNIXOS2__) || defined(__QNX__)) && defined(FIONBIO) || defined(__USE_W32_SOCKETS) { int arg; arg = 1; @@ -1299,7 +1299,7 @@ #endif /* CRAY */ -#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) +#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) || defined(__USE_W32_SOCKETS) /* * emulate readv @@ -1331,7 +1331,7 @@ #endif /* SYSV && i386 || WIN32 || __sxg__ */ -#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) +#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) || defined(__USE_W32_SOCKETS) /* * emulate writev Index: lib/xtrans/Xtrans.h =================================================================== RCS file: /cvs/xorg/xc/lib/xtrans/Xtrans.h,v retrieving revision 1.2 diff -u -r1.2 Xtrans.h --- lib/xtrans/Xtrans.h 23 Apr 2004 18:44:27 -0000 1.2 +++ lib/xtrans/Xtrans.h 9 Nov 2004 16:19:29 -0000 @@ -57,7 +57,7 @@ #include #include -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) #ifndef Lynx #include #else @@ -483,7 +483,7 @@ int /* maxlen */ ); -#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN)) +#if (defined(WIN32) || defined(__USE_W32_SOCKETS)) && (defined(TCPCONN) || defined(DNETCONN)) int TRANS(WSAStartup)(); #endif Index: lib/xtrans/Xtransint.h =================================================================== RCS file: /cvs/xorg/xc/lib/xtrans/Xtransint.h,v retrieving revision 1.2 diff -u -r1.2 Xtransint.h --- lib/xtrans/Xtransint.h 23 Apr 2004 18:44:27 -0000 1.2 +++ lib/xtrans/Xtransint.h 9 Nov 2004 16:19:29 -0000 @@ -93,7 +93,7 @@ #include -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) # ifndef Lynx # include # else @@ -383,7 +383,7 @@ * systems, so they may be emulated. */ -#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) +#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) || defined(__USE_W32_SOCKETS) #define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt) @@ -400,7 +400,7 @@ #endif /* CRAY || (SYSV && i386) || WIN32 || __sxg__ || */ -#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) +#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) || defined(__USE_W32_SOCKETS) #define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt) Index: lib/xtrans/Xtranssock.c =================================================================== RCS file: /cvs/xorg/xc/lib/xtrans/Xtranssock.c,v retrieving revision 1.2 diff -u -r1.2 Xtranssock.c --- lib/xtrans/Xtranssock.c 23 Apr 2004 18:44:27 -0000 1.2 +++ lib/xtrans/Xtranssock.c 9 Nov 2004 16:19:31 -0000 @@ -58,7 +58,7 @@ #include #endif -#ifndef WIN32 +#if !defined(WIN32) && !defined(WINSOCK2XWIN) #if defined(TCPCONN) || defined(UNIXCONN) #include @@ -114,9 +114,12 @@ #else /* !WIN32 */ #include +#if !defined(WINSOCK2XWIN) #include +#endif #undef close #define close closesocket +#if !defined(__USE_W32_SOCKETS) #define ECONNREFUSED WSAECONNREFUSED #define EADDRINUSE WSAEADDRINUSE #define EPROTOTYPE WSAEPROTOTYPE @@ -124,6 +127,7 @@ #define EWOULDBLOCK WSAEWOULDBLOCK #undef EINTR #define EINTR WSAEINTR +#endif #define X_INCLUDE_NETDB_H #define XOS_USE_MTSAFE_NETDBAPI #include @@ -288,6 +292,73 @@ static int haveIPv6 = 1; #endif +#if !defined(__USE_W32_SOCKETS) +#define FD_TO_SOCKET(x) do{}while(0) +#define SOCKET_TO_FD(x) do{}while(0) +#define FREE_FD(x) do{}while(0) +#else +#define FD_TO_SOCKET(x) TRANS(FdToSocket)(x) +#define SOCKET_TO_FD(x) TRANS(SocketToFd)(x) +#define FREE_FD(x) TRANS(FreeFd)(x) +#endif + +#if defined(__USE_W32_SOCKETS) +#define MAXFD 500 +static SOCKET g_fdSockets[MAXFD]; +static int g_fdSocketsInitialized = FALSE; + +void TRANS(InitFdSocketTable)() +{ + if (!g_fdSocketsInitialized) + { + int i; + for (i = 0; i < MAXFD; i++) + { + g_fdSockets[i] = INVALID_SOCKET; + } + g_fdSocketsInitialized = TRUE; + } +} + +SOCKET TRANS(FdToSocket)(int fd) +{ + TRANS(InitFdSocketTable)(); + if (fd < 0 || fd > MAXFD - 1) + { + return -1; + } + return g_fdSockets[fd]; +} + +int TRANS(SocketToFd)(SOCKET s) +{ + int i; + int freefd = -1; + TRANS(InitFdSocketTable)(); + + for(i = 0; i < MAXFD; i++) + { + if (g_fdSockets[i] == s) + return i; + if (g_fdSockets[i] == INVALID_SOCKET) freefd = i; + } + if (freefd < 0) + { + //nomore fd + } + else + { + g_fdSockets[freefd] = s; + } + return freefd; +} + +void TRANS(FreeFd)(int fd) +{ + g_fdSockets[fd] = INVALID_SOCKET; +} +#endif + /* * These are some utility function used by the real interface function below. */ @@ -345,7 +416,7 @@ socknamePtr = &socknamev4; } - if (getsockname (ciptr->fd,(struct sockaddr *) socknamePtr, + if (getsockname (FD_TO_SOCKET(ciptr->fd),(struct sockaddr *) socknamePtr, (void *)&namelen) < 0) { PRMSG (1,"SocketINETGetAddr: getsockname() failed: %d\n", @@ -417,7 +488,7 @@ PRMSG (3,"SocketINETGetPeerAddr(%p)\n", ciptr, 0, 0); - if (getpeername (ciptr->fd, (struct sockaddr *) socknamePtr, + if (getpeername (FD_TO_SOCKET(ciptr->fd), (struct sockaddr *) socknamePtr, (void *)&namelen) < 0) { PRMSG (1,"SocketINETGetPeerAddr: getpeername() failed: %d\n", @@ -467,9 +538,14 @@ return NULL; } - if ((ciptr->fd = socket(Sockettrans2devtab[i].family, type, - Sockettrans2devtab[i].protocol)) < 0 -#ifndef WIN32 + if ((ciptr->fd = SOCKET_TO_FD(socket(Sockettrans2devtab[i].family, type, + Sockettrans2devtab[i].protocol))) +#if defined(WIN32) || defined(__USE_W32_SOCKETS) + == INVALID_SOCKET +#else + < 0 +#endif +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) #if (defined(X11_t) && !defined(USE_POLL)) || defined(FS_t) || defined(FONT_t) || ciptr->fd >= TRANS_OPEN_MAX #endif @@ -481,6 +557,8 @@ xfree ((char *) ciptr); return NULL; } + PRMSG (3, "SocketOpen: socket() fd = %d\n", + ciptr->fd, 0, 0); #ifdef TCP_NODELAY if (Sockettrans2devtab[i].family == AF_INET @@ -494,7 +572,7 @@ */ int tmp = 1; - setsockopt (ciptr->fd, IPPROTO_TCP, TCP_NODELAY, + setsockopt (FD_TO_SOCKET(ciptr->fd), IPPROTO_TCP, TCP_NODELAY, (char *) &tmp, sizeof (int)); } #endif @@ -626,7 +704,7 @@ ) { int one = 1; - setsockopt (ciptr->fd, SOL_SOCKET, SO_REUSEADDR, + setsockopt (FD_TO_SOCKET(ciptr->fd), SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (int)); } #endif @@ -634,7 +712,7 @@ if (Sockettrans2devtab[i].family == AF_INET6) { int one = 1; - setsockopt(ciptr->fd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(int)); + setsockopt(FD_TO_SOCKET(ciptr->fd), IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(int)); } #endif /* Save the index for later use */ @@ -719,7 +797,7 @@ if (Sockettrans2devtab[i].family == AF_INET6) { int one = 1; - setsockopt(ciptr->fd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(int)); + setsockopt(FD_TO_SOCKET(ciptr->fd), IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(int)); } #endif /* Save the index for later use */ @@ -860,7 +938,7 @@ else retry = 0; - while (bind (fd, (struct sockaddr *) sockname, namelen) < 0) + while (bind (FD_TO_SOCKET(fd), (struct sockaddr *) sockname, namelen) < 0) { if (errno == EADDRINUSE) { if (flags & ADDR_IN_USE_ALLOWED) @@ -872,7 +950,8 @@ if (retry-- == 0) { PRMSG (1, "SocketCreateListener: failed to bind listener\n", 0, 0, 0); - close (fd); + close (FD_TO_SOCKET(fd)); + FREE_FD(fd); return TRANS_CREATE_LISTENER_FAILED; } #ifdef SO_REUSEADDR @@ -888,22 +967,23 @@ #endif ) { #ifdef SO_DONTLINGER - setsockopt (fd, SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0); + setsockopt (FD_TO_SOCKET(fd), SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0); #else #ifdef SO_LINGER { static int linger[2] = { 0, 0 }; - setsockopt (fd, SOL_SOCKET, SO_LINGER, + setsockopt (FD_TO_SOCKET(fd), SOL_SOCKET, SO_LINGER, (char *) linger, sizeof (linger)); } #endif #endif } - if (listen (fd, BACKLOG) < 0) + if (listen (FD_TO_SOCKET(fd), BACKLOG) < 0) { PRMSG (1, "SocketCreateListener: listen() failed\n", 0, 0, 0); - close (fd); + close (FD_TO_SOCKET(fd)); + FREE_FD(fd); return TRANS_CREATE_LISTENER_FAILED; } @@ -1174,26 +1254,29 @@ } #endif - close (ciptr->fd); + close (FD_TO_SOCKET(ciptr->fd)); + FD_FREE(ciptr->fd); unlink (unsock->sun_path); - if ((ciptr->fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) + if ((ciptr->fd = SOCKET_TO_FD(socket (AF_UNIX, SOCK_STREAM, 0))) < 0) { TRANS(FreeConnInfo) (ciptr); (void) umask (oldUmask); return TRANS_RESET_FAILURE; } - if (bind (ciptr->fd, (struct sockaddr *) unsock, ciptr->addrlen) < 0) + if (bind (FD_TO_SOCKET(ciptr->fd), (struct sockaddr *) unsock, ciptr->addrlen) < 0) { - close (ciptr->fd); + close (FD_TO_SOCKET(ciptr->fd)); + FREE_FD(ciptr->fd); TRANS(FreeConnInfo) (ciptr); return TRANS_RESET_FAILURE; } - if (listen (ciptr->fd, BACKLOG) < 0) + if (listen (FD_TO_SOCKET(ciptr->fd), BACKLOG) < 0) { close (ciptr->fd); + FREE_FD(ciptr->fd); TRANS(FreeConnInfo) (ciptr); (void) umask (oldUmask); return TRANS_RESET_FAILURE; @@ -1230,8 +1313,8 @@ return NULL; } - if ((newciptr->fd = accept (ciptr->fd, - (struct sockaddr *) &sockname, (void *)&namelen)) < 0) + if ((newciptr->fd = SOCKET_TO_FD(accept (FD_TO_SOCKET(ciptr->fd), + (struct sockaddr *) &sockname, (void *)&namelen))) < 0) { PRMSG (1, "SocketINETAccept: accept() failed\n", 0, 0, 0); xfree (newciptr); @@ -1246,7 +1329,7 @@ */ int tmp = 1; - setsockopt (newciptr->fd, IPPROTO_TCP, TCP_NODELAY, + setsockopt (FD_TO_SOCKET(newciptr->fd), IPPROTO_TCP, TCP_NODELAY, (char *) &tmp, sizeof (int)); } #endif @@ -1261,7 +1344,8 @@ PRMSG (1, "SocketINETAccept: ...SocketINETGetAddr() failed:\n", 0, 0, 0); - close (newciptr->fd); + close (FD_TO_SOCKET(newciptr->fd)); + FREE_FD(newciptr->fd); xfree (newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; @@ -1272,7 +1356,8 @@ PRMSG (1, "SocketINETAccept: ...SocketINETGetPeerAddr() failed:\n", 0, 0, 0); - close (newciptr->fd); + close (FD_TO_SOCKET(newciptr->fd)); + FREE_FD(newciptr->fd); if (newciptr->addr) xfree (newciptr->addr); xfree (newciptr); *status = TRANS_ACCEPT_MISC_ERROR; @@ -1310,8 +1395,8 @@ return NULL; } - if ((newciptr->fd = accept (ciptr->fd, - (struct sockaddr *) &sockname, (void *)&namelen)) < 0) + if ((newciptr->fd = FD_TO_SOCKET(accept (ciptr->fd, + (struct sockaddr *) &sockname, (void *)&namelen))) < 0) { PRMSG (1, "SocketUNIXAccept: accept() failed\n", 0, 0, 0); xfree (newciptr); @@ -1329,7 +1414,8 @@ PRMSG (1, "SocketUNIXAccept: Can't allocate space for the addr\n", 0, 0, 0); - close (newciptr->fd); + close (FD_TO_SOCKET(newciptr->fd)); + FREE_FD(newciptr->fd); xfree (newciptr); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; @@ -1344,7 +1430,8 @@ PRMSG (1, "SocketUNIXAccept: Can't allocate space for the addr\n", 0, 0, 0); - close (newciptr->fd); + close (FD_TO_SOCKET(newciptr->fd)); + FREE_FD(newciptr->fd); if (newciptr->addr) xfree (newciptr->addr); xfree (newciptr); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -1677,7 +1764,7 @@ { int tmp = 1; - setsockopt (ciptr->fd, SOL_SOCKET, SO_KEEPALIVE, + setsockopt (FD_TO_SOCKET(ciptr->fd), SOL_SOCKET, SO_KEEPALIVE, (char *) &tmp, sizeof (int)); } @@ -1685,9 +1772,9 @@ * Do the connect() */ - if (connect (ciptr->fd, socketaddr, socketaddrlen ) < 0) + if (connect (FD_TO_SOCKET(ciptr->fd), socketaddr, socketaddrlen ) < 0) { -#ifdef WIN32 +#if defined(WIN32) || defined(__USE_W32_SOCKETS) int olderrno = WSAGetLastError(); #else int olderrno = errno; @@ -1997,7 +2084,7 @@ * Do the connect() */ - if (connect (ciptr->fd, (struct sockaddr *) &sockname, namelen) < 0) + if (connect (FD_TO_SOCKET(ciptr->fd), (struct sockaddr *) &sockname, namelen) < 0) { int olderrno = errno; int connected = 0; @@ -2005,7 +2092,7 @@ #if defined(hpux) && defined(X11_t) if (olderrno == ENOENT) { - if (connect (ciptr->fd, + if (connect (FD_TO_SOCKET(ciptr->fd), (struct sockaddr *) &old_sockname, old_namelen) >= 0) { connected = 1; @@ -2080,8 +2167,8 @@ #if defined(QNX4) *pend = 0L; /* FIONREAD only returns a short. Zero out upper bits */ #endif -#ifdef WIN32 - return ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend); +#if defined(WIN32) || defined(__USE_W32_SOCKETS) + return ioctlsocket ((SOCKET) FD_TO_SOCKET(ciptr->fd), FIONREAD, (u_long *) pend); #else #if (defined(i386) && defined(SYSV) && !defined(sco)) || (defined(_SEQUENT_) && _SOCKET_VERSION == 1) return ioctl (ciptr->fd, I_NREAD, (char *) pend); @@ -2102,8 +2189,8 @@ { PRMSG (2,"SocketRead(%d,%p,%d)\n", ciptr->fd, buf, size); -#if defined(WIN32) || defined(__UNIXOS2__) - return recv ((SOCKET)ciptr->fd, buf, size, 0); +#if defined(WIN32) || defined(__UNIXOS2__) || defined(__USE_W32_SOCKETS) + return recv ((SOCKET)FD_TO_SOCKET(ciptr->fd), buf, size, 0); #else return read (ciptr->fd, buf, size); #endif /* WIN32 */ @@ -2116,8 +2203,8 @@ { PRMSG (2,"SocketWrite(%d,%p,%d)\n", ciptr->fd, buf, size); -#if defined(WIN32) || defined(__UNIXOS2__) - return send ((SOCKET)ciptr->fd, buf, size, 0); +#if defined(WIN32) || defined(__UNIXOS2__) || defined(__USE_W32_SOCKETS) + return send ((SOCKET)FD_TO_SOCKET(ciptr->fd), buf, size, 0); #else return write (ciptr->fd, buf, size); #endif /* WIN32 */ @@ -2150,7 +2237,7 @@ { PRMSG (2,"SocketDisconnect(%p,%d)\n", ciptr, ciptr->fd, 0); - return shutdown (ciptr->fd, 2); /* disallow further sends and receives */ + return shutdown (FD_TO_SOCKET(ciptr->fd), 2); /* disallow further sends and receives */ } @@ -2161,7 +2248,8 @@ { PRMSG (2,"SocketINETClose(%p,%d)\n", ciptr, ciptr->fd, 0); - return close (ciptr->fd); + FREE_FD(ciptr->fd); + return close (FD_TO_SOCKET(ciptr->fd)); } #endif /* TCPCONN */ @@ -2183,7 +2271,8 @@ PRMSG (2,"SocketUNIXClose(%p,%d)\n", ciptr, ciptr->fd, 0); - ret = close(ciptr->fd); + ret = close(FD_TO_SOCKET(ciptr->fd)); + FREE_FD(ciptr->fd); if (ciptr->flags && sockname @@ -2212,7 +2301,8 @@ PRMSG (2,"SocketUNIXCloseForCloning(%p,%d)\n", ciptr, ciptr->fd, 0); - ret = close(ciptr->fd); + ret = close(FD_TO_SOCKET(ciptr->fd)); + FREE_FD(ciptr->fd); return ret; } Index: lib/xtrans/Xtransutil.c =================================================================== RCS file: /cvs/xorg/xc/lib/xtrans/Xtransutil.c,v retrieving revision 1.5 diff -u -r1.5 Xtransutil.c --- lib/xtrans/Xtransutil.c 27 Aug 2004 22:47:45 -0000 1.5 +++ lib/xtrans/Xtransutil.c 9 Nov 2004 16:19:32 -0000 @@ -464,7 +464,7 @@ #endif /* ICE_t */ -#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN)) +#if (defined(WIN32) || defined(__USE_W32_SOCKETS)) && (defined(TCPCONN) || defined(DNETCONN)) int TRANS(WSAStartup) (void) { Index: lib/xtrans/transport.c =================================================================== RCS file: /cvs/xorg/xc/lib/xtrans/transport.c,v retrieving revision 1.2 diff -u -r1.2 transport.c --- lib/xtrans/transport.c 23 Apr 2004 18:44:27 -0000 1.2 +++ lib/xtrans/transport.c 9 Nov 2004 16:19:32 -0000 @@ -55,6 +55,10 @@ #define I_NEED_OS2_H #endif +#if defined(WINSOCK2XWIN) +#define __USE_W32_SOCKETS +#endif + #ifdef XSERV_t #include "os.h" #else Index: programs/Xserver/Imakefile =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/Imakefile,v retrieving revision 1.20 diff -u -r1.20 Imakefile --- programs/Xserver/Imakefile 28 Sep 2004 20:50:02 -0000 1.20 +++ programs/Xserver/Imakefile 9 Nov 2004 16:19:37 -0000 @@ -1013,7 +1013,7 @@ XWINOBJS = $(XWINDDXDIR)/stubs.o $(XWINDDXDIR)/XWin.res XWINLIBS = PreFbLibs $(XWINLIB) FbPostFbLibs $(XWINLIB) $(XWINLAYERLIB) \ $(SHADOW) $(XWINPARSERLIB) $(ROOTLESSLIB) -XWINSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XONLYLIB) $(SYSLIBS) -lgdi32 +XWINSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XONLYLIB) $(SYSLIBS) -lgdi32 -lws2_32 EXTRA_LDOPTIONS = -e _mainCRTStartup Index: programs/Xserver/hw/xwin/InitInput.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xwin/InitInput.c,v retrieving revision 1.3 diff -u -r1.3 InitInput.c --- programs/Xserver/hw/xwin/InitInput.c 21 Jun 2004 13:19:32 -0000 1.3 +++ programs/Xserver/hw/xwin/InitInput.c 9 Nov 2004 16:20:21 -0000 @@ -163,7 +163,11 @@ } /* Add the message queue as a device to wait for in WaitForSomething */ +#if defined(WINSOCK2XWIN) + //FIXME: Something like WaitForMultipleObjects? +#else AddEnabledDevice (g_fdMessageQueue); +#endif } #if CYGDEBUG Index: programs/Xserver/include/os.h =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/include/os.h,v retrieving revision 1.2 diff -u -r1.2 os.h --- programs/Xserver/include/os.h 23 Apr 2004 19:54:23 -0000 1.2 +++ programs/Xserver/include/os.h 9 Nov 2004 16:20:21 -0000 @@ -290,7 +290,7 @@ void OsReleaseSignals (void); -#if !defined(WIN32) && !defined(__UNIXOS2__) +#if !defined(WIN32) && !defined(__UNIXOS2__) && !defined(__USE_W32_SOCKETS) extern int System(char *); extern pointer Popen(char *, char *); extern int Pclose(pointer); Index: programs/Xserver/os/WaitFor.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/WaitFor.c,v retrieving revision 1.3 diff -u -r1.3 WaitFor.c --- programs/Xserver/os/WaitFor.c 18 Oct 2004 14:21:46 -0000 1.3 +++ programs/Xserver/os/WaitFor.c 9 Nov 2004 16:20:21 -0000 @@ -56,8 +56,13 @@ * *****************************************************************/ -#ifdef WIN32 +#if defined(WINSOCK2XWIN) +#define __USE_W32_SOCKETS +#endif + +#if defined(WIN32) || defined(__USE_W32_SOCKETS) #include +#define errno WSAGetLastError() #endif #include "Xos.h" /* for strings, fcntl, time */ #include @@ -77,6 +82,7 @@ #endif /* modifications by raphael */ +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) int mffs(fd_mask mask) { @@ -91,6 +97,7 @@ } return i; } +#endif #ifdef DPMSExtension #define DPMS_SERVER @@ -113,6 +120,9 @@ static void DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev); static OsTimerPtr timers = NULL; +#if defined(__USE_W32_SOCKETS) +int win32Select(int n,fd_set* r,fd_set* w,fd_set* x,const struct timeval* t); +#endif /***************** * WaitForSomething: @@ -130,7 +140,7 @@ * For more info on ClientsWithInput, see ReadRequestFromClient(). * pClientsReady is an array to store ready client->index values into. *****************/ - +#if !defined(__USE_W32_SOCKETS) int WaitForSomething(int *pClientsReady) { @@ -177,8 +187,13 @@ #ifdef SMART_SCHEDULE if (someReady) { + DUMP_FD_SET(LastSelectMask); + DUMP_FD_SET(AllSockets); XFD_COPYSET(&AllSockets, &LastSelectMask); + DUMP_FD_SET(LastSelectMask); + DUMP_FD_SET(AllSockets); XFD_UNSET(&LastSelectMask, &ClientsWithInput); + DUMP_FD_SET(LastSelectMask); } else { @@ -186,13 +201,13 @@ wt = NULL; if (timers) { - now = GetTimeInMillis(); + now = GetTimeInMillis(); timeout = timers->expires - now; - if (timeout < 0) - timeout = 0; + if (timeout < 0) + timeout = 0; waittime.tv_sec = timeout / MILLI_PER_SECOND; waittime.tv_usec = (timeout % MILLI_PER_SECOND) * - (1000000 / MILLI_PER_SECOND); + (1000000 / MILLI_PER_SECOND); wt = &waittime; } XFD_COPYSET(&AllSockets, &LastSelectMask); @@ -200,7 +215,9 @@ } SmartScheduleIdle = TRUE; #endif + DUMP_FD_SET(LastSelectMask); BlockHandler((pointer)&wt, (pointer)&LastSelectMask); + DUMP_FD_SET(LastSelectMask); if (NewOutputPending) FlushAllOutput(); #ifdef XTESTEXT1 @@ -210,6 +227,12 @@ XTestComputeWaitTime (&waittime); } #endif /* XTESTEXT1 */ + if (!dispatchException) + { + DUMP_FD_SET(LastSelectMask); + if (AnyClientsWriteBlocked) + DUMP_FD_SET(clientsWritable); + } /* keep this check close to select() call to minimize race */ if (dispatchException) i = -1; @@ -223,7 +246,9 @@ i = Select (MaxClients, &LastSelectMask, NULL, NULL, wt); } selecterr = errno; + DUMP_FD_SET(LastSelectMask); WakeupHandler(i, (pointer)&LastSelectMask); + DUMP_FD_SET(LastSelectMask); #ifdef XTESTEXT1 if (playback_on) { i = XTestProcessInputAction (i, &waittime); @@ -242,7 +267,11 @@ { if (dispatchException) return 0; - if (i < 0) +#if defined(WIN32) || defined(__USE_W32_SOCKETS) + if (i == SOCKET_ERROR) +#else + if (i < 0) +#endif { if (selecterr == EBADF) /* Some client disconnected */ { @@ -267,8 +296,10 @@ /* * If no-one else is home, bail quickly */ + DUMP_FD_SET(LastSelectMask); XFD_COPYSET(&ClientsWithInput, &LastSelectMask); XFD_COPYSET(&ClientsWithInput, &clientsReadable); + DUMP_FD_SET(LastSelectMask); break; } #endif @@ -327,6 +358,7 @@ if (XFD_ANYSET(&tmp_set)) QueueWorkProc(EstablishNewConnections, NULL, (pointer)&LastSelectMask); + DUMP_FD_SET(LastSelectMask); #ifdef DPMSExtension if (XFD_ANYSET (&devicesReadable) && (DPMSPowerLevel != DPMSModeOn)) DPMSSet(DPMSModeOn); @@ -339,7 +371,7 @@ nready = 0; if (XFD_ANYSET (&clientsReadable)) { -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) for (i=0; iexpires - now; + if (timeout < 0) + timeout = 0; + waittime.tv_sec = timeout / MILLI_PER_SECOND; + waittime.tv_usec = (timeout % MILLI_PER_SECOND) * + (1000000 / MILLI_PER_SECOND); + wt = &waittime; + } + XFD_COPYSET(&AllSockets, &LastSelectMask); + BlockHandler((pointer)&wt, (pointer)&LastSelectMask); + + if (NewOutputPending) + FlushAllOutput(); + + /* keep this check close to select() call to minimize race */ + if (dispatchException) + i = -1; + else if (AnyClientsWriteBlocked) + { + XFD_COPYSET(&ClientsWriteBlocked, &clientsWritable); + i = Select (MaxClients, &LastSelectMask, &clientsWritable, NULL, wt); + } + else + { + i = Select (MaxClients, &LastSelectMask, NULL, NULL, wt); + } + selecterr = errno; + DUMP_FD_SET(LastSelectMask); + WakeupHandler(i, (pointer)&LastSelectMask); + DUMP_FD_SET(LastSelectMask); + if (i <= 0) /* An error or timeout occurred */ + { + if (dispatchException) + return 0; + + if (i == SOCKET_ERROR) + { + if (selecterr == EBADF) /* Some client disconnected */ + { + CheckConnections (); + if (! XFD_ANYSET (&AllClients)) + return 0; + } + else if (selecterr == EINVAL) + { + FatalError("WaitForSomething(): select: errno=%d\n", + selecterr); + } + else if (selecterr != EINTR) + { + ErrorF("WaitForSomething(): select: errno=%d\n", + selecterr); + } + } + if (*checkForInput[0] != *checkForInput[1]) + return 0; + + if (timers) + { + int expired = 0; + now = GetTimeInMillis(); + if ((int) (timers->expires - now) <= 0) + expired = 1; + + while (timers && (int) (timers->expires - now) <= 0) + DoTimer(timers, now, &timers); + + if (expired) + return 0; + } + } + else + { + fd_set tmp_set; + + if (*checkForInput[0] == *checkForInput[1]) { + if (timers) + { + int expired = 0; + now = GetTimeInMillis(); + if ((int) (timers->expires - now) <= 0) + expired = 1; + + while (timers && (int) (timers->expires - now) <= 0) + DoTimer(timers, now, &timers); + + if (expired) + return 0; + } + } + if (AnyClientsWriteBlocked && XFD_ANYSET (&clientsWritable)) + { + NewOutputPending = TRUE; + XFD_ORSET(&OutputPending, &clientsWritable, &OutputPending); + XFD_UNSET(&ClientsWriteBlocked, &clientsWritable); + if (! XFD_ANYSET(&ClientsWriteBlocked)) + AnyClientsWriteBlocked = FALSE; + } + + XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients); + XFD_ANDSET(&tmp_set, &LastSelectMask, &WellKnownConnections); + if (XFD_ANYSET(&tmp_set)) + QueueWorkProc(EstablishNewConnections, NULL, + (pointer)&LastSelectMask); + DUMP_FD_SET(LastSelectMask); + if (XFD_ANYSET (&clientsReadable)) + break; + } + } + + nready = 0; + if (XFD_ANYSET (&clientsReadable)) + { + int highest_priority = 0; + fd_set savedClientsReadable; + XFD_COPYSET(&clientsReadable, &savedClientsReadable); + for (i = 0; i < XFD_SETCOUNT(&savedClientsReadable); i++) + { + int client_priority, client_index; + + curclient = XFD_FD(&savedClientsReadable, i); + client_index = ConnectionTranslation[curclient]; +#ifdef XSYNC + /* We implement "strict" priorities. + * Only the highest priority client is returned to + * dix. If multiple clients at the same priority are + * ready, they are all returned. This means that an + * aggressive client could take over the server. + * This was not considered a big problem because + * aggressive clients can hose the server in so many + * other ways :) + */ + client_priority = clients[client_index]->priority; + if (nready == 0 || client_priority > highest_priority) + { + /* Either we found the first client, or we found + * a client whose priority is greater than all others + * that have been found so far. Either way, we want + * to initialize the list of clients to contain just + * this client. + */ + pClientsReady[0] = client_index; + highest_priority = client_priority; + nready = 1; + } + /* the following if makes sure that multiple same-priority + * clients get batched together + */ + else if (client_priority == highest_priority) +#endif + { + pClientsReady[nready++] = client_index; + } + FD_CLR(curclient, &clientsReadable); + } + } + return nready; +} +#endif #if 0 /* @@ -671,3 +895,330 @@ DPMSOffTimerExpire, NULL); } #endif + +#if defined(__USE_W32_SOCKETS) +extern SOCKET _XSERVTransFdToSocket(int fd); +extern int _XSERVTransSocketToFd(SOCKET s); +#define FD_TO_SOCKET(x) _XSERVTransFdToSocket(x) +#define SOCKET_TO_FD(x) _XSERVTransSocketToFd(x) + +int _win32Select (int n, fd_set* r, fd_set* w, fd_set* x, + const struct timeval* t) +{ + fd_set winR, winW, winX; + int i; + int ret; + + if (r) + { + for (i = 0; i < XFD_SETCOUNT(r); i++) + { + XFD_FD(&winR, i) = FD_TO_SOCKET(XFD_FD(r, i)); + } + XFD_SETCOUNT(&winR) = XFD_SETCOUNT(r); + } + + if (w) + { + for (i = 0; i < XFD_SETCOUNT(w); i++) + { + XFD_FD(&winW, i) = FD_TO_SOCKET(XFD_FD(w, i)); + } + XFD_SETCOUNT(&winW) = XFD_SETCOUNT(w); + } + + if (x) + { + for (i = 0; i < XFD_SETCOUNT(x); i++) + { + XFD_FD(&winX, i) = FD_TO_SOCKET(XFD_FD(x, i)); + } + XFD_SETCOUNT(&winX) = XFD_SETCOUNT(x); + } + + ret = select (n, r?&winR:NULL, w?&winW:NULL, x?&winX:NULL, t); + + if (r) + { + int j = 0; + for (i = 0; i < XFD_SETCOUNT(&winR); i++) + { + SOCKET s = SOCKET_TO_FD(XFD_FD(&winR, i)); + if (s == INVALID_SOCKET) continue; + XFD_FD(r, j) = s; + j++; + } + XFD_SETCOUNT(r) = j;//XFD_SETCOUNT(&winR); + } + + if (w) + { + int j = 0; + for (i = 0; i < XFD_SETCOUNT(&winW); i++) + { + SOCKET s = SOCKET_TO_FD(XFD_FD(&winW, i)); + if (s == INVALID_SOCKET) continue; + XFD_FD(w, j) = s; + j++; + } + XFD_SETCOUNT(w) = j;//XFD_SETCOUNT(&winW); + } + + if (x) + { + int j = 0; + for (i = 0; i < XFD_SETCOUNT(&winX); i++) + { + SOCKET s = SOCKET_TO_FD(XFD_FD(&winX, i)); + if (s == INVALID_SOCKET) continue; + XFD_FD(x, j) = s; + j++; + } + XFD_SETCOUNT(x) = j;//XFD_SETCOUNT(&winX); + } + return ret; +} +void PrintWSAError(int err) +{ + switch (err) + { + case WSANOTINITIALISED: + ErrorF("A successful WSAStartup call must occur before using this function.\n"); + break; + case WSAENETDOWN: + ErrorF("The network subsystem has failed.\n"); + break; + case WSAEINVAL: + ErrorF("Indicates that one of the specified parameters was invalid.\n"); + break; + case WSAEINPROGRESS: + ErrorF("A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.\n"); + break; + case WSAENOTSOCK: + ErrorF("The descriptor is not a socket.\n"); + break; + case WSAEFAULT: + ErrorF("The lpNetworkEvents parameter is not a valid part of the user address space."); + case 0: + break; + } +} + +#define XDUMP_FD_SET(fd) do {int _ii; for (_ii = 0; _ii < XFD_SETCOUNT(fd); _ii++) {\ + ErrorF ("%s(%d): " #fd "[%d] = %d\n", \ + __FUNCTION__, __LINE__, _ii, XFD_FD(fd, _ii)); \ + }}while(0) +int win32Select (int n, fd_set* r, fd_set* w, fd_set* x, + const struct timeval* t) +{ + static HANDLE ahEvents[FD_SETSIZE*2]; + SOCKET ahSockets[FD_SETSIZE*2]; + DWORD dwWait, dwRet; + int i, j = 0; + static BOOL fInit = FALSE; + struct timeval notime; + + notime.tv_sec = 0; + notime.tv_usec = 0; + + //ErrorF("win32Select(%d, %d, %d, %d, %d)\n", n, r, w, x, t); + if(x != NULL) + { + ErrorF("win32Select x != NULL unimplemented.\n"); + } + + if (fInit) + { + for (i = 0; i < FD_SETSIZE*2; i++) + { + //ResetEvent(ahEvents[i]); + } + } + else + { + for (i = 0; i < FD_SETSIZE*2; i++) + { + ahEvents[i] = WSACreateEvent(); + } + fInit = TRUE; + } + + //return _win32Select(n, r, w, x, t); + + if (t && (t->tv_sec == 0) && (t->tv_usec == 0)){ + return _win32Select(n, r, w, x, t); + } + + if (r) + { + //ErrorF("win32Select rfd\n"); + //XDUMP_FD_SET(r); + for (i = 0; i < r->fd_count; i++) + { + SOCKET s = FD_TO_SOCKET(r->fd_array[i]); +#if 1 + //ErrorF("[%d/%d]%d -> %d & %d\n", i, j, + //r->fd_array[i], ahEvents[j], s); + ResetEvent(ahEvents[j]); + if (WSAEventSelect(s, ahEvents[j], + FD_READ|FD_ACCEPT|FD_CLOSE)) + PrintWSAError(WSAGetLastError()); + ahSockets[j] = r->fd_array[i]; +#else + ahSockets[j] = s; +#endif + j++; + } + } + + if (w) + { + //ErrorF("win32Select wfd\n"); + //XDUMP_FD_SET(w); + for (i = 0; i < w->fd_count; i++) + { + if (!r || !FD_ISSET(w->fd_array[i], r)) + { + SOCKET s = FD_TO_SOCKET(w->fd_array[i]); +#if 1 + ResetEvent(ahEvents[j]); + if (WSAEventSelect(s, ahEvents[j], + FD_WRITE|FD_CONNECT)) + PrintWSAError(WSAGetLastError()); + ahSockets[j] = w->fd_array[i]; +#else + ahSockets[j] = s; +#endif + j++; + } + else// if (FD_ISSET(w->fd_array[i], r)) + { +#if 1 + u_int ii; + SOCKET s; + + for (ii = 0; ii < r->fd_count ; ii++) { + if (w->fd_array[i] == r->fd_array[ii]) break; + } + + if (ii == r->fd_count) + { + ErrorF(__FUNCTION__":read fd not found\n"); + } + + if (w->fd_array[i] != ahSockets[ii]) + { + ErrorF(__FUNCTION__":rfd differ\n"); + } + + s = FD_TO_SOCKET(w->fd_array[i]); + + if (WSAEventSelect(s, ahEvents[ii], + FD_READ|FD_WRITE|FD_ACCEPT|FD_CLOSE|FD_CONNECT)) + PrintWSAError(WSAGetLastError()); + //ahSockets[ii] = w->fd_array[i]; + //j++; +#endif + } + } + } + + if (t) + dwWait = t->tv_sec * 1000 + t->tv_usec / 1000; + else + dwWait = INFINITE; + + //ErrorF("win32Select(n=%d, wait=%ld)\n", j, dwWait); + +#if 1 + dwRet = MsgWaitForMultipleObjects (j, ahEvents, FALSE, dwWait, QS_ALLEVENTS); +#else + + dwRet = MsgWaitForMultipleObjects (j, ahSockets, FALSE, dwWait, QS_ALLEVENTS); +#endif + + //ErrorF("win32Select return %ld\n", dwRet); + + if (dwRet == WAIT_OBJECT_0 + j) + { + //ErrorF("win32Select windows message\n"); + //Message + if (r) FD_ZERO(r); + if (w) FD_ZERO(w); + if (x) FD_ZERO(x); + WSASetLastError(0); + return 0; + } + else if ((dwRet >= WAIT_OBJECT_0) && (dwRet < WAIT_OBJECT_0 + j)) + { +#if 1 + WSANETWORKEVENTS NetworkEvents; + int nRet; +#if 1 + i = dwRet - WAIT_OBJECT_0; + WSAEnumNetworkEvents(FD_TO_SOCKET(ahSockets[i]), ahEvents[i], &NetworkEvents); + + if (r) FD_ZERO(r); + if (w) FD_ZERO(w); + if (x) FD_ZERO(x); + + if (r && (NetworkEvents.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE))) + { + FD_SET(ahSockets[i], r); + } + if (w && (NetworkEvents.lNetworkEvents & (FD_WRITE|FD_CONNECT))) + { + FD_SET(ahSockets[i], w); + } + nRet = 1; +#else + for (i = 0, nRet = j; i < j; i++) + { + WSAEnumNetworkEvents(FD_TO_SOCKET(ahSockets[i]), ahEvents[i], &NetworkEvents); + if (r && + !(NetworkEvents.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE)) && + FD_ISSET(ahSockets[i], r)) + { + FD_CLR(ahSockets[i], r); + nRet--; + } + + if (w && + !(NetworkEvents.lNetworkEvents & (FD_WRITE|FD_CONNECT)) && + FD_ISSET(ahSockets[i], w)) + { + FD_CLR(ahSockets[i], w); + nRet--; + } + } +#endif + WSASetLastError(0); + return nRet; +#else + //ErrorF("win32Select call _win32Select\n"); + dwRet = _win32Select(n, r, w, x, ¬ime); + //ErrorF("win32Select call _win32Select ret\n"); + return dwRet; +#endif + } + else if (dwRet == WAIT_TIMEOUT) + { + ErrorF("win32Select timeout\n"); + if (r) FD_ZERO(r); + if (w) FD_ZERO(w); + if (x) FD_ZERO(x); + WSASetLastError(0); + return 0; + } + else + { + //error + ErrorF("win32Select error\n"); + if (r) FD_ZERO(r); + if (w) FD_ZERO(w); + if (x) FD_ZERO(x); + return -1; + } +} + +#endif Index: programs/Xserver/os/access.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/access.c,v retrieving revision 1.6 diff -u -r1.6 access.c --- programs/Xserver/os/access.c 17 Oct 2004 10:46:14 -0000 1.6 +++ programs/Xserver/os/access.c 9 Nov 2004 16:20:22 -0000 @@ -57,7 +57,11 @@ ******************************************************************/ /* $XFree86: xc/programs/Xserver/os/access.c,v 3.53 2004/01/02 18:23:19 tsi Exp $ */ -#ifdef WIN32 +#if defined(WINSOCK2XWIN) +#define __USE_W32_SOCKETS +#endif + +#if defined(WIN32) || defined(__USE_W32_SOCKETS) #include #endif @@ -71,7 +75,7 @@ #include "site.h" #include #include -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) #ifndef Lynx #include #else @@ -172,6 +176,8 @@ /* #endif */ #endif +#elif defined(__USE_W32_SOCKETS) +#include #endif /* WIN32 */ #ifndef PATH_MAX Index: programs/Xserver/os/connection.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/connection.c,v retrieving revision 1.3 diff -u -r1.3 connection.c --- programs/Xserver/os/connection.c 17 Oct 2004 10:46:14 -0000 1.3 +++ programs/Xserver/os/connection.c 9 Nov 2004 16:20:23 -0000 @@ -63,7 +63,11 @@ * *****************************************************************/ -#ifdef WIN32 +#if defined(WINSOCK2XWIN) +#define __USE_W32_SOCKETS +#endif + +#if defined(WIN32) || defined(__USE_W32_SOCKETS) #include #endif #include "X.h" @@ -74,7 +78,7 @@ #include #include -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) #if defined(Lynx) #include #else @@ -106,6 +110,9 @@ #define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t) extern __const__ int _nfiles; #endif +#if defined(__USE_W32_SOCKETS) +extern int win32Select(int n,fd_set* r,fd_set* w,fd_set* x,const struct timeval* t); +#endif #if defined(TCPCONN) || defined(STREAMSCONN) # include @@ -195,7 +202,7 @@ int GrabInProgress = 0; int *ConnectionTranslation = NULL; -#if defined(WIN32) +#if defined(WIN32) || defined(__USE_W32_SOCKETS) /* SPAM ALERT !!! * On NT fds are not between 0 and MAXSOCKS, they are unrelated, and there is * not even a known maximum value, so use something quite arbitrary for now. @@ -283,7 +290,7 @@ ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients); #endif -#if !defined(WIN32) +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) ConnectionTranslation = (int *)xnfalloc(sizeof(int)*(lastfdesc + 1)); #else ConnectionTranslation = (int *)xnfalloc(sizeof(int)*(MAXFD)); @@ -305,11 +312,13 @@ OsSigHandlerPtr handler; FD_ZERO(&AllSockets); + DUMP_FD_SET(AllSockets); FD_ZERO(&AllClients); FD_ZERO(&LastSelectMask); FD_ZERO(&ClientsWithInput); + DUMP_FD_SET(LastSelectMask); -#if !defined(WIN32) +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) for (i=0; i 1) { kill (ParentProcess, SIGUSR1); @@ -724,7 +734,7 @@ #ifdef LBX trans_conn && #endif -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) fd >= lastfdesc #else XFD_SETCOUNT(&AllClients) >= MaxClients @@ -764,7 +774,9 @@ else { FD_SET(fd, &AllClients); + DUMP_FD_SET(AllSockets); FD_SET(fd, &AllSockets); + DUMP_FD_SET(AllSockets); } } @@ -846,7 +858,7 @@ CloseDownClient(client); } } -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) { while (readyconnections.fds_bits[i]) @@ -857,7 +869,7 @@ XtransConnInfo trans_conn, new_trans_conn; int status; -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) curconn = ffs (readyconnections.fds_bits[i]) - 1; readyconnections.fds_bits[i] &= ~((fd_mask)1 << curconn); curconn += (i * (sizeof(fd_mask)*8)); @@ -894,7 +906,7 @@ _XSERVTransClose(new_trans_conn); } } -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) } #endif return TRUE; @@ -979,7 +991,9 @@ xfree(oc); #endif ConnectionTranslation[connection] = 0; + DUMP_FD_SET(AllSockets); FD_CLR(connection, &AllSockets); + DUMP_FD_SET(AllSockets); FD_CLR(connection, &AllClients); FD_CLR(connection, &ClientsWithInput); FD_CLR(connection, &GrabImperviousClients); @@ -1007,7 +1021,7 @@ void CheckConnections(void) { -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) fd_mask mask; #endif fd_set tmask; @@ -1015,14 +1029,14 @@ int i; struct timeval notime; int r; -#ifdef WIN32 +#if defined(WIN32) || defined(__USE_W32_SOCKETS) fd_set savedAllClients; #endif notime.tv_sec = 0; notime.tv_usec = 0; -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) for (i=0; iindex; } } @@ -1145,7 +1165,9 @@ { if (GrabInProgress) { + DUMP_FD_SET(AllSockets); XFD_ORSET(&AllSockets, &AllSockets, &SavedAllSockets); + DUMP_FD_SET(AllSockets); XFD_ORSET(&AllClients, &AllClients, &SavedAllClients); XFD_ORSET(&ClientsWithInput, &ClientsWithInput, &SavedClientsWithInput); GrabInProgress = 0; @@ -1181,9 +1203,13 @@ else FD_CLR(connection, &IgnoredClientsWithInput); FD_CLR(connection, &ClientsWithInput); + DUMP_FD_SET(AllSockets); FD_CLR(connection, &AllSockets); + DUMP_FD_SET(AllSockets); FD_CLR(connection, &AllClients); + DUMP_FD_SET(LastSelectMask); FD_CLR(connection, &LastSelectMask); + DUMP_FD_SET(LastSelectMask); } else { @@ -1219,8 +1245,12 @@ FD_ISSET(connection, &GrabImperviousClients)) { FD_SET(connection, &AllClients); + DUMP_FD_SET(AllSockets); FD_SET(connection, &AllSockets); + DUMP_FD_SET(AllSockets); + DUMP_FD_SET(LastSelectMask); FD_SET(connection, &LastSelectMask); + DUMP_FD_SET(LastSelectMask); if (FD_ISSET (connection, &IgnoredClientsWithInput)) FD_SET(connection, &ClientsWithInput); } @@ -1268,7 +1298,9 @@ FD_SET(connection, &SavedClientsWithInput); FD_CLR(connection, &ClientsWithInput); } + DUMP_FD_SET(AllSockets); FD_CLR(connection, &AllSockets); + DUMP_FD_SET(AllSockets); FD_CLR(connection, &AllClients); isItTimeToYield = TRUE; } Index: programs/Xserver/os/io.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/io.c,v retrieving revision 1.2 diff -u -r1.2 io.c --- programs/Xserver/os/io.c 23 Apr 2004 19:54:28 -0000 1.2 +++ programs/Xserver/os/io.c 9 Nov 2004 16:20:24 -0000 @@ -55,17 +55,21 @@ *****************************************************************/ /* $XFree86: xc/programs/Xserver/os/io.c,v 3.34 2002/05/31 18:46:05 dawes Exp $ */ +#if defined(WINSOCK2XWIN) +#define __USE_W32_SOCKETS +#endif + #if 0 #define DEBUG_COMMUNICATION #endif -#ifdef WIN32 +#if defined(WIN32) || defined(__USE_W32_SOCKETS) #include #endif #include #include #include "Xmd.h" #include -#if !defined(__UNIXOS2__) && !defined(WIN32) +#if !defined(__UNIXOS2__) && !defined(WIN32) && !defined(__USE_W32_SOCKETS) #ifndef Lynx #include #else @@ -106,6 +110,12 @@ #else /* __UNIXOS2__ Writing to full pipes may return ENOSPC */ #define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK || err == ENOSPC) #endif +#if defined(WIN32) || defined(__USE_W32_SOCKETS) +static int _wsaerrno; +int* wsaerr(){ _wsaerrno = WSAGetLastError(); return &_wsaerrno; } +#define errno (*wsaerr()) +#define ETEST(err) (err == WSATRY_AGAIN || err == WSAEWOULDBLOCK) +#endif Bool CriticalOutputPending; int timesThisConnection = 0; @@ -805,11 +815,13 @@ FlushAllOutput(void) { register int index, base; +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) register fd_mask mask; /* raphael */ +#endif OsCommPtr oc; register ClientPtr client; Bool newoutput = NewOutputPending; -#if defined(WIN32) +#if defined(WIN32) || defined(__USE_W32_SOCKETS) fd_set newOutputPending; #endif @@ -827,7 +839,7 @@ CriticalOutputPending = FALSE; NewOutputPending = FALSE; -#ifndef WIN32 +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) for (base = 0; base < howmany(XFD_SETSIZE, NFDBITS); base++) { mask = OutputPending.fds_bits[ base ]; @@ -1118,6 +1130,7 @@ InsertIOV (padBuffer, padsize) errno = 0; + WSASetLastError(0); if (trans_conn && (len = _XSERVTransWritev(trans_conn, iov, i)) >= 0) { written += len; Index: programs/Xserver/os/osdep.h =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/osdep.h,v retrieving revision 1.2 diff -u -r1.2 osdep.h --- programs/Xserver/os/osdep.h 23 Apr 2004 19:54:28 -0000 1.2 +++ programs/Xserver/os/osdep.h 9 Nov 2004 16:20:24 -0000 @@ -119,6 +119,17 @@ #define HAS_GETDTABLESIZE #endif +#if defined(__USE_W32_SOCKETS) +#if 1 +#define DUMP_FD_SET(fd) do {}while(0) +#else +#define DUMP_FD_SET(fd) do {int _ii; for (_ii = 0; _ii < XFD_SETCOUNT(fd); _ii++) {\ + ErrorF ("%s(%d): " #fd "[%d] = %d\n", \ + __FUNCTION__, __LINE__, _ii, XFD_FD(fd, _ii)); \ + }}while(0) +#endif +#endif + #include typedef Bool (*ValidatorFunc)(ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type); @@ -259,9 +270,11 @@ extern WorkQueuePtr workQueue; +#if !defined(__USE_W32_SOCKETS) /* added by raphael */ #define ffs mffs extern int mffs(fd_mask); +#endif /* in auth.c */ extern void GenerateRandomData (int len, char *buf); Index: programs/Xserver/os/utils.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/utils.c,v retrieving revision 1.9 diff -u -r1.9 utils.c --- programs/Xserver/os/utils.c 29 Sep 2004 04:17:44 -0000 1.9 +++ programs/Xserver/os/utils.c 9 Nov 2004 16:20:25 -0000 @@ -57,7 +57,7 @@ #include #endif -#if defined(WIN32) && !defined(__CYGWIN__) +#if (defined(WIN32) && !defined(__CYGWIN__)) || defined(__USE_W32_SOCKETS) #include #endif #include "Xos.h" @@ -98,7 +98,7 @@ #include /* for malloc() */ #if defined(TCPCONN) || defined(STREAMSCONN) -# ifndef WIN32 +# if !defined(WIN32) && !defined(__USE_W32_SOCKETS) # include # endif #endif @@ -1672,7 +1672,7 @@ #endif } -#if !defined(WIN32) && !defined(__UNIXOS2__) +#if !defined(WIN32) && !defined(__UNIXOS2__) && !defined(__USE_W32_SOCKETS) /* * "safer" versions of system(3), popen(3) and pclose(3) which give up * all privs before running a command. Index: programs/Xserver/os/xdmcp.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/xdmcp.c,v retrieving revision 1.3 diff -u -r1.3 xdmcp.c --- programs/Xserver/os/xdmcp.c 20 Jul 2004 15:15:13 -0000 1.3 +++ programs/Xserver/os/xdmcp.c 9 Nov 2004 16:20:26 -0000 @@ -16,6 +16,10 @@ */ /* $XFree86: xc/programs/Xserver/os/xdmcp.c,v 3.31 2003/12/30 21:24:32 herrb Exp $ */ +#if defined(WINSOCK2XWIN) +#define __USE_W32_SOCKETS +#endif + #ifdef WIN32 /* avoid conflicting definitions */ #define BOOL wBOOL @@ -30,9 +34,13 @@ #undef RT_CURSOR #endif +#if defined(__USE_W32_SOCKETS) +#include +#endif + #include "Xos.h" -#if !defined(WIN32) +#if !defined(WIN32) && !defined(__USE_W32_SOCKETS) #ifndef Lynx #include #include