[Python-checkins] r87658 - in python/branches/release31-maint: Doc/library/socket.rst Doc/library/ssl.rst

antoine.pitrou python-checkins at python.org
Sun Jan 2 23:36:00 CET 2011


Author: antoine.pitrou
Date: Sun Jan  2 23:35:59 2011
New Revision: 87658

Log:
Merged revisions 87653-87655 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r87653 | antoine.pitrou | 2011-01-02 23:06:53 +0100 (dim., 02 janv. 2011) | 3 lines
  
  Clarify behaviour of close() and shutdown() on sockets.
........
  r87654 | antoine.pitrou | 2011-01-02 23:09:27 +0100 (dim., 02 janv. 2011) | 3 lines
  
  Add a shutdown() call in the server example.
........
  r87655 | antoine.pitrou | 2011-01-02 23:12:22 +0100 (dim., 02 janv. 2011) | 3 lines
  
  Some nits.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Doc/library/socket.rst
   python/branches/release31-maint/Doc/library/ssl.rst

Modified: python/branches/release31-maint/Doc/library/socket.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/socket.rst	(original)
+++ python/branches/release31-maint/Doc/library/socket.rst	Sun Jan  2 23:35:59 2011
@@ -26,6 +26,15 @@
 is implicit on send operations.
 
 
+.. seealso::
+
+   Module :mod:`socketserver`
+      Classes that simplify writing network servers.
+
+   Module :mod:`ssl`
+      A TLS/SSL wrapper for socket objects.
+
+
 Socket families
 ---------------
 
@@ -487,12 +496,6 @@
    same as ``type(socket(...))``.
 
 
-.. seealso::
-
-   Module :mod:`socketserver`
-      Classes that simplify writing network servers.
-
-
 .. _socket-objects:
 
 Socket Objects
@@ -522,6 +525,12 @@
    remote end will receive no more data (after queued data is flushed). Sockets are
    automatically closed when they are garbage-collected.
 
+   .. note::
+      :meth:`close()` releases the resource associated with a connection but
+      does not necessarily close the connection immediately.  If you want
+      to close the connection in a timely fashion, call :meth:`shutdown()`
+      before :meth:`close()`.
+
 
 .. method:: socket.connect(address)
 

Modified: python/branches/release31-maint/Doc/library/ssl.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/ssl.rst	(original)
+++ python/branches/release31-maint/Doc/library/ssl.rst	Sun Jan  2 23:35:59 2011
@@ -1,8 +1,8 @@
-:mod:`ssl` --- SSL wrapper for socket objects
-=============================================
+:mod:`ssl` --- TLS/SSL wrapper for socket objects
+=================================================
 
 .. module:: ssl
-   :synopsis: SSL wrapper for socket objects
+   :synopsis: TLS/SSL wrapper for socket objects
 
 .. moduleauthor:: Bill Janssen <bill.janssen at gmail.com>
 .. sectionauthor::  Bill Janssen <bill.janssen at gmail.com>
@@ -537,13 +537,17 @@
 for it::
 
    while True:
-      newsocket, fromaddr = bindsocket.accept()
-      connstream = ssl.wrap_socket(newsocket,
-                                   server_side=True,
-                                   certfile="mycertfile",
-                                   keyfile="mykeyfile",
-                                   ssl_version=ssl.PROTOCOL_TLSv1)
-      deal_with_client(connstream)
+       newsocket, fromaddr = bindsocket.accept()
+       connstream = ssl.wrap_socket(newsocket,
+                                    server_side=True,
+                                    certfile="mycertfile",
+                                    keyfile="mykeyfile",
+                                    ssl_version=ssl.PROTOCOL_TLSv1)
+       try:
+           deal_with_client(connstream)
+       finally:
+           connstream.shutdown(socket.SHUT_RDWR)
+           connstream.close()
 
 Then you'd read data from the ``connstream`` and do something with it till you
 are finished with the client (or the client is finished with you)::
@@ -559,7 +563,6 @@
             break
          data = connstream.read()
       # finished with client
-      connstream.close()
 
 And go back to listening for new client connections.
 


More information about the Python-checkins mailing list