- /* Buffer is too small, enlarge it and copy contents */
- int old_bufsz = bufsz;
- unsigned char* temp = buffer;
-
- bufsz += data_length;
- buffer = new unsigned char[bufsz + 1];
-
- memcpy(buffer, temp, old_bufsz);
-
- delete[] temp;
- }
-
- memcpy(buffer + bufptr, data, data_length);
- bufptr += data_length;
- amount_read += data_length;
-
- if ((!amount_expected) && (amount_read >= 4))
- {
- /* We have enough to read an int */
- int* size = (int*)buffer;
- amount_expected = ntohl(*size);
+ /* We have enough to read an int -
+ * Yes, this is safe, but its ugly. Give me
+ * a nicer way to read 4 bytes from a binary
+ * stream, and push them into a 32 bit int,
+ * and i'll consider replacing this.
+ */
+ amount_expected = ntohl((buffer[3] << 24) | (buffer[2] << 16) | (buffer[1] << 8) | buffer[0]);
+ buffer = buffer.substr(4);