diff options
Diffstat (limited to 'libvncclient/tls_gnutls.c')
-rw-r--r-- | libvncclient/tls_gnutls.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/libvncclient/tls_gnutls.c b/libvncclient/tls_gnutls.c index 3daa416..b9ffe89 100644 --- a/libvncclient/tls_gnutls.c +++ b/libvncclient/tls_gnutls.c @@ -67,9 +67,20 @@ InitializeTLS(void) * libvncclient are linked to different versions of msvcrt.dll. */ #ifdef WIN32 -static void WSAtoTLSErrno() +static void WSAtoTLSErrno(gnutls_session_t* session) { switch(WSAGetLastError()) { +#if (GNUTLS_VERSION_NUMBER >= 0x029901) + case WSAEWOULDBLOCK: + gnutls_transport_set_errno(session, EAGAIN); + break; + case WSAEINTR: + gnutls_transport_set_errno(session, EINTR); + break; + default: + gnutls_transport_set_errno(session, EIO); + break; +#else case WSAEWOULDBLOCK: gnutls_transport_set_global_errno(EAGAIN); break; @@ -79,11 +90,11 @@ static void WSAtoTLSErrno() default: gnutls_transport_set_global_errno(EIO); break; +#endif } } #endif - static ssize_t PushTLS(gnutls_transport_ptr_t transport, const void *data, size_t len) { @@ -96,7 +107,7 @@ PushTLS(gnutls_transport_ptr_t transport, const void *data, size_t len) if (ret < 0) { #ifdef WIN32 - WSAtoTLSErrno(); + WSAtoTLSErrno((gnutls_session_t*)&client->tlsSession); #endif if (errno == EINTR) continue; return -1; @@ -118,7 +129,7 @@ PullTLS(gnutls_transport_ptr_t transport, void *data, size_t len) if (ret < 0) { #ifdef WIN32 - WSAtoTLSErrno(); + WSAtoTLSErrno((gnutls_session_t*)&client->tlsSession); #endif if (errno == EINTR) continue; return -1; @@ -480,6 +491,14 @@ WriteToTLS(rfbClient* client, char *buf, unsigned int n) unsigned int offset = 0; ssize_t ret; + if (client->LockWriteToTLS) + { + if (!client->LockWriteToTLS(client)) + { + rfbClientLog("Callback to get lock in WriteToTLS() failed\n"); + return -1; + } + } while (offset < n) { ret = gnutls_record_send((gnutls_session_t)client->tlsSession, buf+offset, (size_t)(n-offset)); @@ -488,10 +507,23 @@ WriteToTLS(rfbClient* client, char *buf, unsigned int n) { if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) continue; rfbClientLog("Error writing to TLS: %s.\n", gnutls_strerror(ret)); + if (client->UnlockWriteToTLS) + { + if (!client->UnlockWriteToTLS(client)) + rfbClientLog("Callback to unlock WriteToTLS() failed\n"); + } return -1; } offset += (unsigned int)ret; } + if (client->UnlockWriteToTLS) + { + if (!client->UnlockWriteToTLS(client)) + { + rfbClientLog("Callback to unlock WriteToTLS() failed\n"); + return -1; + } + } return offset; } |