Use non-blocking sockets in x0vnserver
diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx
index caf7814..8f73ac2 100644
--- a/unix/x0vncserver/x0vncserver.cxx
+++ b/unix/x0vncserver/x0vncserver.cxx
@@ -510,7 +510,7 @@
while (!caughtSignal) {
int wait_ms;
struct timeval tv;
- fd_set rfds;
+ fd_set rfds, wfds;
std::list<Socket*> sockets;
std::list<Socket*>::iterator i;
@@ -518,6 +518,8 @@
TXWindow::handleXEvents(dpy);
FD_ZERO(&rfds);
+ FD_ZERO(&wfds);
+
FD_SET(ConnectionNumber(dpy), &rfds);
for (std::list<TcpListener*>::iterator i = listeners.begin();
i != listeners.end();
@@ -532,6 +534,8 @@
delete (*i);
} else {
FD_SET((*i)->getFd(), &rfds);
+ if ((*i)->outStream().bufferUsage() > 0)
+ FD_SET((*i)->getFd(), &wfds);
clients_connected++;
}
}
@@ -555,7 +559,7 @@
// Do the wait...
sched.sleepStarted();
- int n = select(FD_SETSIZE, &rfds, 0, 0,
+ int n = select(FD_SETSIZE, &rfds, &wfds, 0,
wait_ms ? &tv : NULL);
sched.sleepFinished();
@@ -575,6 +579,7 @@
if (FD_ISSET((*i)->getFd(), &rfds)) {
Socket* sock = (*i)->accept();
if (sock) {
+ sock->outStream().setBlocking(false);
server.addSocket(sock);
} else {
vlog.status("Client connection rejected");
@@ -595,6 +600,8 @@
for (i = sockets.begin(); i != sockets.end(); i++) {
if (FD_ISSET((*i)->getFd(), &rfds))
server.processSocketReadEvent(*i);
+ if (FD_ISSET((*i)->getFd(), &wfds))
+ server.processSocketWriteEvent(*i);
}
if (desktop.isRunning() && sched.goodTimeToPoll()) {