http: Allow non-blocking on Windows.

This commit is contained in:
Unknown W. Brackets
2016-05-26 18:16:37 -07:00
parent 8dd7527dc8
commit 026a69ebb0
2 changed files with 12 additions and 4 deletions
+11 -3
View File
@@ -75,7 +75,7 @@ ssize_t Write(int fd, const std::string &str) {
return WriteLine(fd, str.c_str(), str.size());
}
bool WaitUntilReady(int fd, double timeout) {
bool WaitUntilReady(int fd, double timeout, bool for_write) {
struct timeval tv;
tv.tv_sec = floor(timeout);
tv.tv_usec = (timeout - floor(timeout)) * 1000000.0;
@@ -84,7 +84,12 @@ bool WaitUntilReady(int fd, double timeout) {
FD_ZERO(&fds);
FD_SET(fd, &fds);
// First argument to select is the highest socket in the set + 1.
int rval = select(fd + 1, &fds, NULL, NULL, &tv);
int rval;
if (for_write) {
rval = select(fd + 1, NULL, &fds, NULL, &tv);
} else {
rval = select(fd + 1, &fds, NULL, NULL, &tv);
}
if (rval < 0) {
// Error calling select.
return false;
@@ -115,7 +120,10 @@ void SetNonBlocking(int sock, bool non_blocking) {
ELOG("Error setting socket nonblocking status");
}
#else
WLOG("NonBlocking mode not supported on Win32");
u_long val = non_blocking ? 1 : 0;
if (ioctlsocket(sock, FIONBIO, &val) != 0) {
ELOG("Error setting socket nonblocking status");
}
#endif
}
+1 -1
View File
@@ -18,7 +18,7 @@ ssize_t Write(int fd, const std::string &str);
// Returns true if the fd became ready, false if it didn't or
// if there was another error.
bool WaitUntilReady(int fd, double timeout);
bool WaitUntilReady(int fd, double timeout, bool for_write = false);
void SetNonBlocking(int fd, bool non_blocking);