Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5aa0d10

Browse files
committed
Improve docs for socket.makefile() and SocketIO
1 parent 872b79d commit 5aa0d10

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

Doc/library/socket.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,9 @@ correspond to Unix system calls applicable to sockets.
622622
arguments are interpreted the same way as by the built-in :func:`open`
623623
function.
624624

625-
The returned file object references a :cfunc:`dup`\ ped version of the
626-
socket file descriptor, so the file object and socket object may be
627-
closed or garbage-collected independently. The socket must be in
628-
blocking mode (it can not have a timeout).
625+
Closing the file object won't close the socket unless there are no
626+
remaining references to the socket. The socket must be in blocking mode
627+
(it can not have a timeout).
629628

630629

631630
.. method:: socket.recv(bufsize[, flags])

Lib/socket.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
errno = None
5555
EBADF = getattr(errno, 'EBADF', 9)
5656
EINTR = getattr(errno, 'EINTR', 4)
57+
EAGAIN = getattr(errno, 'EAGAIN', 11)
58+
EWOULDBLOCK = getattr(errno, 'EWOULDBLOCK', 11)
5759

5860
__all__ = ["getfqdn", "create_connection"]
5961
__all__.extend(os._get_exports_list(_socket))
@@ -249,6 +251,13 @@ def __init__(self, sock, mode):
249251
self._writing = "w" in mode
250252

251253
def readinto(self, b):
254+
"""Read up to len(b) bytes into the writable buffer *b* and return
255+
the number of bytes read. If the socket is non-blocking and no bytes
256+
are available, None is returned.
257+
258+
If *b* is non-empty, a 0 return value indicates that the connection
259+
was shutdown at the other end.
260+
"""
252261
self._checkClosed()
253262
self._checkReadable()
254263
while True:
@@ -260,17 +269,28 @@ def readinto(self, b):
260269
raise
261270

262271
def write(self, b):
272+
"""Write the given bytes or bytearray object *b* to the socket
273+
and return the number of bytes written. This can be less than
274+
len(b) if not all data could be written. If the socket is
275+
non-blocking and no bytes could be written None is returned.
276+
"""
263277
self._checkClosed()
264278
self._checkWritable()
265279
return self._sock.send(b)
266280

267281
def readable(self):
282+
"""True if the SocketIO is open for reading.
283+
"""
268284
return self._reading and not self.closed
269285

270286
def writable(self):
287+
"""True if the SocketIO is open for writing.
288+
"""
271289
return self._writing and not self.closed
272290

273291
def fileno(self):
292+
"""Return the file descriptor of the underlying socket.
293+
"""
274294
self._checkClosed()
275295
return self._sock.fileno()
276296

@@ -283,6 +303,9 @@ def mode(self):
283303
return self._mode
284304

285305
def close(self):
306+
"""Close the SocketIO object. This doesn't close the underlying
307+
socket, except if all references to it have disappeared.
308+
"""
286309
if self.closed:
287310
return
288311
io.RawIOBase.close(self)

0 commit comments

Comments
 (0)