Xref: utzoo comp.unix.programmer:1782 comp.unix.questions:31171 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!decuac!hussar.dco.dec.com!mjr From: mjr@decuac.dec.com (Marcus J. Ranum) Newsgroups: comp.unix.programmer,comp.unix.questions Subject: timeouts on connect(2) - EWOULDBLOCK, & such. Message-ID: <1991May09.221038.21861@decuac.dec.com> Date: 9 May 91 22:10:38 GMT Organization: Digital Equipment Corp., Washington Ultrix Resource Center Lines: 19 Originator: mjr@hussar.dco.dec.com I've been trying to implement what amounts to a timeout on a connect(2) call, and I'm unsatisfied with the results I've been getting. Basically, I set the socket nonblocking, do the connect(), it fails, then I select the socket for reading. First off, I get EINPROGRESS instead of EWOULDBLOCK as TFM implies, but worst of all I don't have an indication of whether or not the file descriptor is any good - in the case where I select on the fd, and a very short time later I get a connection refusal, it's hard to tell if that indeed happened. What's the elegant way to do this? I'd basically like to just "connect to that machine and give me an error if it takes more than N sec" kind of thing. Do I have to do something really gross like try to write junk and see if it bombs? TFM for fstat implies it's useless. Suggestions? mjr.