[Help-gnutls] gnutls_record_recv with non-blocking i/o
From:
Martin Knappe
Subject:
[Help-gnutls] gnutls_record_recv with non-blocking i/o
Date:
Thu, 22 Jan 2009 12:46:00 +0100
hi
i have set up a server that accepts several tls clients; the client opens a socket descriptor for each new client and makes it a non-blocking socket (via fcntl(socket, F_SETFL, O_NONBLOCK)) i handle all clients in the same thread
my server loop looks like this (pseudo code)
for(;;) { poll(sockets) for sockets: s do { if canRead(s) { handleInput(s) } }
function handleInput(socket s) {
if (doTlsRecv(s, &buffer) == SUCCESS) { doSomethingWithInput(buffer); } }
the reason why i wrote doTlsRecv like this is because the gnutls documentation says this (documentation for gnutls_record_recv):
"If
GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN is returned, you must call
this function again, with the same parameters"
However, this does not work as it should: It works for a while, but when I run the manager for a while and clients start pumping data through the tls connection, I end up seeing the printf("repeating %d times\n", count); in doTlsRecv eternally! Why is that? How could I handle this?
Thanks
Martin
PS: I am using non-blocking sockets, because I dont want the server to hang when a client suddenly goes down while sending something (without properly closing tcp connection).