Fix recv return type and better download error handling

This commit is contained in:
Tixx 2025-03-28 23:47:59 +01:00
parent ad7177bec8
commit 472e2d16b6
No known key found for this signature in database
GPG Key ID: EC6E7A2BAABF0B8C
4 changed files with 12 additions and 6 deletions

View File

@ -141,7 +141,7 @@ void GetServerInfo(std::string Data) {
const std::string buffer = ([&]() -> std::string {
int32_t Header;
std::vector<char> data(sizeof(Header));
int32_t Temp = recv(ISock, data.data(), sizeof(Header), MSG_WAITALL);
int Temp = recv(ISock, data.data(), sizeof(Header), MSG_WAITALL);
auto checkBytes = ([&](const int32_t bytes) -> bool {
if (bytes == 0) {
@ -352,7 +352,8 @@ void Parse(std::string Data, SOCKET CSocket) {
}
void GameHandler(SOCKET Client) {
CoreSocket = Client;
int32_t Size, Temp, Rcv;
int32_t Size, Rcv;
int Temp;
char Header[10] = { 0 };
do {
Rcv = 0;

View File

@ -262,7 +262,8 @@ void TCPGameServer(const std::string& IP, int Port) {
NetMainThread = std::make_unique<std::thread>(NetMain, IP, Port);
CServer = false;
}
int32_t Size, Temp, Rcv;
int32_t Size, Rcv;
int Temp;
char Header[10] = { 0 };
// Read byte by byte until '>' is rcved then get the size and read based on it

View File

@ -164,9 +164,12 @@ std::vector<char> TCPRcvRaw(SOCKET Sock, uint64_t& GRcv, uint64_t Size) {
do {
// receive at most some MB at a time
int Len = std::min(int(Size - Rcv), 1 * 1024 * 1024);
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
int Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
if (Temp < 1) {
info(std::to_string(Temp));
debug("Recv returned: " + std::to_string(Temp));
if (Temp == -1) {
error("Socket error during download: " + std::to_string(WSAGetLastError()));
}
UUl("Socket Closed Code 1");
KillSocket(Sock);
Terminate = true;

View File

@ -81,7 +81,8 @@ std::string TCPRcv(SOCKET Sock) {
UUl("Invalid Socket");
return "";
}
int32_t Header, Temp;
int32_t Header;
int Temp;
std::vector<char> Data(sizeof(Header));
Temp = recv(Sock, Data.data(), sizeof(Header), MSG_WAITALL);
if (!CheckBytes(Temp)) {