Hello, I have been playing with libnanohttp and I found a quite annoying bug :
To reproduce it : start an HTTP server on port 10000 for example, then run : telnet localhost 10000 to connect to it, and then quit the telnet without even sending anything. Then the server will load the CPU.
I tracked down the problem, and it is in hssl_read (both SSL and non-SSL versions). This line is faulty :
if ((count = hsocket_select_recv(sock->sock, buf, len)) == -1)
hsocket_select_read does a select, and if select says there's something to read, calls read. The problem is that when a socket is closed, select still returns that the socket is readable, and read is called. Then read returns 0, which means end of file. So here the condition should consider this 0 value to stop checking on that socket and close it. My correction suggests to replace that line by :
if ((count = hsocket_select_recv(sock->sock, buf, len)) < 1)