diff options
author | Christian Beier <dontmind@freeshell.org> | 2010-09-07 17:43:58 +0200 |
---|---|---|
committer | Christian Beier <dontmind@freeshell.org> | 2010-09-13 14:19:15 +0200 |
commit | c0373e9cd48b0fc22ac295fdab51a29e3df7a0cd (patch) | |
tree | 253b193dfb1805cd6de337f26cf6f82e74a42cad /libvncclient/sockets.c | |
parent | 0df84e5c27eefad8b731b12d58f8fbede71823e0 (diff) | |
download | libtdevnc-c0373e9cd48b0fc22ac295fdab51a29e3df7a0cd.tar.gz libtdevnc-c0373e9cd48b0fc22ac295fdab51a29e3df7a0cd.zip |
Non-blocking sockets for Windows.
Expands the SetNonBlocking() function in libvncclient/sockets.c to also
work under Windows and also changes it to honour maybe already present
socket flags.
A similar function was introduced for libvncserver as well and
all the #ifdef'ed fnctl calls replaced with calls to that one.
Signed-off-by: Christian Beier <dontmind@freeshell.org>
Diffstat (limited to 'libvncclient/sockets.c')
-rw-r--r-- | libvncclient/sockets.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c index 0171a5c..28b0256 100644 --- a/libvncclient/sockets.c +++ b/libvncclient/sockets.c @@ -551,14 +551,17 @@ AcceptTcpConnection(int listenSock) rfbBool SetNonBlocking(int sock) { -#ifndef __MINGW32__ - if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { - rfbClientErr("AcceptTcpConnection: fcntl\n"); - return FALSE; - } +#ifdef WIN32 + unsigned long block=1; + if(ioctlsocket(sock, FIONBIO, &block) == SOCKET_ERROR) { + errno=WSAGetLastError(); #else - rfbClientErr("O_NONBLOCK on MinGW32 NOT IMPLEMENTED\n"); + int flags = fcntl(sock, F_GETFL); + if(flags < 0 || fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) { #endif + rfbClientErr("Setting socket to non-blocking failed: %s\n",strerror(errno)); + return FALSE; + } return TRUE; } |