diff options
author | pixel <pixel> | 2007-02-07 04:52:01 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-02-07 04:52:01 +0000 |
commit | ad5b3e7d98be15b5f8b8f953899a28a8882173c1 (patch) | |
tree | 005d8f64351830f4230d62e2f2ac595a29ff2433 /lib | |
parent | c5e2bbb73d1a0b8ae24cd8045883c6a15632ed17 (diff) |
Fixing win32 port of poll.
Fixed vector<> usage issue.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/TaskMan.cc | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index 31ed942..183b162 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -88,6 +88,7 @@ static int poll (struct pollfd *fds, unsigned int nfds, int timeout) { struct timeval tv = { timeout / 1000, (timeout % 1000) * 1000 }; int max_fd = 0, retval, changedfds; unsigned int i; + int n_non_socket = 0; FD_ZERO(&read_fds); FD_ZERO(&write_fds); @@ -97,6 +98,19 @@ static int poll (struct pollfd *fds, unsigned int nfds, int timeout) { if (!fds[i].fd && !fds[i].events) continue; + BOOL dummy; + int dummy_s = sizeof(dummy); + + if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ACCEPTCONN, (char *) &dummy, &dummy_s) == SOCKET_ERROR) { + if (WSAGetLastError() == WSAENOTSOCK) { + if (fds[i].events & POLLIN) { + n_non_socket++; + fds[i].revents |= POLLIN; + } + continue; + } + } + if (fds[i].fd > max_fd) max_fd = fds[i].fd; @@ -111,11 +125,47 @@ static int poll (struct pollfd *fds, unsigned int nfds, int timeout) { fds[i].revents = 0; } + if (n_non_socket) { + tv.tv_sec = 0; + tv.tv_usec = 0; + timeout = 0; + } + changedfds = retval = select(max_fd + 1, &read_fds, &write_fds, &except_fds, timeout < 0 ? NULL : &tv); if (retval <= 0) { - // got timeout or error - return retval; + if (retval < 0) { + int err = WSAGetLastError(); + // got timeout or error + switch (err) { + case WSANOTINITIALISED: + Base::printm(M_INFO, "WSANOTINITIALISED\n"); + break; + case WSAEFAULT: + Base::printm(M_INFO, "WSAEFAULT\n"); + break; + case WSAENETDOWN: + Base::printm(M_INFO, "WSAENETDOWN\n"); + break; + case WSAEINVAL: + Base::printm(M_INFO, "WSAEINVAL\n"); + break; + case WSAEINTR: + Base::printm(M_INFO, "WSAEINTR\n"); + break; + case WSAEINPROGRESS: + Base::printm(M_INFO, "WSAEINPROGRESS\n"); + break; + case WSAENOTSOCK: + Base::printm(M_INFO, "WSAENOTSOCK\n"); + break; + default: + Base::printm(M_INFO, "Unknown error\n"); + } + return retval; + } else { + return n_non_socket; + } } for (i = 0; i < nfds; i++) { @@ -138,7 +188,7 @@ static int poll (struct pollfd *fds, unsigned int nfds, int timeout) { break; } - return retval; + return retval + n_non_socket; } #define EPOCHFILETIME (116444736000000000i64) @@ -578,6 +628,7 @@ void TaskMan::MainLoop() throw (GeneralException) { // cerr << "-=- TaskMan: launching task " << p->T->GetName() << " for handle " << p->ha->GetHandle() << endl; w4ha_t w4 = *p; p->dirty = true; + ehandle = p->ha; if (!(p->flags & Task::W4_STICKY)) { w4ha.erase(p); @@ -585,7 +636,6 @@ void TaskMan::MainLoop() throw (GeneralException) { touched = true; - ehandle = p->ha; w4.T->Run(); CheckDead(w4.T); } |