- if (socket->m_fd == -1)
- {
- socket->m_error = GSOCK_INVSOCK;
- return FALSE;
- }
-
- FD_ZERO(&readfds);
- FD_ZERO(&writefds);
- FD_ZERO(&exceptfds);
- FD_SET(socket->m_fd, &readfds);
- FD_SET(socket->m_fd, &writefds);
- FD_SET(socket->m_fd, &exceptfds);
-
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- select(socket->m_fd + 1, &readfds, &writefds, &exceptfds, &tv);
-
- mask = 0;
-
- /* If select() says that the socket is readable, then we have
- * no way to distinguish if that means 'data available' (to
- * recv) or 'incoming connection' (to accept). The same goes
- * for writability: we cannot distinguish between 'you can
- * send data' and 'connection request completed'. So we will
- * assume the following: if the flag was set upon entry,
- * that means that the event was possible.
- */
- if (FD_ISSET(socket->m_fd, &readfds))
- {
- mask |= (flags & GSOCK_CONNECTION_FLAG);
- mask |= (flags & GSOCK_INPUT_FLAG);
- }
- if (FD_ISSET(socket->m_fd, &writefds))
- {
- if (socket->m_establishing)
- {
- getsockopt(socket->m_fd, SOL_SOCKET, SO_ERROR, &error, &len);
-
- if (error)
- mask |= (flags & GSOCK_LOST_FLAG);
- else
- mask |= (flags & GSOCK_CONNECTION_FLAG);
- }
- mask |= (flags & GSOCK_OUTPUT_FLAG);
- }
- if (FD_ISSET(socket->m_fd, &exceptfds))
- mask |= (flags & GSOCK_LOST_FLAG);
-
- return mask;