python / cpython

The Python programming language
https://www.python.org
Other
63.22k stars 30.27k forks source link

os.writev and socket.sendmsg return value are not ideal #84204

Open e888b79e-0010-4e57-af49-96f92d830757 opened 4 years ago

e888b79e-0010-4e57-af49-96f92d830757 commented 4 years ago
BPO 40023
Nosy @larryhastings, @tzickel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-feature', 'library', '3.9'] title = 'os.writev and socket.sendmsg return value are not ideal' updated_at = user = 'https://github.com/tzickel' ``` bugs.python.org fields: ```python activity = actor = 'tzickel' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'tzickel' dependencies = [] files = [] hgrepos = [] issue_num = 40023 keywords = [] message_count = 1.0 messages = ['364651'] nosy_count = 2.0 nosy_names = ['larry', 'tzickel'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue40023' versions = ['Python 3.9'] ```

e888b79e-0010-4e57-af49-96f92d830757 commented 4 years ago

os.writev and socket.sendmsg accept an iterable but the return value is number of bytes sent. That is not helpful as the user will have to write manual code to figure out which part of the iterable was not sent.

I propose to make a version of the functions where:

  1. The return value is an iterable of the leftovers (including a maybe one-time memoryview into an item who has been partly-sent).

  2. There is a small quirk where writev accepts only sequences but sendmsg accepts any iterable, which causes them not to behave the same for no good reason.

  3. Do we want an sendmsgall like sendall in socket, where it doesn't give up until everything is sent ?

  4. Today trying to use writev / sendmsg to be fully complaint requires checking the number of input items in the iterable to not go over IOV_MAX, maybe the python version of the functions should handle this automatically (and if it overflows, return the extra in leftovers) ?

Should the functions be the current one with an optional argument (return_leftovers) or a new function altogether.