Expanding asyncio support for socket APIs

The asyncio event loop provides coroutine based versions of socket.recv, and others. Some socket.socket APIs like sendmsg and recvmsg are missing. This enhancement would be to add

  • loop.sock_sendmsg - async analogue of socket.sendmsg
  • loop.sock_recvmsg - async analogue of socket.recvmsg
  • loop.sock_send_fds - async analogue of socket.send_fds
  • loop.sock_recv_fds - async analogue of socket.recv_fds
  • more, depending on desire for more complete compatibility with the socket.socket API set.

Some socket APIs like sendmsg and send_fds provide different features that socket.send do not, for example sending ancillary data or sharing file descriptors between processes.

From my understanding, we could implement these proposed loop.sock_[sendmsg/recvmsg/etc] with a similar approach to how asyncio’s sock_send works. Once we’re happy with the set of APIs, I’d be happy to start implementation of this work.

Do you have real-world code that would benefit from these new APIs? How much? New APIs are a maintenance burden even if nobody uses them, we’ve learned.

My use case would be a client of something like sockpool. Sockpool is a server that pools sockets, with clients using sendmsg/recvmsg (in C terms) or the Python convenience wrappers send_fds/recv_fds to acquire and donate socket connections. This is the only specific real-world code that I have (and, thus far, I’ve wrapped my own versions of non-blocking socket.socket APIs that integrate with the event loop).

Let’s see if others have the same use case. If it’s just you, I’d rather not be responsible for such a new feature.