[Python-checkins] cpython (2.7): #12781: Mention SO_REUSEADDR flag near socket examples
sandro.tosi
python-checkins at python.org
Fri Sep 2 20:09:53 CEST 2011
http://hg.python.org/cpython/rev/fe60689d6a2e
changeset: 72203:fe60689d6a2e
branch: 2.7
user: Sandro Tosi <sandro.tosi at gmail.com>
date: Fri Sep 02 20:04:20 2011 +0200
summary:
#12781: Mention SO_REUSEADDR flag near socket examples
files:
Doc/library/socket.rst | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -989,3 +989,22 @@
# disabled promiscuous mode
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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list