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



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?

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?

Thanks,
Jason
.



Relevant Pages

  • 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: 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: Erlang-style concurrency
    ... /Any/ receive operation in Erang, selective or not, is blocking. ... blocks until a message arrives (or the timeout expires, ... then given that passing is asynchronous in Erlang the the sender can't ... blocks only for B (possibly with a timeout) or whether it will accept ...
    (comp.lang.functional)
  • Re: GNAT.Sockets: Timeval_Duration is in milliseconds?
    ... "Sets a timeout, in milliseconds, for blocking receive calls. ... I suppose we have to report this as a bug in GNAT though it would be ...
    (comp.lang.ada)
  • Re: View timed out every now and then
    ... If the timeout is due to blocking, ... The reason why we thought it was blocking is because the same query ... Links for SQL Server Books Online: ...
    (microsoft.public.sqlserver.programming)