mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-23 08:27:06 +00:00
Add endian-correctness to TCPSend&Rcv (parallel to the Launcher commit)
This commit is contained in:
@@ -12,7 +12,8 @@
|
|||||||
void TCPSend(Client*c,const std::string&Data){
|
void TCPSend(Client*c,const std::string&Data){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
if(c == nullptr)return;
|
if(c == nullptr)return;
|
||||||
auto Size = int32_t(Data.size());
|
// Size is BIG ENDIAN now, use only for header!
|
||||||
|
auto Size = htonl(int32_t(Data.size()));
|
||||||
std::string Send(4,0);
|
std::string Send(4,0);
|
||||||
memcpy(&Send[0],&Size,sizeof(Size));
|
memcpy(&Send[0],&Size,sizeof(Size));
|
||||||
Send += Data;
|
Send += Data;
|
||||||
@@ -61,6 +62,8 @@ void TCPRcv(Client*c){
|
|||||||
#else
|
#else
|
||||||
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<void*>(&Header), sizeof(Header), 0);
|
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<void*>(&Header), sizeof(Header), 0);
|
||||||
#endif
|
#endif
|
||||||
|
// convert back to host endianness
|
||||||
|
Header = ntohl(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."));
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user