37 extern HANDLE fd_to_handle(
int fd) {
39 HANDLE handle = (HANDLE)_get_osfhandle(fd);
40 if (handle != INVALID_HANDLE_VALUE)
return handle;
43 return reinterpret_cast<HANDLE
>(fd);
49 if (
close(fd) == -1 && errno == EBADF) {
63 #if defined SO_SNDTIMEO || defined SO_RCVTIMEO 71 if (
usual(timeout < numeric_limits<DWORD>::max() / 1000))
74 t = numeric_limits<DWORD>::max();
77 (void)setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO,
78 reinterpret_cast<char*>(&t),
sizeof(t));
81 (void)setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,
82 reinterpret_cast<char*>(&t),
sizeof(t));
96 (void)setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
97 reinterpret_cast<char*>(&flag),
sizeof(flag));
void set_socket_timeouts(int fd, double timeout)
Attempt to set socket-level timeouts.
unsigned timeout
A timeout value in milliseconds.
Work around MSVC's unhelpful non-standard invalid parameter handling.
include <sys/socket.h> with portability workarounds.
void close_fd_or_socket(int fd)
Socket handling utilities.
void to_timeval(double t, struct timeval *tv)
Fill in struct timeval from number of seconds in a double.
Functions for handling a time or time interval in a double.