From cf72a0f7c35ee791d5b4a81ef799d006e1b16bda Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Thu, 3 Mar 2011 16:11:38 +0100 Subject: Call WSAGetLastError() everywhere errno is read after a Winsock call. Winsock does NOT update errno for us, we have fetch the last error manually using WSAGetLastError(). --- libvncclient/sockets.c | 9 ++++++++- libvncclient/tls.c | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'libvncclient') diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c index 334928e..4183192 100644 --- a/libvncclient/sockets.c +++ b/libvncclient/sockets.c @@ -262,6 +262,9 @@ WriteToRFBServer(rfbClient* client, char *buf, int n) j = write(client->sock, buf + i, (n - i)); if (j <= 0) { if (j < 0) { +#ifdef WIN32 + errno=WSAGetLastError(); +#endif if (errno == EWOULDBLOCK || #ifdef LIBVNCSERVER_ENOENT_WORKAROUND errno == ENOENT || @@ -735,8 +738,12 @@ int WaitForMessage(rfbClient* client,unsigned int usecs) FD_SET(client->sock,&fds); num=select(client->sock+1, &fds, NULL, NULL, &timeout); - if(num<0) + if(num<0) { +#ifdef WIN32 + errno=WSAGetLastError(); +#endif rfbClientLog("Waiting for message failed: %d (%s)\n",errno,strerror(errno)); + } return num; } diff --git a/libvncclient/tls.c b/libvncclient/tls.c index 206dbda..eb89413 100644 --- a/libvncclient/tls.c +++ b/libvncclient/tls.c @@ -62,6 +62,9 @@ PushTLS(gnutls_transport_ptr_t transport, const void *data, size_t len) ret = write(client->sock, data, len); if (ret < 0) { +#ifdef WIN32 + errno=WSAGetLastError(); +#endif if (errno == EINTR) continue; return -1; } @@ -81,6 +84,9 @@ PullTLS(gnutls_transport_ptr_t transport, void *data, size_t len) ret = read(client->sock, data, len); if (ret < 0) { +#ifdef WIN32 + errno=WSAGetLastError(); +#endif if (errno == EINTR) continue; return -1; } -- cgit v1.1