- size_t ret;
-
- ret = m_o_socket->Write((const char *)buffer, size).LastCount();
- switch (m_o_socket->LastError()) {
- case GSOCK_NOERROR:
- m_lasterror = wxStream_NOERROR;
- break;
- default:
- m_lasterror = wxStream_READ_ERR;
- break;
- }
- return ret;
-
+ const char *buf = (const char *)buffer;
+ size_t count = 0;
+
+ while ( count < size && m_o_socket->WaitForWrite() )
+ {
+ const size_t ret = m_o_socket->Write(buf, size - count).LastCount();
+
+ buf += ret;
+ count += ret;
+
+ if ( m_o_socket->Error() )
+ {
+ if (m_o_socket->LastError() != wxSOCKET_WOULDBLOCK)
+ {
+ m_lasterror = wxSTREAM_WRITE_ERROR;
+ return count;
+ }
+ }
+ }
+
+ m_lasterror = wxSTREAM_NO_ERROR;
+ return count;