+wxSocketBase& wxSocketBase::WriteMsg(const char *buffer, wxUint32 nbytes)
+{
+ wxUint32 total;
+ bool error;
+ int old_flags;
+ struct {
+ unsigned char sig[4];
+ unsigned char len[4];
+ } msg;
+
+ // Mask write events
+ m_writing = TRUE;
+
+ error = TRUE;
+ total = 0;
+ old_flags = m_flags;
+ SetFlags((m_flags & SPEED) | WAITALL);
+
+ // warning about 'cast truncates constant value'
+#ifdef __VISUALC__
+# pragma warning(disable: 4310)
+#endif // __VISUALC__
+
+ msg.sig[0] = (unsigned char) 0xad;
+ msg.sig[1] = (unsigned char) 0xde;
+ msg.sig[2] = (unsigned char) 0xed;
+ msg.sig[3] = (unsigned char) 0xfe;
+
+ msg.len[0] = (unsigned char) nbytes & 0xff;
+ msg.len[1] = (unsigned char) (nbytes >> 8) & 0xff;
+ msg.len[2] = (unsigned char) (nbytes >> 16) & 0xff;
+ msg.len[3] = (unsigned char) (nbytes >> 24) & 0xff;
+
+ //wxLogMessage("Writemsg: %d %d %d %d -> %d",
+ // nbytes & 0xff,
+ // (nbytes >> 8) & 0xff,
+ // (nbytes >> 16) & 0xff,
+ // (nbytes >> 24) & 0xff,
+ // nbytes
+ // );
+
+ if (_Write((char *)&msg, sizeof(msg)) < sizeof(msg))
+ goto exit;
+
+ total = _Write(buffer, nbytes);
+
+ if (total < nbytes)
+ goto exit;
+
+ msg.sig[0] = (unsigned char) 0xed;
+ msg.sig[1] = (unsigned char) 0xfe;
+ msg.sig[2] = (unsigned char) 0xad;
+ msg.sig[3] = (unsigned char) 0xde;
+ msg.len[0] = msg.len[1] = msg.len[2] = msg.len[3] = (char) 0;
+
+ if ((_Write((char *)&msg, sizeof(msg))) < sizeof(msg))
+ goto exit;
+
+ // everything was OK
+ error = FALSE;
+
+exit:
+ m_error = error;
+ m_lcount = total;
+ m_writing = FALSE;
+
+ // TODO: TriggerWrite
+ return *this;
+
+#ifdef __VISUALC__
+# pragma warning(default: 4310)
+#endif // __VISUALC__
+}
+
+wxSocketBase& wxSocketBase::Unread(const char *buffer, wxUint32 nbytes)
+{
+ if (nbytes != 0)
+ Pushback(buffer, nbytes);
+
+ m_error = FALSE;
+ m_lcount = nbytes;
+
+ return *this;
+}
+
+void wxSocketBase::DoDefer()
+{
+ int ret;
+
+ if (!m_defer_buffer)
+ return;
+
+ switch(m_defering)
+ {
+ case DEFER_READ:
+ ret = GSocket_Read(m_socket, m_defer_buffer, m_defer_nbytes);
+ break;
+ case DEFER_WRITE:
+ ret = GSocket_Write(m_socket, m_defer_buffer, m_defer_nbytes);
+ break;
+ default:
+ ret = -1;
+ }
+
+ if (ret >= 0)
+ m_defer_nbytes -= ret;
+
+ // If we are waiting for all bytes to be acquired, keep the defering
+ // mode enabled.
+ if (!(m_flags & WAITALL) || !m_defer_nbytes || ret < 0)
+ {
+ m_defer_buffer = NULL;
+ }
+ else
+ {
+ m_defer_buffer += ret;
+ m_defer_timer->Start(m_timeout * 1000, FALSE);
+ }
+
+ //wxLogMessage("DoDefer ha transferido %d bytes", ret);
+}
+
+wxSocketBase& wxSocketBase::Discard()