[Python-bugs-list] [Bug #111710] socket.send() can do partial writes on some systems.

noreply@sourceforge.net noreply@sourceforge.net
Fri, 15 Sep 2000 11:50:58 -0700


Bug #111710, was updated on 2000-Aug-11 13:25
Here is a current snapshot of the bug.

Project: Python
Category: Library
Status: Closed
Resolution: None
Bug Group: Platform-specific
Priority: 5
Summary: socket.send() can do partial writes on some systems.

Details: 0811 15:57 chronis:~% uname -a
FreeBSD chronis.pobox.com 4.0-STABLE FreeBSD 4.0-STABLE #0: Tue Mar 21 01:05:14 EST 2000     root@chronis.pobox.com:/usr/src/sys/compile/MYBSD  i386
0811 15:57 chronis:~% 


0811 15:57 chronis:~% cat scratch/sendtstsrv.py     
import socket         
                      
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind("chronis.pobox.com", 8010) 

while 1:
    s.listen(1)
    conn, addr = s.accept()
    print "connected from", addr
    while 1:
        data = conn.recv(1024)
        if not data: break
    print "done"
    conn.close()

0811 15:58 chronis:~% python scratch/sendtstsrv.py &
[2] 76562

0811 15:58 chronis:~% cat scratch/sendtst.py 
#!/usr/bin/env python

s = "0" * 10000000



import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect("chronis.pobox.com", 8010)
sent = sock.send(s)
if sent != len(s):
    print "sent %d/%d chars" % (sent, len(s))
else:
    print "sent all chars"

0811 15:58 chronis:~% python !$
python scratch/sendtst.py
connected from ('208.210.124.49', 1258)
sent 17520/10000000 chars
done
0811 15:58 chronis:~%            


NOTE: there is nothing in any man page for send() under linux (RH 6.1), Solaris (SunOS 5.5.1), OSF1 V4.0, or FreeBSD{3,4} that states that send() must not perform a
partial write, though of those systems, it only seems
to reproducibly do partial writes under FreeBSD4.0 Stable.

Additionally, W.Richard Stevens' Unix Network Programming Vol 1, second edition states that """
A read or write on a stream socket might input or output fewer bytes than requested, but this is not an error condition.""" (page 77).  Later, Stevens says of send() and recv() "These two functions are similar to the standard read and write functions, but one additional argument is required". (page 354).

scott

Follow-Ups:

Date: 2000-Sep-07 15:01
By: jhylton

Comment:
Please do triage on this bug.
-------------------------------------------------------

Date: 2000-Sep-15 11:50
By: jhylton

Comment:
scott-- Is there a bug here?  It seems clear that the send system call is not required to send all the bytes you asked it to send.  It returns the number of bytes it did send.  If you want to make sure all your data is sent, you can wrap send in a while loop that calls send until all the data is consumed.

-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=111710&group_id=5470