+ socket->m_detected |= (1 << event);
+ _GSocket_Uninstall_Callback(socket, event);
+}
+
+/* _GSocket_Input_Timeout:
+ * For blocking sockets, wait until data is available or
+ * until timeout ellapses.
+ */
+GSocketError _GSocket_Input_Timeout(GSocket *socket)
+{
+ struct timeval tv;
+ fd_set readfds;
+
+ /* Linux select() will overwrite the struct on return */
+ tv.tv_sec = (socket->m_timeout / 1000);
+ tv.tv_usec = (socket->m_timeout % 1000) * 1000;
+
+ if (!socket->m_non_blocking)
+ {
+ FD_ZERO(&readfds);
+ FD_SET(socket->m_fd, &readfds);
+ if (select(socket->m_fd + 1, &readfds, NULL, NULL, &tv) == 0)
+ {
+ socket->m_error = GSOCK_TIMEDOUT;
+ return GSOCK_TIMEDOUT;
+ }
+ }
+ return GSOCK_NOERROR;
+}
+
+/* _GSocket_Output_Timeout:
+ * For blocking sockets, wait until data can be sent without
+ * blocking or until timeout ellapses.
+ */
+GSocketError _GSocket_Output_Timeout(GSocket *socket)
+{
+ struct timeval tv;
+ fd_set writefds;
+
+ /* Linux select() will overwrite the struct on return */
+ tv.tv_sec = (socket->m_timeout / 1000);
+ tv.tv_usec = (socket->m_timeout % 1000) * 1000;
+
+ if (!socket->m_non_blocking)
+ {
+ FD_ZERO(&writefds);
+ FD_SET(socket->m_fd, &writefds);
+ if (select(socket->m_fd + 1, NULL, &writefds, NULL, &tv) == 0)
+ {
+ socket->m_error = GSOCK_TIMEDOUT;
+ return GSOCK_TIMEDOUT;
+ }
+ }
+ return GSOCK_NOERROR;