<div dir="ltr"><div>With current socket.sendall() implementation if an error occurs it's impossible to tell how much data was sent. As such I'm wondering whether it would make sense to add a "counter" parameter which gets incremented internally:<br>
</div><div><br></div><div><div>sent = 0</div><div>try:</div><div> sock.sendall(data, counter=sent)</div><div>except socket.error as err:</div><div> priint("only %s bytes were sent" % sent)<br></div><div>
<br></div><div>This would both allow to not lose information on error and avoid keeping track of the total data being sent, which usually requires and extra len() call. E.g. when sending a file:</div><div><br></div><div>
<div>
file = open('somefile', 'rb')<br></div><div>total = 0<br></div><div>while True:</div><div> chunk = file.read(8192)</div><div> if not chunk:</div><div> break</div><div> sock.sendall(chunk, counter=total)</div>
</div><div><br></div><div>Thoughts?</div><div><br></div><div><div>-- <br><div dir="ltr"><div>Giampaolo - <a href="http://grodola.blogspot.com" target="_blank">http://grodola.blogspot.com</a></div><div><br></div></div>
</div></div></div></div>