Minor fixes

This commit is contained in:
Lion Kortlepel
2020-11-08 01:31:34 +01:00
parent fe6cfd027e
commit a42ab67d2f
3 changed files with 54 additions and 6 deletions

View File

@@ -54,24 +54,43 @@ bool CheckBytes(Client*c,int32_t BytesRcv){
void TCPRcv(Client*c){
Assert(c);
static int32_t Header,BytesRcv,Temp;
static thread_local int32_t Header,BytesRcv,Temp;
if(c == nullptr || c->GetStatus() < 0)return;
#ifdef WIN32
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<char*>(&Header), sizeof(Header),0);
#else
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<void*>(&Header), sizeof(Header), 0);
#endif
if(!CheckBytes(c,BytesRcv))return;
#ifdef DEBUG
//debug(std::string(__func__) + Sec(": expecting ") + std::to_string(Header) + Sec(" bytes."));
#endif // DEBUG
if(!CheckBytes(c,BytesRcv)) {
#ifdef DEBUG
error(std::string(__func__) + Sec(": failed on CheckBytes"));
#endif // DEBUG
return;
}
// TODO: std::vector
char* Data = new char[Header];
Assert(Data);
BytesRcv = 0;
do{
Temp = recv(c->GetTCPSock(), Data+BytesRcv, Header-BytesRcv,0);
if(!CheckBytes(c,Temp)){
#ifdef DEBUG
error(std::string(__func__) + Sec(": failed on CheckBytes in while(BytesRcv < Header)"));
#endif // DEBUG
delete[] Data;
return;
}
#ifdef DEBUG
//debug(std::string(__func__) + Sec(": Temp: ") + std::to_string(Temp) + Sec(", BytesRcv: ") + std::to_string(BytesRcv));
#endif // DEBUG
BytesRcv += Temp;
}while(BytesRcv < Header);
#ifdef DEBUG
//debug(std::string(__func__) + Sec(": finished recv with Temp: ") + std::to_string(Temp) + Sec(", BytesRcv: ") + std::to_string(BytesRcv));
#endif // DEBUG
std::string Ret = std::string(Data,Header);
delete[] Data;
if (Ret.substr(0, 4) == "ABG:") {