summaryrefslogtreecommitdiffstats
path: root/Doc/library/socket.rst
diff options
context:
space:
mode:
authorSandro Tosi <sandro.tosi@gmail.com>2011-09-02 18:07:34 (GMT)
committerSandro Tosi <sandro.tosi@gmail.com>2011-09-02 18:07:34 (GMT)
commit0b6b1c3fb5423bdde5a86284ad2fa98b8b031321 (patch)
treeff86f758864f087ca30ea298da2cb91d07df6773 /Doc/library/socket.rst
parent6f08f53e797848b6e2f5e7eeaf20f9dcaba3e28b (diff)
parent172f374a63bfc61f71ee925463927a81350b66da (diff)
downloadcpython-0b6b1c3fb5423bdde5a86284ad2fa98b8b031321.zip
cpython-0b6b1c3fb5423bdde5a86284ad2fa98b8b031321.tar.gz
cpython-0b6b1c3fb5423bdde5a86284ad2fa98b8b031321.tar.bz2
#12781: merge with 3.2
Diffstat (limited to 'Doc/library/socket.rst')
-rw-r--r--Doc/library/socket.rst19
1 files changed, 19 insertions, 0 deletions
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index 196fe8b..8b5b728 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -1239,6 +1239,25 @@ the interface::
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
+Running an example several times with too small delay between executions, could
+lead to this error::
+
+ socket.error: [Errno 98] Address already in use
+
+This is because the previous execution has left the socket in a ``TIME_WAIT``
+state, and can't be immediately reused.
+
+There is a :mod:`socket` flag to set, in order to prevent this,
+:data:`socket.SO_REUSEADDR`::
+
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ s.bind((HOST, PORT))
+
+the :data:`SO_REUSEADDR` flag tells the kernel to reuse a local socket in
+``TIME_WAIT`` state, without waiting for its natural timeout to expire.
+
+
.. seealso::
For an introduction to socket programming (in C), see the following papers: