Socket read() hangs for a while when there is no data to read.

Posted by janesconference on Stack Overflow See other posts from Stack Overflow or by janesconference
Published on 2010-05-24T11:45:42Z Indexed on 2010/05/24 11:51 UTC
Read the original article Hit count: 301

Filed under:
|
|
|
|

Hi' I'm writing a simple http port forwarder. I read data from port 80, and pass the data to my lighttpd server, on port 8080.

As long as I write() data on the socket on port 8080 (forwarding the request) there's no problem, but when I read() data from that socket (forwarding the response), the last read() hangs a lot (about 1 or 2 seconds) before realizing there's no more data and returning 0.

I tried to set the socket to non-blocking, but this doesn't work, as sometimes it returns EWOULDBLOCKING even if there's some data left (lighttpd + cgi can be quite slow). I tried to set a timeout with select(), but, as above, a slow cgi could timeout the socket when there's actually some data to transmit.

How would you do?

© Stack Overflow or respective owner

Related posts about c

    Related posts about linux