aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/os/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/os/connection.c')
-rw-r--r--xorg-server/os/connection.c79
1 files changed, 59 insertions, 20 deletions
diff --git a/xorg-server/os/connection.c b/xorg-server/os/connection.c
index 1099752e4..53a6ca005 100644
--- a/xorg-server/os/connection.c
+++ b/xorg-server/os/connection.c
@@ -66,6 +66,9 @@ SOFTWARE.
#ifdef WIN32
#include <X11/Xwinsock.h>
+#ifdef _DEBUG
+#define DEBUG
+#endif
#endif
#include <X11/X.h>
#include <X11/Xproto.h>
@@ -108,6 +111,10 @@ SOFTWARE.
#include "dixstruct.h"
#include "xace.h"
+#ifdef _MSC_VER
+typedef int pid_t;
+#endif
+
#define Pid_t pid_t
#ifdef HAVE_GETPEERUCRED
@@ -139,11 +146,13 @@ int MaxClients = 0;
Bool NewOutputPending; /* not yet attempted to write some new output */
Bool AnyClientsWriteBlocked; /* true if some client blocked on write */
+#if !defined(_MSC_VER)
static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
+static Pid_t ParentProcess;
+#endif
Bool RunFromSigStopParent; /* send SIGSTOP to our own process; Upstart (or
equivalent) will send SIGCONT back. */
Bool PartialNetwork; /* continue even if unable to bind all addrs */
-static Pid_t ParentProcess;
static Bool debug_conns = FALSE;
@@ -268,6 +277,23 @@ lookup_trans_conn(int fd)
return NULL;
}
+int
+TransIsListening(char *protocol)
+{
+ /* look for this transport in the list of listeners */
+ int i;
+ for (i = 0; i < ListenTransCount; i++)
+ {
+ if (!strcmp(protocol, ListenTransConns[i]->transptr->TransName))
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+
/* Set MaxClients and lastfdesc, and allocate ConnectionTranslation */
void
@@ -391,21 +417,24 @@ CreateWellKnownSockets(void)
if ((_XSERVTransMakeAllCOTSServerListeners(port, &partial,
&ListenTransCount,
&ListenTransConns) >= 0) &&
- (ListenTransCount >= 1)) {
+ (ListenTransCount >= 1)) {
if (!PartialNetwork && partial) {
FatalError("Failed to establish all listening sockets");
}
else {
ListenTransFds = malloc(ListenTransCount * sizeof(int));
- for (i = 0; i < ListenTransCount; i++) {
- int fd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
+ for (i = ListenTransCount; i > 0; i--) {
+ int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i-1]);
- ListenTransFds[i] = fd;
+ ListenTransFds[i-1] = fd;
FD_SET(fd, &WellKnownConnections);
- if (!_XSERVTransIsLocal(ListenTransConns[i])) {
- DefineSelf(fd);
+ if (!_XSERVTransIsLocal (ListenTransConns[i-1])) {
+ int protocol = 0;
+ if (!strcmp("inet", ListenTransConns[i-1]->transptr->TransName)) protocol = 4;
+ else if (!strcmp("inet6", ListenTransConns[i-1]->transptr->TransName)) protocol = 6;
+ DefineSelf (fd, protocol);
}
}
}
@@ -949,15 +978,17 @@ CheckConnections(void)
{
#ifndef WIN32
fd_mask mask;
+ int curoff;
#endif
fd_set tmask;
- int curclient, curoff;
+ int curclient;
int i;
struct timeval notime;
int r;
#ifdef WIN32
- fd_set savedAllClients;
+ fd_set savedAllSockets;
+ unsigned j;
#endif
notime.tv_sec = 0;
@@ -981,17 +1012,21 @@ CheckConnections(void)
}
}
#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);
- do {
- r = Select(curclient + 1, &tmask, NULL, NULL, &notime);
- } while (r < 0 && (errno == EINTR || errno == EAGAIN));
- if (r < 0)
- if (GetConnectionTranslation(curclient) > 0)
- CloseDownClient(clients[GetConnectionTranslation(curclient)]);
+ /* First test AllSockets and then AllClients are valid sockets */
+ XFD_COPYSET(&AllSockets, &savedAllSockets);
+ for (j=0; j<2; j++) {
+ for (i = 0; i < XFD_SETCOUNT(&savedAllSockets); i++) {
+ curclient = XFD_FD(&savedAllSockets, i);
+ FD_ZERO(&tmask);
+ FD_SET(curclient, &tmask);
+ do {
+ r = Select (curclient + 1, &tmask, NULL, NULL, &notime);
+ } while (r == SOCKET_ERROR && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK));
+ if (r < 0)
+ if (GetConnectionTranslation(curclient) > 0)
+ CloseDownClient(clients[GetConnectionTranslation(curclient)]);
+ }
+ XFD_COPYSET(&AllClients, &savedAllSockets);
}
#endif
}
@@ -1009,6 +1044,10 @@ CloseDownConnection(ClientPtr client)
if (FlushCallback)
CallCallbacks(&FlushCallback, NULL);
+#ifdef DEBUG
+ ErrorF("CloseDownConnection: client index = %d, socket fd = %d\n",
+ client->index, oc->fd);
+#endif
if (oc->output && oc->output->count)
FlushClient(client, oc, (char *) NULL, 0);
#ifdef XDMCP