Persistent Timeout Protocol and the Sockets Package
Description
Examples
A number of routines in the Sockets package block indefinitely by default. In most cases, it is possible to limit the time for which a routine will block by passing an extra timeout argument. The timeout argument indicates the number of seconds to block while waiting for the availability of data. If this time expires, the routine returns the value false.
In some cases, it is inconvenient (and error-prone) to maintain a timeout value at each and every callsite to a blocking routine. For this reason, most of these types of routines obey the "persistent timeout protocol."
It is possible to configure a socket connection with a "persistent timeout" value by using the procedure Configure with the timeout option. The default value of the timeout option is -1, which means that no persistent timeout has been configured on that connection.
You can set a persistent timeout on a connection by a call of the form Configure( sid, 'timeout' = secs ), where sid is the socket ID of the connection to configure and secs is the number of seconds to configure the persistent timeout to block for. This is essentially equivalent to specifying secs as the optional timeout parameter in all subsequent calls to routines that take one on that connection. However, the persistent timeout value can still be overridden by a transient timeout specification at the call site.
A persistent timeout value can be removed from a socket connection by setting the option value to -1 by using Configure( sid, 'timeout' = -1 ).
By default, no persistent timeout is configured on a connection.
with⁡Sockets:
sid≔Open⁡localhost,echo
0
Configure⁡sid,timeout
−1
See Also
socket definition
Sockets
Sockets[Configure]
Sockets[Peek]
Sockets[Read]
Sockets[ReadBinary]
Sockets[ReadLine]
Download Help Document