|
@@ -75,47 +75,47 @@ struct PacketReader : LoadFilter {
|
|
|
if (to_write == in_packet) return;
|
|
|
|
|
|
/* Allocate a new chunk and add the remaining data. */
|
|
|
pbuf += to_write;
|
|
|
to_write = in_packet - to_write;
|
|
|
this->buf = *this->blocks.Append() = CallocT<byte>(CHUNK);
|
|
|
this->bufe = this->buf + CHUNK;
|
|
|
|
|
|
memcpy(this->buf, pbuf, to_write);
|
|
|
this->buf += to_write;
|
|
|
}
|
|
|
|
|
|
/* virtual */ size_t Read(byte *rbuf, size_t size)
|
|
|
size_t Read(byte *rbuf, size_t size) override
|
|
|
{
|
|
|
/* Limit the amount to read to whatever we still have. */
|
|
|
size_t ret_size = size = min(this->written_bytes - this->read_bytes, size);
|
|
|
this->read_bytes += ret_size;
|
|
|
const byte *rbufe = rbuf + ret_size;
|
|
|
|
|
|
while (rbuf != rbufe) {
|
|
|
if (this->buf == this->bufe) {
|
|
|
this->buf = *this->block++;
|
|
|
this->bufe = this->buf + CHUNK;
|
|
|
}
|
|
|
|
|
|
size_t to_write = min(this->bufe - this->buf, rbufe - rbuf);
|
|
|
memcpy(rbuf, this->buf, to_write);
|
|
|
rbuf += to_write;
|
|
|
this->buf += to_write;
|
|
|
}
|
|
|
|
|
|
return ret_size;
|
|
|
}
|
|
|
|
|
|
/* virtual */ void Reset()
|
|
|
void Reset() override
|
|
|
{
|
|
|
this->read_bytes = 0;
|
|
|
|
|
|
this->block = this->blocks.Begin();
|
|
|
this->buf = *this->block++;
|
|
|
this->bufe = this->buf + CHUNK;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Create an emergency savegame when the network connection is lost.
|