fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
782 stars 126 forks source link

Added multi-write: stream_socket::write(vector<iovec>) #31

Closed snej closed 4 years ago

snej commented 4 years ago

Scatter/gather write method, like writev. Credit to @borrrden for the Windows version.

26

fpagliughi commented 4 years ago

This is pretty close to what I have. I'll merge and include my readv()

fpagliughi commented 4 years ago

I pushed this into an io_vec branch, for now. I will have a closer look, implement readv(), and write the unit tests and docs.

fpagliughi commented 4 years ago

Oh, and thanks again!

fpagliughi commented 4 years ago

Actually, I'm a little confused about the Windows implementation, looking at the documentation for WSASendMsg here: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg

The WSASendMsg function can only be used with datagrams and raw sockets. The socket descriptor in the s parameter must be opened with the socket type set to SOCK_DGRAM or SOCK_RAW.

So, will it work with stream sockets?

In addition, when I try to compile in the read variant, WSARecvMsg() I get a build error, saying that it's not found.

 error C3861: 'WSARecvMsg': identifier not found

Any ideas?

borrrden commented 4 years ago

Hm I've been away from this for a bit but I didn't notice that part of the documentation. Are there tests that cover this part? I might have seen it and assumed it worked because of its similarity to the Unix variant.

borrrden commented 4 years ago

It looks like WSASend, not WSASendMsg is the one we are after. The signature is almost identical, except that it takes its arguments in two parameters instead of one combined one for the buffers. Perhaps WSARecv is also the one to use for the reverse (which is where, actually?)

fpagliughi commented 4 years ago

I moved this pull request into the io_vec branch, so I could start messing around with it. I didn't push the last stuff I did in Windows as it was turning into an ugly hack fest. I'll do a quick cleanup, maybe look at WSASend/Recv, and git it a push.

fpagliughi commented 4 years ago

@borrrden I just put in WSASend/Recv. It compiles, but I don't have time to test it today. I'll get back to it in a day or two.