+ // Mask write events
+ m_writing = true;
+
+ m_lcount = DoWrite(buffer, nbytes);
+
+ // If in wxSOCKET_WAITALL mode, all bytes should have been written.
+ if (m_flags & wxSOCKET_WAITALL)
+ m_error = (m_lcount != nbytes);
+ else
+ m_error = (m_lcount == 0);
+
+ // Allow write events again
+ m_writing = false;
+
+ return *this;
+}
+
+// This function is a mirror image of DoRead() except that it doesn't use the
+// push back buffer, please see comments there
+wxUint32 wxSocketBase::DoWrite(const void *buffer_, wxUint32 nbytes)
+{
+ const char *buffer = static_cast<const char *>(buffer_);
+
+ // Return if there is nothing to read or the socket is (already?) closed.
+ if ( !m_impl || !nbytes )
+ return 0;
+
+ wxCHECK_MSG( buffer, 0, "NULL buffer" );
+
+ wxUint32 total = 0;
+ if ( m_flags & wxSOCKET_NOWAIT )
+ {
+ wxSocketUnblocker unblock(m_impl);
+ const int ret = m_impl->Write(buffer, nbytes);
+ if ( ret > 0 )
+ total += ret;
+ }
+ else // blocking socket
+ {
+ for ( ;; )
+ {
+ if ( !(m_flags & wxSOCKET_BLOCK) && !WaitForWrite() )
+ break;
+
+ const int ret = m_impl->Write(buffer, nbytes);
+ if ( ret == 0 )
+ {
+ m_closed = true;
+ break;
+ }
+
+ if ( ret < 0 )
+ return 0;
+
+ total += ret;
+ if ( !(m_flags & wxSOCKET_WAITALL) )
+ break;
+
+ nbytes -= ret;
+ if ( !nbytes )
+ break;
+
+ buffer += ret;
+ }
+ }
+
+ return total;
+}
+
+wxSocketBase& wxSocketBase::WriteMsg(const void *buffer, wxUint32 nbytes)
+{
+ wxUint32 total;
+ bool error;
+ struct
+ {
+ unsigned char sig[4];
+ unsigned char len[4];
+ } msg;