mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2025-08-18 12:45:36 +00:00
TCP header fix
This commit is contained in:
parent
8e9bf46778
commit
b663563f01
@ -57,13 +57,21 @@ bool CheckBytes(Client*c,int32_t BytesRcv){
|
|||||||
|
|
||||||
void TCPRcv(Client*c){
|
void TCPRcv(Client*c){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
int32_t Header,BytesRcv,Temp;
|
int32_t Header,BytesRcv = 0,Temp;
|
||||||
if(c == nullptr || c->GetStatus() < 0)return;
|
if(c == nullptr || c->GetStatus() < 0)return;
|
||||||
#ifdef WIN32
|
|
||||||
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
std::vector<char> Data(sizeof(Header));
|
||||||
#else
|
do {
|
||||||
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<void*>(&Header), sizeof(Header), 0);
|
Temp = recv(c->GetTCPSock(), &Data[BytesRcv], 4-BytesRcv, 0);
|
||||||
#endif
|
if(!CheckBytes(c,Temp)){
|
||||||
|
#ifdef DEBUG
|
||||||
|
error(std::string(__func__) + Sec(": failed on CheckBytes in while(BytesRcv < 4)"));
|
||||||
|
#endif // DEBUG
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BytesRcv += Temp;
|
||||||
|
}while(BytesRcv < sizeof(Header));
|
||||||
|
memcpy(&Header,&Data[0],sizeof(Header));
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
//debug(std::string(__func__) + Sec(": expecting ") + std::to_string(Header) + Sec(" bytes."));
|
//debug(std::string(__func__) + Sec(": expecting ") + std::to_string(Header) + Sec(" bytes."));
|
||||||
@ -74,8 +82,7 @@ void TCPRcv(Client*c){
|
|||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: std::vector
|
Data.resize(Header);
|
||||||
std::vector<char> Data(Header);
|
|
||||||
BytesRcv = 0;
|
BytesRcv = 0;
|
||||||
do{
|
do{
|
||||||
Temp = recv(c->GetTCPSock(), &Data[BytesRcv], Header-BytesRcv,0);
|
Temp = recv(c->GetTCPSock(), &Data[BytesRcv], Header-BytesRcv,0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user