+ char *buffer = new char[MAX_DISCARD_SIZE];
+ wxUint32 ret;
+ wxUint32 total = 0;
+
+ // Mask read events
+ m_reading = true;
+
+ const int old_flags = m_flags;
+ SetFlags(wxSOCKET_NOWAIT);
+
+ do
+ {
+ ret = DoRead(buffer, MAX_DISCARD_SIZE);
+ total += ret;
+ }
+ while (ret == MAX_DISCARD_SIZE);
+
+ delete[] buffer;
+ m_lcount = total;
+ SetError(wxSOCKET_NOERROR);
+
+ // Allow read events again
+ m_reading = false;
+
+ SetFlags(old_flags);
+
+ return *this;
+}
+
+// --------------------------------------------------------------------------
+// Wait functions
+// --------------------------------------------------------------------------
+
+/*
+ This function will check for the events specified in the flags parameter,
+ and it will return a mask indicating which operations can be performed.
+ */
+wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags,
+ const timeval *timeout)
+{
+ if ( m_fd == INVALID_SOCKET )
+ return (wxSOCKET_LOST_FLAG & flags);
+
+ struct timeval tv;
+ if ( timeout )
+ tv = *timeout;
+ else
+ tv.tv_sec = tv.tv_usec = 0;
+
+ // prepare the FD sets, passing NULL for the one(s) we don't use
+ fd_set
+ readfds, *preadfds = NULL,
+ writefds, *pwritefds = NULL,
+ exceptfds; // always want to know about errors
+
+ if ( flags & wxSOCKET_INPUT_FLAG )
+ {
+ preadfds = &readfds;
+ wxFD_ZERO(preadfds);
+ wxFD_SET(m_fd, preadfds);
+ }
+
+ // when using non-blocking connect() the socket becomes connected
+ // (successfully or not) when it becomes writable
+ if ( flags & (wxSOCKET_OUTPUT_FLAG | wxSOCKET_CONNECTION_FLAG) )
+ {
+ pwritefds = &writefds;
+ wxFD_ZERO(pwritefds);
+ wxFD_SET(m_fd, pwritefds);
+ }
+
+ wxFD_ZERO(&exceptfds);
+ wxFD_SET(m_fd, &exceptfds);
+
+ const int rc = select(m_fd + 1, preadfds, pwritefds, &exceptfds, &tv);
+
+ // check for errors first
+ if ( rc == -1 || wxFD_ISSET(m_fd, &exceptfds) )
+ {
+ m_establishing = false;