fpagliughi / sockpp

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

Does Windows support socket timeouts? #32

Closed fpagliughi closed 4 years ago

fpagliughi commented 4 years ago

In the stream_socket class, the calls to read_timeout() and write_timeout() are empty for Windows. I can't remember if Windows doesn't support this, or if I was just too lazy to look up how.

@borrrden Do you know?

bool stream_socket::read_timeout(const microseconds& to)
{
    #if !defined(_WIN32)
        timeval tv = to_timeval(to);
        return set_option(SOL_SOCKET, SO_RCVTIMEO, tv);
    #else
        return false;
    #endif
}
borrrden commented 4 years ago

Not in the same way, I think. It does support read and write timeouts but they are set per socket (i.e. setsockopt) while it looks like this is being set globally.

fpagliughi commented 4 years ago

Oh, sorry that code snippet is a bit misleading. The set_option() call is a socket member function, so it changes the timeout for the specific socket.

It just calls the OS setsockopt(). Does Windows support that? Looks like maybe. So perhaps I remove the conditional compilation and it works. I'll try that when I dust off the Windows laptop.

borrrden commented 4 years ago

Yes, setsockopt is a part of the WSA API.

fpagliughi commented 4 years ago

Yes, the same call... except that Windows uses a different data type for the parameter! (DWORD milliseconds instead of timeval). OMG. Windows.