Re: When is it OK to change O_NONBLOCK mode of a socket?



In article
<2419d918-a467-4c06-ac4a-fcbfd1adf358@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"jason.cipriani@xxxxxxxxx" <jason.cipriani@xxxxxxxxx> wrote:

First of all, what I want to do:

1. Create socket (will be either SOCK_STREAM/SOCK_DGRAM + PF_INET).
2. Set as nonblocking.
3. Connect with timeout (connect + select).
4. Set as blocking.
5. Other I/O stuff.

In my application, a blocking socket is more convenient, but I would
like to set it to non-blocking mode for connect() so I have control
over the timeout. Is this always OK?

Yes.


Also, in general, are there any rules about when it's OK to change the
blocking/non-blocking mode of a socket? Can I just do it arbitrarily?

Yes. It just affects future calls to operations that can block.

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.



Relevant Pages

  • When is it OK to change O_NONBLOCK mode of a socket?
    ... Connect with timeout. ... In my application, a blocking socket is more convenient, but I would ... like to set it to non-blocking mode for connectso I have control ...
    (comp.unix.programmer)
  • Re: help adding timeout to nntp?
    ... including the http library in tcl itself, provide a timeout. ... Problem is that Tcl's API isn't complete. ... switching between blocking and non-blocking. ... The tell here is why switch to blocking mode? ...
    (comp.lang.tcl)
  • Re: recv blocks although socket is ready
    ... I'm not sure if changing to non-blocking mode is really an option. ... code for those members of the interface which have blocking semantics. ... IRIX, IRIX64, Linux, OSF1, SunOS and Windows. ... frequently when there is some UDP traffic on another socket. ...
    (microsoft.public.win32.programmer.networks)
  • Re: how to avoid recv() blocking issue?
    ... blocking socket it's certainly possible. ... Yet another reason to not use blocking sockets... ... Microsoft MVP, MCSD ... drop the connection abnormally such that the blocking recv will never ...
    (microsoft.public.win32.programmer.networks)
  • Re: select() "hangs"
    ... Are all descriptors set to non-blocking mode? ... Running as normal and attaching once the ... superfluous, if not wrong, to open the files in a blocking manner... ... The operation of selectis not affected by the non-blocking mode of the ...
    (comp.unix.programmer)