Closed mhupfer closed 2 years ago
AsyncSocket::poll_recv_from_full
already provides the "get size of message first, then allocate, then read" functionality. (I just saw the doc for it is broken, and just a copy of the one above. That probably should get fixed.)
I'm quite sure I designed the trait this way on purpose, because handling flags and a length that (with the MSG_TRUNC
flag) doesn't necessarily reflect the number of bytes read is imho quite dangerous and should be used for a low-level API only.
Any reason you can't use AsyncSocket::poll_recv_from_full
?
Found it, will give it a try.
Meanwhile I stumbled upon another issue. In impl<'buffer, B, I> Parseable<NetlinkBuffer<&'buffer B>> for NetlinkMessage the code exits immediately when it detects NLMSG_DONE. But at least for the kernel connector (https://github.com/torvalds/linux/blob/master/Documentation/driver-api/connector.rst) the last messages flagged with NLMSG_DONE transports a payload.
I solved that by commenting out one line:
...
//NLMSG_DONE => Done,
...
and checking in my application if the received buffer is completely parsed. Maybe you have a better idea ...
Regarding NLMSG_DONE
see #230 and perhaps #249.
And when will #249 be merged?
Can be achieved by using AsyncSocket::poll_recv_from_full
Pass flags to recv() and recv_from(), give back the received bytes as result.
Thats enables passing MSG_PEEK | MSG_TRUNC to determine the number of bytes in the socket first, before allocating a buffer and receiving the data.