Commit d409b566 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

os: unifdef WIN32

parent 74270d6b
......@@ -82,9 +82,6 @@ SOFTWARE.
#include <dix-config.h>
#endif
#ifdef WIN32
#include <nx-X11/Xwinsock.h>
#endif
#include <nx-X11/Xos.h> /* for strings, fcntl, time */
#include <errno.h>
#include <stdio.h>
......@@ -105,22 +102,9 @@ static unsigned long startTimeInMillis;
#endif
#ifdef WIN32
/* Error codes from windows sockets differ from fileio error codes */
#undef EINTR
#define EINTR WSAEINTR
#undef EINVAL
#define EINVAL WSAEINVAL
#undef EBADF
#define EBADF WSAENOTSOCK
/* Windows select does not set errno. Use GetErrno as wrapper for
WSAGetLastError */
#define GetErrno WSAGetLastError
#else
/* This is just a fallback to errno to hide the differences between unix and
Windows in the code */
#define GetErrno() errno
#endif
/* modifications by raphael */
int
......@@ -484,30 +468,12 @@ WaitForSomething(int *pClientsReady)
if (XFD_ANYSET (&clientsReadable))
break;
#ifdef WIN32
/* Windows keyboard and mouse events are added to the input queue
in Block- and WakupHandlers. There is no device to check if
data is ready. So check here if new input is available */
#if defined(NX_TRANS_SOCKET)
if (*checkForInput[0] != *checkForInput[1])
{
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG)
fprintf(stderr, "WaitForSomething: Returning 0 because of (*checkForInput[0] != *checkForInput[1]).\n");
#endif
return 0;
}
#else
if (*checkForInput[0] != *checkForInput[1])
return 0;
#endif
#endif
}
}
nready = 0;
if (XFD_ANYSET (&clientsReadable))
{
#ifndef WIN32
for (i=0; i<howmany(XFD_SETSIZE, NFDBITS); i++)
{
while (clientsReadable.fds_bits[i])
......@@ -517,23 +483,9 @@ WaitForSomething(int *pClientsReady)
curclient = ffs (clientsReadable.fds_bits[i]) - 1;
client_index = /* raphael: modified */
ConnectionTranslation[curclient + (i * (sizeof(fd_mask) * 8))];
#else
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 = GetConnectionTranslation(curclient);
#endif
pClientsReady[nready++] = client_index;
#ifndef WIN32
clientsReadable.fds_bits[i] &= ~(((fd_mask)1L) << curclient);
}
#else
FD_CLR(curclient, &clientsReadable);
#endif
}
}
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG)
......
......@@ -58,9 +58,6 @@ SOFTWARE.
#include <dix-config.h>
#endif
#ifdef WIN32
#include <nx-X11/Xwinsock.h>
#endif
#include <stdio.h>
#include <stdlib.h>
......@@ -75,7 +72,6 @@ SOFTWARE.
#include "site.h"
#include <errno.h>
#include <sys/types.h>
#ifndef WIN32
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <ctype.h>
......@@ -141,7 +137,6 @@ SOFTWARE.
/* #endif */
#endif
#endif /* WIN32 */
#ifndef PATH_MAX
#include <sys/param.h>
......@@ -474,13 +469,7 @@ DefineSelf (int fd)
int family;
register HOST *host;
#ifndef WIN32
struct utsname name;
#else
struct {
char nodename[512];
} name;
#endif
register struct hostent *hp;
......@@ -504,11 +493,7 @@ DefineSelf (int fd)
* uname() lets me access to the whole string (it smashes release, you
* see), whereas gethostname() kindly truncates it for me.
*/
#ifndef WIN32
uname(&name);
#else
gethostname(name.nodename, sizeof(name.nodename));
#endif
hp = _XGethostbyname(name.nodename, hparams);
if (hp != NULL)
......@@ -1692,10 +1677,6 @@ ConvertAddr (
return FamilyLocal;
#if defined(TCPCONN)
case AF_INET:
#ifdef WIN32
if (16777343 == *(long*)&((struct sockaddr_in *) saddr)->sin_addr)
return FamilyLocal;
#endif
*len = sizeof (struct in_addr);
*addr = (void *) &(((struct sockaddr_in *) saddr)->sin_addr);
return FamilyInternet;
......
......@@ -71,9 +71,6 @@ from The Open Group.
#define _SECURITY_SERVER
# include <nx-X11/extensions/security.h>
#endif
#ifdef WIN32
#include <nx-X11/Xw32defs.h>
#endif
struct protocol {
unsigned short name_length;
......
......@@ -65,9 +65,6 @@ SOFTWARE.
#include <dix-config.h>
#endif
#ifdef WIN32
#include <nx-X11/Xwinsock.h>
#endif
#include <nx-X11/X.h>
#include <nx-X11/Xproto.h>
#define XSERV_t
......@@ -81,7 +78,6 @@ SOFTWARE.
#include <stdlib.h>
#include <unistd.h>
#ifndef WIN32
#include <sys/socket.h>
#if defined(TCPCONN)
......@@ -104,7 +100,6 @@ SOFTWARE.
#endif
#include <sys/uio.h>
#endif /* WIN32 */
#include "misc.h"
#include "osdep.h"
#include <nx-X11/Xpoll.h>
......@@ -155,98 +150,7 @@ int GrabInProgress = 0;
static void
QueueNewConnections(int curconn, int ready, void *data);
#if !defined(WIN32)
int *ConnectionTranslation = NULL;
#else
/*
* 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.
* Do storage is a hash table of size 256. Collisions are handled in a linked
* list.
*/
#undef MAXSOCKS
#define MAXSOCKS 500
#undef MAXSELECT
#define MAXSELECT 500
#define MAXFD 500
struct _ct_node {
struct _ct_node *next;
int key;
int value;
};
struct _ct_node *ct_head[256];
void InitConnectionTranslation(void)
{
bzero(ct_head, sizeof(ct_head));
}
int GetConnectionTranslation(int conn)
{
struct _ct_node *node = ct_head[conn & 0xff];
while (node != NULL)
{
if (node->key == conn)
return node->value;
node = node->next;
}
return 0;
}
void SetConnectionTranslation(int conn, int client)
{
struct _ct_node **node = ct_head + (conn & 0xff);
if (client == 0) /* remove entry */
{
while (*node != NULL)
{
if ((*node)->key == conn)
{
struct _ct_node *temp = *node;
*node = (*node)->next;
free(temp);
return;
}
node = &((*node)->next);
}
return;
} else
{
while (*node != NULL)
{
if ((*node)->key == conn)
{
(*node)->value = client;
return;
}
node = &((*node)->next);
}
*node = (struct _ct_node*)malloc(sizeof(struct _ct_node));
(*node)->next = NULL;
(*node)->key = conn;
(*node)->value = client;
return;
}
}
void ClearConnectionTranslation(void)
{
unsigned i;
for (i = 0; i < 256; i++)
{
struct _ct_node *node = ct_head[i];
while (node != NULL)
{
struct _ct_node *temp = node;
node = node->next;
free(temp);
}
}
}
#endif
XtransConnInfo *ListenTransConns = NULL;
int *ListenTransFds = NULL;
......@@ -318,11 +222,7 @@ InitConnectionLimits(void)
ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients);
#endif
#if !defined(WIN32)
ConnectionTranslation = (int *)xnfalloc(sizeof(int)*(lastfdesc + 1));
#else
InitConnectionTranslation();
#endif
}
/*
......@@ -341,7 +241,6 @@ InitConnectionLimits(void)
static void
InitParentProcess(void)
{
#if !defined(WIN32)
OsSigHandlerPtr handler;
handler = OsSignal (SIGUSR1, SIG_IGN);
if ( handler == SIG_IGN)
......@@ -357,13 +256,11 @@ InitParentProcess(void)
*/
ParentProcess = GetPPID (ParentProcess);
#endif /* __UNIXOS2__ */
#endif
}
void
NotifyParentProcess(void)
{
#if !defined(WIN32)
if (displayfd >= 0) {
#ifdef NXAGENT_SERVER
if (displayfd == STDERR_FILENO)
......@@ -385,7 +282,6 @@ NotifyParentProcess(void)
kill (ParentProcess, SIGUSR1);
}
}
#endif
}
static Bool
......@@ -416,11 +312,7 @@ CreateWellKnownSockets(void)
FD_ZERO(&LastSelectMask);
FD_ZERO(&ClientsWithInput);
#if !defined(WIN32)
for (i=0; i<MaxClients; i++) ConnectionTranslation[i] = 0;
#else
ClearConnectionTranslation();
#endif
/* display is initialized to "0" by main(). It is then set to the display
* number if specified on the command line. */
......@@ -473,10 +365,8 @@ CreateWellKnownSockets(void)
if (ListenTransCount == 0 && !NoListenAll)
FatalError ("Cannot establish any listening sockets - Make sure an X server isn't already running");
#if !defined(WIN32)
OsSignal (SIGPIPE, SIG_IGN);
OsSignal (SIGHUP, AutoResetServer);
#endif
OsSignal (SIGINT, GiveUp);
OsSignal (SIGTERM, GiveUp);
ResetHosts(display);
......@@ -802,11 +692,7 @@ AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time)
ClientPtr client;
if (
#ifndef WIN32
fd >= lastfdesc
#else
XFD_SETCOUNT(&AllClients) >= MaxClients
#endif
)
return NullClient;
oc = (OsCommPtr)malloc(sizeof(OsCommRec));
......@@ -825,11 +711,7 @@ AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time)
}
client->local = ComputeLocalClient(client);
{
#if !defined(WIN32)
ConnectionTranslation[fd] = client->index;
#else
SetConnectionTranslation(fd, client->index);
#endif
if (GrabInProgress)
{
FD_SET(fd, &SavedAllClients);
......@@ -893,11 +775,7 @@ EstablishNewConnections(ClientPtr clientUnused, void * closure)
if (newconn < lastfdesc) {
int clientid;
#if !defined(WIN32)
clientid = ConnectionTranslation[newconn];
#else
clientid = GetConnectionTranslation(newconn);
#endif
if (clientid && (client = clients[clientid]))
CloseDownClient(client);
}
......@@ -990,11 +868,7 @@ CloseDownFileDescriptor(OsCommPtr oc)
}
FreeOsBuffers(oc);
free(oc);
#ifndef WIN32
ConnectionTranslation[connection] = 0;
#else
SetConnectionTranslation(connection, 0);
#endif
FD_CLR(connection, &AllSockets);
FD_CLR(connection, &AllClients);
FD_CLR(connection, &ClientsWithInput);
......@@ -1023,22 +897,16 @@ CloseDownFileDescriptor(OsCommPtr oc)
void
CheckConnections(void)
{
#ifndef WIN32
fd_mask mask;
#endif
fd_set tmask;
int curclient, curoff;
int i;
struct timeval notime;
int r;
#ifdef WIN32
fd_set savedAllClients;
#endif
notime.tv_sec = 0;
notime.tv_usec = 0;
#ifndef WIN32
for (i=0; i<howmany(XFD_SETSIZE, NFDBITS); i++)
{
mask = AllClients.fds_bits[i];
......@@ -1054,18 +922,6 @@ CheckConnections(void)
mask &= ~((fd_mask)1 << curoff);
}
}
#else
XFD_COPYSET(&AllClients, &savedAllClients);
for (i = 0; i < XFD_SETCOUNT(&savedAllClients); i++)
{
curclient = XFD_FD(&savedAllClients, i);
FD_ZERO(&tmask);
FD_SET(curclient, &tmask);
r = Select (curclient + 1, &tmask, NULL, NULL, &notime);
if (r < 0)
CloseDownClient(clients[GetConnectionTranslation(curclient)]);
}
#endif
}
......
......@@ -60,9 +60,6 @@ SOFTWARE.
#if 0
#define DEBUG_COMMUNICATION
#endif
#ifdef WIN32
#include <nx-X11/Xwinsock.h>
#endif
#include <stdio.h>
#define XSERV_t
#define TRANS_SERVER
......@@ -70,9 +67,7 @@ SOFTWARE.
#include <nx-X11/Xtrans/Xtrans.h>
#include <nx-X11/Xmd.h>
#include <errno.h>
#if !defined(WIN32)
#include <sys/uio.h>
#endif
#include <nx-X11/X.h>
#include <nx-X11/Xproto.h>
#include "os.h"
......@@ -88,7 +83,6 @@ CallbackListPtr FlushCallback;
/* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
* systems are broken and return EWOULDBLOCK when they should return EAGAIN
*/
#ifndef WIN32
#if defined(EAGAIN) && defined(EWOULDBLOCK)
#define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK)
#else
......@@ -98,9 +92,6 @@ CallbackListPtr FlushCallback;
#define ETEST(err) (err == EWOULDBLOCK)
#endif
#endif
#else /* WIN32 The socket errorcodes differ from the normal errors*/
#define ETEST(err) (err == EAGAIN || err == WSAEWOULDBLOCK)
#endif
Bool CriticalOutputPending;
int timesThisConnection = 0;
......@@ -777,9 +768,6 @@ FlushAllOutput(void)
OsCommPtr oc;
register ClientPtr client;
Bool newoutput = NewOutputPending;
#if defined(WIN32)
fd_set newOutputPending;
#endif
if (!newoutput)
return;
......@@ -792,7 +780,6 @@ FlushAllOutput(void)
CriticalOutputPending = FALSE;
NewOutputPending = FALSE;
#ifndef WIN32
for (base = 0; base < howmany(XFD_SETSIZE, NFDBITS); base++)
{
mask = OutputPending.fds_bits[ base ];
......@@ -817,28 +804,6 @@ FlushAllOutput(void)
(void)FlushClient(client, oc, (char *)NULL, 0);
}
}
#else /* WIN32 */
FD_ZERO(&newOutputPending);
for (base = 0; base < XFD_SETCOUNT(&OutputPending); base++)
{
index = XFD_FD(&OutputPending, base);
if ((index = GetConnectionTranslation(index)) == 0)
continue;
client = clients[index];
if (client->clientGone)
continue;
oc = (OsCommPtr)client->osPrivate;
if (
FD_ISSET(oc->fd, &ClientsWithInput))
{
FD_SET(oc->fd, &newOutputPending); /* set the bit again */
NewOutputPending = TRUE;
}
else
(void)FlushClient(client, oc, (char *)NULL, 0);
}
XFD_COPYSET(&newOutputPending, &OutputPending);
#endif /* WIN32 */
}
void
......
......@@ -117,10 +117,6 @@ OR PERFORMANCE OF THIS SOFTWARE.
#include "site.h"
#include "opaque.h"
#ifdef WIN32
#include <process.h>
#define getpid(x) _getpid(x)
#endif
#ifdef NX_TRANS_SOCKET
......@@ -268,9 +264,7 @@ LogInit(const char *fname, const char *backup)
if (saveBuffer && bufferSize > 0) {
fwrite(saveBuffer, bufferPos, 1, logFile);
fflush(logFile);
#ifndef WIN32
fsync(fileno(logFile));
#endif
}
}
......@@ -398,10 +392,8 @@ LogVWrite(int verb, const char *f, va_list args)
fwrite(tmpBuffer, len, 1, logFile);
if (logFlush) {
fflush(logFile);
#ifndef WIN32
if (logSync)
fsync(fileno(logFile));
#endif
}
} else if (needBuffer) {
/*
......
......@@ -69,11 +69,6 @@ SOFTWARE.
#undef _POSIX_SOURCE
#endif
#else /* X_NOT_POSIX */
#ifdef WIN32
#define _POSIX_
#include <limits.h>
#undef _POSIX_
#endif
#endif /* X_NOT_POSIX */
#ifndef OPEN_MAX
......@@ -85,11 +80,7 @@ SOFTWARE.
#if defined(NOFILE) && !defined(NOFILES_MAX)
#define OPEN_MAX NOFILE
#else
#if !defined(WIN32)
#define OPEN_MAX NOFILES_MAX
#else
#define OPEN_MAX 256
#endif
#endif
#endif
#endif
......@@ -213,13 +204,7 @@ extern fd_set ClientsWriteBlocked;
extern fd_set OutputPending;
extern fd_set IgnoredClientsWithInput;
#ifndef WIN32
extern int *ConnectionTranslation;
#else
extern int GetConnectionTranslation(int conn);
extern void SetConnectionTranslation(int conn, int client);
extern void ClearConnectionTranslation();
#endif
extern Bool NewOutputPending;
extern Bool AnyWritesPending;
......@@ -234,9 +219,6 @@ extern OsCommPtr AvailableInput;
extern WorkQueuePtr workQueue;
/* added by raphael */
#ifdef WIN32
typedef long int fd_mask;
#endif
#define ffs mffs
extern int mffs(fd_mask);
......
......@@ -66,7 +66,7 @@ SOFTWARE.
#endif
#if !defined(SYSV) && !defined(WIN32)
#if !defined(SYSV)
#include <sys/resource.h>
#endif
......@@ -131,7 +131,7 @@ OsInit(void)
dup2 (fileno (err), 2);
fclose (err);
}
#if defined(SYSV) || defined(SVR4) || defined(WIN32) || defined(__CYGWIN__)
#if defined(SYSV) || defined(SVR4) || defined(__CYGWIN__)
{
static char buf[BUFSIZ];
setvbuf (stderr, buf, _IOLBF, BUFSIZ);
......@@ -145,7 +145,7 @@ OsInit(void)
if (getpgrp () == 0)
setpgid (0, 0);
#else
#if !defined(SYSV) && !defined(WIN32)
#if !defined(SYSV)
if (getpgrp (0) == 0)
setpgrp (0, getpid ());
#endif
......
......@@ -83,9 +83,6 @@ OR PERFORMANCE OF THIS SOFTWARE.
#include <signal.h>
#endif
#if defined(WIN32) && !defined(__CYGWIN__)
#include <nx-X11/Xwinsock.h>
#endif
#include <nx-X11/Xos.h>
#include <stdio.h>
#include "misc.h"
......@@ -115,10 +112,8 @@ OR PERFORMANCE OF THIS SOFTWARE.
#undef _POSIX_SOURCE
#endif
#endif
#ifndef WIN32
#include <sys/wait.h>
#endif
#if !defined(SYSV) && !defined(WIN32)
#if !defined(SYSV)
#include <sys/resource.h>
#endif
#include <time.h>
......@@ -132,9 +127,7 @@ OR PERFORMANCE OF THIS SOFTWARE.
#include <stdlib.h> /* for malloc() */
#if defined(TCPCONN)
# ifndef WIN32
# include <netdb.h>
# endif
#endif
#include "opaque.h"
......@@ -910,7 +903,7 @@ ProcessCommandLine(int argc, char *argv[])
#ifdef SERVER_LOCK
else if ( strcmp ( argv[i], "-nolock") == 0)
{
#if !defined(WIN32) && !defined(__CYGWIN__)
#if !defined(__CYGWIN__)
if (getuid() != 0)
ErrorF("Warning: the -nolock option can only be used by root\n");
else
......@@ -1230,7 +1223,7 @@ ExpandCommandLine(int *pargc, char ***pargv)
{
int i;
#if !defined(WIN32) && !defined(__CYGWIN__)
#if !defined(__CYGWIN__)
if (getuid() != geteuid())
return;
#endif
......@@ -1566,7 +1559,6 @@ OsReleaseSignals (void)
#endif
}
#if !defined(WIN32)
/*
* "safer" versions of system(3), popen(3) and pclose(3) which give up
* all privs before running a command.
......@@ -1948,7 +1940,6 @@ Fclose(void * iop)
#endif
}
#endif /* !WIN32 */
/*
......@@ -1981,11 +1972,7 @@ Fclose(void * iop)
/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */
#ifndef CHECK_EUID
#ifndef WIN32
#define CHECK_EUID 1
#else
#define CHECK_EUID 0
#endif
#endif
/*
......
......@@ -17,22 +17,13 @@
#include <dix-config.h>
#endif
#ifdef WIN32
#include <nx-X11/Xwinsock.h>
#define XSERV_t
#define TRANS_SERVER
#define TRANS_REOPEN
#include <nx-X11/Xtrans/Xtrans.h>
#endif
#include <nx-X11/Xos.h>
#if !defined(WIN32)
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#endif
#include <stdio.h>
#include <stdlib.h>
......@@ -1507,9 +1498,6 @@ get_addr_by_name(
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
_Xgethostbynameparams hparams;
#endif
#if defined(WIN32) && defined(TCPCONN)
_XSERVTransWSAStartup();
#endif
if (!(hep = _XGethostbyname(namestr, hparams)))
{
FatalError("Xserver: %s unknown host: %s\n", argtype, namestr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment