[Help-gnutls] gnutls_record_recv with non-blocking i/o

Martin Knappe martin.knappe at gmail.com
Thu Jan 22 12:46:00 CET 2009


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);
    }
}

function doTlsRecv(void *buffer) {
    count = 1;
    for(;;) {
        read = gnutls_record_recv(session, buffer, INPUTSIZE);
        if ((read == GNUTLS_E_INTERRUPTED) || (read == GNUTLS_E_AGAIN)) {
            printf("repeating %d times\n", count);
            count++;
        } else {
            break;
        }
    if (read < 0) {
        return FAILURE;
    }
return SUCCESS;
}

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).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20090122/ca4557cb/attachment.htm>


More information about the Gnutls-help mailing list