mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-14 07:35:12 +01:00
Correct handling of data > 4096 bytes. This is for example sent out as
screenshots when multiple servers are waiting on the frodo network
This commit is contained in:
parent
bb3fbc0fb2
commit
914bcd03ba
@ -552,6 +552,7 @@ bool Network::ReceiveUpdate(NetworkUpdate *dst, size_t total_sz,
|
|||||||
{
|
{
|
||||||
Uint8 *p = (Uint8*)dst;
|
Uint8 *p = (Uint8*)dst;
|
||||||
size_t sz_left = total_sz;
|
size_t sz_left = total_sz;
|
||||||
|
size_t received = 0;
|
||||||
bool has_stop = false;
|
bool has_stop = false;
|
||||||
|
|
||||||
if (this->Select(this->sock, tv) == false)
|
if (this->Select(this->sock, tv) == false)
|
||||||
@ -562,20 +563,24 @@ bool Network::ReceiveUpdate(NetworkUpdate *dst, size_t total_sz,
|
|||||||
|
|
||||||
/* Receive the header */
|
/* Receive the header */
|
||||||
do {
|
do {
|
||||||
size_t actual_sz = this->ReceiveFrom(p, this->sock,
|
ssize_t actual_sz = this->ReceiveFrom(p, this->sock,
|
||||||
4096, NULL);
|
4096, NULL);
|
||||||
if (actual_sz <= 0)
|
if (actual_sz <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (this->DeMarshalAllData((NetworkUpdate*)p, actual_sz,
|
received += actual_sz;
|
||||||
&has_stop) == false) {
|
if (this->ScanDataForStop(dst, received) == true)
|
||||||
printf("Demarshal error\n");
|
break;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
sz_left -= actual_sz;
|
sz_left -= actual_sz;
|
||||||
p = p + actual_sz;
|
p = p + actual_sz;
|
||||||
} while (!has_stop);
|
} while (!has_stop);
|
||||||
|
|
||||||
|
if (this->DeMarshalAllData(dst, received) == false) {
|
||||||
|
printf("Demarshal error\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -822,8 +827,7 @@ bool Network::DeMarshalData(NetworkUpdate *p)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Network::DeMarshalAllData(NetworkUpdate *ud, size_t max_size,
|
bool Network::DeMarshalAllData(NetworkUpdate *ud, size_t max_size)
|
||||||
bool *has_stop)
|
|
||||||
{
|
{
|
||||||
NetworkUpdate *p = ud;
|
NetworkUpdate *p = ud;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
@ -839,11 +843,28 @@ bool Network::DeMarshalAllData(NetworkUpdate *ud, size_t max_size,
|
|||||||
p = this->GetNext(p);
|
p = this->GetNext(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The stop tag (maybe) */
|
|
||||||
*has_stop = (ntohs(p->type) == STOP);
|
|
||||||
return this->DeMarshalData(p);
|
return this->DeMarshalData(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Network::ScanDataForStop(NetworkUpdate *ud, size_t max_size)
|
||||||
|
{
|
||||||
|
NetworkUpdate *p = ud;
|
||||||
|
size_t sz = 0;
|
||||||
|
|
||||||
|
while (ntohs(p->type) != STOP &&
|
||||||
|
sz + ntohl(p->size) < max_size)
|
||||||
|
{
|
||||||
|
size_t cur_sz = ntohl(p->size);
|
||||||
|
|
||||||
|
sz += cur_sz;
|
||||||
|
p = (NetworkUpdate*)((Uint8*)p + cur_sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The stop tag (maybe) */
|
||||||
|
return ntohs(p->type) == STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst)
|
bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst)
|
||||||
{
|
{
|
||||||
NetworkUpdate *p = this->ud;
|
NetworkUpdate *p = this->ud;
|
||||||
|
@ -311,11 +311,12 @@ protected:
|
|||||||
|
|
||||||
bool MarshalAllData(NetworkUpdate *p);
|
bool MarshalAllData(NetworkUpdate *p);
|
||||||
|
|
||||||
bool DeMarshalAllData(NetworkUpdate *ud, size_t max_size,
|
bool DeMarshalAllData(NetworkUpdate *ud, size_t max_size);
|
||||||
bool *has_stop);
|
|
||||||
|
|
||||||
bool DeMarshalData(NetworkUpdate *ud);
|
bool DeMarshalData(NetworkUpdate *ud);
|
||||||
|
|
||||||
|
bool ScanDataForStop(NetworkUpdate *ud, size_t max_size);
|
||||||
|
|
||||||
bool ConnectToBroker();
|
bool ConnectToBroker();
|
||||||
|
|
||||||
bool ConnectToPeer();
|
bool ConnectToPeer();
|
||||||
|
Loading…
Reference in New Issue
Block a user