Commit 2f30f268 authored by Mathias Haage's avatar Mathias Haage

Correct nasty network bug from last year

parent 693f2f2a
......@@ -28,19 +28,20 @@ public class ClientReadThread extends Thread {
while (true) {
// Read header
int size = Pack.HEAD_SIZE;
int n = 0;
while ((n = is.read(buffer, n, size)) > 0) {
size -= n;
int n;
int bytesread = 0;
while ((n = is.read(buffer, bytesread, size - bytesread)) > 0) {
bytesread += n;
}
if (size != 0) break;
if (size != bytesread) break;
// Read payload
int bufsize = size = Pack.unpackHeaderSize(buffer);
n = 0;
while ((n = is.read(buffer, n+Pack.HEAD_SIZE, size)) > 0) {
size -= n;
bytesread = 0;
while ((n = is.read(buffer, bytesread + Pack.HEAD_SIZE, size - bytesread)) > 0) {
bytesread += n;
}
if (size != 0) break;
if (size != bytesread) break;
// Unpack payload and verify integrity
Utils.printBuffer("ClientReadThread", bufsize, buffer);
......
......@@ -27,19 +27,20 @@ public class ServerReadThread extends Thread {
while (true) {
// Read header
int size = Pack.HEAD_SIZE;
int n = 0;
while ((n = is.read(buffer, n, size)) > 0) {
size -= n;
int n;
int bytesread = 0;
while ((n = is.read(buffer, bytesread, size - bytesread)) > 0) {
bytesread += n;
}
if (size != 0) break;
if (size != bytesread) break;
// Read payload
int payloadSize = size = Pack.unpackHeaderSize(buffer);
n = 0;
while ((n = is.read(buffer, n+Pack.HEAD_SIZE, size)) > 0) {
size -= n;
bytesread = 0;
while ((n = is.read(buffer, bytesread + Pack.HEAD_SIZE, size - bytesread)) > 0) {
bytesread += n;
}
if (size != 0) break;
if (size != bytesread) break;
// Unpack payload and verify integrity
Utils.printBuffer("ServerReadThread", payloadSize, buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment