diff options
| -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);  				} | 
