Michael Wojcik [2014-05-09 21:12]: Hello Michael, thanks for your reply.
> > From: owner-openssl-us...@openssl.org [mailto:owner-openssl- > > us...@openssl.org] On Behalf Of Tilman Sauerbeck > > Sent: Thursday, 08 May, 2014 12:26 > > > > my program is an SSL client which is reading large amounts of data > > without sending data itself (after the initial handshake). > > My machine's connection does drop regularly, and I want to make sure > > that my program detects the dropped connection instead of hanging in > > read()/recv() forever. > > ... > > Another attempt was to use select() to check if the socket is readable > > just before calling SSL_read(), like so: > > That's not useful in your case. When you're receiving on a TCP connection and > not sending, and the connection is closed, the socket will be flagged as > readable. With select() you can't distinguish between a connection that has > data available and a connection that has received a TCP FIN or RST. Yes, and I wanted to only ask OpenSSL to read from the socket if it was readable. I wouldn't care if that read() returned 0. > > Without the SO_RCVTIMEO, this doesn't work either, probably because > > I'm only using select() if SSL_read() failed with SSL_ERROR_WANT_READ > > before. > > I suspect it doesn't work because select is returning non-zero, because the > socket is readable. If the socket was readable, the following call to SSL_read() wouldn't block though. However with that snippet, I'm still seeing hanging read() calls. > > Can anyone shed some light on this issue? > > What am I missing? > > Only that usual practice for an application that wants to be able to abort a > TCP receive operation is to use non-blocking sockets. SO_RCVTIMEO was created > when threading became commonly available on UNIX platforms and blocking > network I/O became a more usable approach for complex applications. > Consequently, most people who want more control over the behavior of a > passive TCP endpoint still use nonblocking sockets. I guess I thought SO_RCVTIMEO was widespread enough for OpenSSL to handle it or mention it in the documentation... I'll give a non-blocking socket a try. Thanks again, Tilman -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org