- msg.sig[0] = (char) 0xad;
- msg.sig[1] = (char) 0xde;
- msg.sig[2] = (char) 0xed;
- msg.sig[3] = (char) 0xfe;
-
- msg.len[0] = (char) nbytes & 0xff;
- msg.len[1] = (char) (nbytes >> 8) & 0xff;
- msg.len[2] = (char) (nbytes >> 16) & 0xff;
- msg.len[3] = (char) (nbytes >> 24) & 0xff;
-
- if (Write((char *)&msg, sizeof(msg)).LastCount() < sizeof(msg))
- return *this;
- if (Write(buffer, nbytes).LastCount() < nbytes)
- return *this;
-
- msg.sig[0] = (char) 0xed;
- msg.sig[1] = (char) 0xfe;
- msg.sig[2] = (char) 0xad;
- msg.sig[3] = (char) 0xde;
+ 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;