Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any operation like socket.recv_into in python 3 asyncio?

Socket module has a socket.recv_into method, so it can use user-defined bytebuffer (like bytearray) for zero-copy. But perhaps BaseEventLoop has no method like that. Is there a way to use method like socket.recv_into in asyncio?

like image 401
SeungHyun Hwang Avatar asked Nov 01 '22 11:11

SeungHyun Hwang


2 Answers

The low-level socket operations defined for BaseEventLoop require a socket.socket object to be passed in, e.g. BaseEventLoop.sock_recv(sock, nbytes). So, given that you have a socket.socket, you could call sock.recv_into(). Whether it is a good idea to do that is another question.

like image 50
mhawke Avatar answered Nov 04 '22 07:11

mhawke


You may implement own asyncio transport which utilizes .recv_into() function but yes, for now asyncio has not a way to use .recv_into() out-the-box.

Personally I doubt in very big speedup: when you develop with C the zero-copy is extremely important but for high-level languages like Python benefits are much lesser.

like image 24
Andrew Svetlov Avatar answered Nov 04 '22 06:11

Andrew Svetlov