+ int total;
+ int ret = 1;
+
+ // we try this even if the connection has already been closed.
+ total = GetPushback(buffer, nbytes, FALSE);
+ nbytes -= total;
+ buffer += total;
+
+ // If the socket is not connected, or we have got the whole
+ // needed buffer, return immedately
+ if (!m_socket || !m_connected || !nbytes)
+ return total;
+
+ // Possible combinations (they are checked in this order)
+ // wxSOCKET_NOWAIT
+ // wxSOCKET_WAITALL | wxSOCKET_BLOCK
+ // wxSOCKET_WAITALL
+ // wxSOCKET_BLOCK
+ // wxSOCKET_NONE
+ //
+ if (m_flags & wxSOCKET_NOWAIT)
+ {
+ GSocket_SetNonBlocking(m_socket, TRUE);
+ ret = GSocket_Read(m_socket, buffer, nbytes);
+ GSocket_SetNonBlocking(m_socket, FALSE);
+
+ if (ret > 0)
+ total += ret;
+ }
+ else if (m_flags & wxSOCKET_WAITALL)
+ {
+ while (ret > 0 && nbytes > 0)
+ {
+ if (!(m_flags & wxSOCKET_BLOCK) && !WaitForRead())
+ break;
+
+ ret = GSocket_Read(m_socket, buffer, nbytes);
+
+ if (ret > 0)
+ {
+ total += ret;
+ buffer += ret;
+ nbytes -= ret;
+ }
+ }
+ }
+ else
+ {
+ if ((m_flags & wxSOCKET_BLOCK) || WaitForRead())
+ {
+ ret = GSocket_Read(m_socket, buffer, nbytes);
+
+ if (ret > 0)
+ total += ret;
+ }
+ }
+
+ return total;
+}
+
+wxSocketBase& wxSocketBase::ReadMsg(char* buffer, wxUint32 nbytes)
+{
+ wxUint32 len, len2, sig, total;
+ bool error;
+ int old_flags;
+ struct
+ {
+ unsigned char sig[4];
+ unsigned char len[4];