- char c;
-
- if (m_fd == INVALID_SOCKET)
- {
- return;
- }
-
- int num = recv(m_fd, &c, 1, MSG_PEEK);
-
- if (num > 0)
- {
- OnStateChange(wxSOCKET_INPUT);
- }
- else
- {
- if (m_server && m_stream)
- {
- OnStateChange(wxSOCKET_CONNECTION);
- }
- else if (num == 0)
+ wxASSERT_MSG( m_fd != INVALID_SOCKET, "invalid socket ready for reading?" );
+
+ // we need to disable the read notifications until we read all the data
+ // already available for the socket, otherwise we're going to keep getting
+ // them continuously which is worse than inefficient: as IO notifications
+ // have higher priority than idle events in e.g. GTK+, our pending events
+ // whose handlers typically call Read() which would consume the data and so
+ // stop the notifications flood would never be dispatched at all if the
+ // notifications were not disabled
+ DisableEvents(wxSOCKET_INPUT_FLAG);
+
+
+ // find out what are we going to notify about exactly
+ wxSocketNotify notify;
+
+ // TCP listening sockets become ready for reading when there is a pending
+ // connection
+ if ( m_server && m_stream )