@@ -72,8 +72,9 @@ \section{\module{socket} ---
7272related to socket or address semantics raise the error
7373\exception {socket.error}.
7474
75- Non-blocking mode is supported through the
76- \method {setblocking()} method.
75+ Non-blocking mode is supported through
76+ \method {setblocking()}. A generalization of this based on timeouts
77+ is supported through \method {settimeout()}.
7778
7879The module \module {socket} exports the following constants and functions:
7980
@@ -284,8 +285,7 @@ \section{\module{socket} ---
284285descriptor is invalid. This function is rarely needed, but can be
285286used to get or set socket options on a socket passed to a program as
286287standard input or output (such as a server started by the \UNIX {} inet
287- daemon). The socket is assumed to be in blocking mode without
288- a timeout.
288+ daemon). The socket is assumed to be in blocking mode.
289289Availability: \UNIX .
290290\end {funcdesc }
291291
@@ -514,38 +514,39 @@ \subsection{Socket Objects \label{socket-objects}}
514514\method {send()} call can't immediately dispose of the data, a
515515\exception {error} exception is raised; in blocking mode, the calls
516516block until they can proceed.
517+ \code {s.setblocking(0)} is equivalent to \code {s.settimeout(0)};
518+ \code {s.setblocking(1)} is equivalent to \code {s.settimeout(None)}.
517519\end {methoddesc }
518520
519521\begin {methoddesc }[socket]{settimeout}{value}
520- Set a timeout on blocking socket operations. Value can be a
521- nonnegative float expressing seconds, or \code {None}. If a float is
522+ Set a timeout on blocking socket operations. The \var {value} argument
523+ can be a nonnegative float expressing seconds, or \code {None}.
524+ If a float is
522525given, subsequent socket operations will raise an \exception {error}
523526exception if the timeout period \var {value} has elapsed before the
524527operation has completed. Setting a timeout of \code {None} disables
525528timeouts on socket operations.
529+ \code {s.settimeout(0.0)} is equivalent to \code {s.blocking(0)};
530+ \code {s.settimeout(None)} is equivalent to \code {s.setblocking(1)}.
526531\versionadded {2.3}
527532\end {methoddesc }
528533
529534\begin {methoddesc }[socket]{gettimeout}{}
530535Returns the timeout in floating seconds associated with socket
531- operations, or \code {None} if no timeout is set.
536+ operations, or \code {None} if no timeout is set. This reflects
537+ the last call to \method {setblocking()} or \method {settimeout()}.
532538\versionadded {2.3}
533539\end {methoddesc }
534540
535- Some notes on the interaction between socket blocking and timeouts: A
536- socket object can be in one of three modes: blocking, non-blocking, or
537- timout. Sockets are always created in blocking mode. In blocking
538- mode, operations block until complete. In non-blocking mode,
539- operations fail (with an error that is unfortunately system-dependent)
540- if they cannot be completed immediately. In timeout mode, operations
541- fail if they cannot be completed within the timeout specified for the
542- socket.
543-
544- Calling \method {settimeout()} cancels non-blocking mode as set by
545- \method {setblocking()}; calling \method {setblocking()} cancels a
546- previously set timeout. Setting the timeout to zero acts similarly
547- but is implemented different than setting the socket in non-blocking
548- mode (this could be considered a bug and may even be fixed).
541+ Some notes on socket blocking and timeouts: A socket object can be in
542+ one of three modes: blocking, non-blocking, or timout. Sockets are
543+ always created in blocking mode. In blocking mode, operations block
544+ until complete. In non-blocking mode, operations fail (with an error
545+ that is unfortunately system-dependent) if they cannot be completed
546+ immediately. In timeout mode, operations fail if they cannot be
547+ completed within the timeout specified for the socket. The
548+ \method {setblocking()} method is simply a shorthand for certain
549+ \method {settimeout()} calls.
549550
550551Timeout mode internally sets the socket in non-blocking mode. The
551552blocking and timeout modes are shared between file descriptors and
0 commit comments