+ 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_connected || !m_socket || !nbytes)
+ return total;
+
+ // Possible combinations (they are checked in this order)
+ // NOWAIT
+ // SPEED | WAITALL
+ // SPEED
+ // WAITALL
+ // NONE
+ //
+ if (m_flags & NOWAIT) // 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 & SPEED) && (m_flags & WAITALL)) // SPEED, WAITALL
+ {
+ while (ret > 0 && nbytes > 0)
+ {
+ ret = GSocket_Read(m_socket, buffer, nbytes);
+ total += ret;
+ buffer += ret;
+ nbytes -= ret;
+ }
+ // In case the last call was an error ...
+ if (ret < 0)
+ total++;
+ }
+ else if (m_flags & SPEED) // SPEED, !WAITALL
+ {
+ ret = GSocket_Read(m_socket, buffer, nbytes);
+
+ if (ret > 0)
+ total += ret;
+ }
+ else // NONE or WAITALL
+ {
+ ret = DeferRead(buffer, nbytes);
+
+ if (ret > 0)
+ total += ret;
+ }
+
+ return total;
+}
+
+wxSocketBase& wxSocketBase::ReadMsg(char* buffer, wxUint32 nbytes)
+{
+#define MAX_DISCARD_SIZE (10 * 1024)
+
+ wxUint32 len, len2, sig, total;
+ bool error;
+ int old_flags;
+ struct
+ {
+ unsigned char sig[4];
+ unsigned char len[4];