mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-09-04 03:35:19 +02:00
http: Allow non-blocking on Windows.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user