Implement various WIN32 fixes

This commit is contained in:
Lion Kortlepel 2020-11-03 12:50:05 +01:00
parent f144d451c7
commit c5c21c43ad
5 changed files with 48 additions and 28 deletions

View File

@ -44,23 +44,15 @@ inline void _assert([[maybe_unused]] const char* file, [[maybe_unused]] const ch
[[maybe_unused]] const char* condition_string, [[maybe_unused]] bool result) {
if (!result) {
#if DEBUG
std::stringstream ss;
ss << std::this_thread::get_id();
fprintf(stdout,
"(debug build) TID %s: %sASSERTION FAILED%s at %s%s:%u%s in \n\t-> in %s%s%s, Line %u: \n\t\t-> "
"Failed Condition: %s%s%s\n",
ss.str().c_str(), ANSI_RED_BOLD, ANSI_RESET, ANSI_UNDERLINE, file, line, ANSI_RESET,
ANSI_BOLD, function, ANSI_RESET, line, ANSI_RED, condition_string,
ANSI_RESET);
fprintf(stdout, "%s... terminating with SIGABRT ...%s\n", ANSI_BOLD, ANSI_RESET);
std::cout << std::flush << "(debug build) TID "
<< std::this_thread::get_id() << ": ASSERTION FAILED: at "
<< file << ":" << line << " \n\t-> in "
<< function << ", Line " << line << ": \n\t\t-> "
<< "Failed Condition: " << condition_string << std::endl;
std::cout << "... terminating ..." << std::endl;
abort();
#else
char buf[2048];
sprintf(buf,
"%s=> ASSERTION `%s` FAILED IN RELEASE BUILD%s%s -> IGNORING FAILED ASSERTION "
"& HOPING IT WON'T CRASH%s",
ANSI_RED_BOLD, condition_string, ANSI_RESET, ANSI_RED, ANSI_RESET);
error(buf);
std::cout << "Assertion '" << condition_string << "' failed, ignoring in release build" << std::endl;
#endif
}
}

View File

@ -17,8 +17,14 @@ struct Hold{
bool Done = false;
};
bool Send(SOCKET TCPSock,std::string Data){
ssize_t BytesSent;
BytesSent = send(TCPSock, Data.c_str(), size_t(Data.size()), 0);
#ifdef WIN32
int BytesSent;
int len = static_cast<int>(Data.size());
#else
int64_t BytesSent;
size_t len = Data.size();
#endif // WIN32
BytesSent = send(TCPSock, Data.c_str(), len, 0);
Data.clear();
if (BytesSent <= 0)return false;
return true;
@ -27,7 +33,7 @@ std::string Rcv(SOCKET TCPSock){
char buf[6768];
size_t len = 6768;
ZeroMemory(buf, len);
ssize_t BytesRcv = recv(TCPSock, buf, len,0);
int64_t BytesRcv = recv(TCPSock, buf, len,0);
if (BytesRcv <= 0)return "";
return std::string(buf);
}

View File

@ -17,7 +17,14 @@ void STCPSend(Client* c, std::string Data) {
Assert(c);
if (c == nullptr)
return;
ssize_t BytesSent = send(c->GetTCPSock(), Data.c_str(), size_t(Data.size()), 0);
#ifdef WIN32
int BytesSent;
int len = static_cast<int>(Data.size());
#else
int64_t BytesSent;
size_t len = Data.size();
#endif // WIN32
BytesSent = send(c->GetTCPSock(), Data.c_str(), len, 0);
Data.clear();
if (BytesSent == 0) {
if (c->GetStatus() > -1)
@ -42,19 +49,19 @@ void SendFile(Client* c, const std::string& Name) {
size_t Size = size_t(fileSize);
size_t Sent = 0;
size_t Diff;
ssize_t Split = 64000;
int64_t Split = 64000;
while (c->GetStatus() > -1 && Sent < Size) {
Diff = Size - Sent;
if (Diff > size_t(Split)) {
std::string Data(size_t(Split), 0);
f.seekg(ssize_t(Sent), std::ios_base::beg);
f.seekg(int64_t(Sent), std::ios_base::beg);
f.read(&Data[0], Split);
STCPSend(c, Data);
Sent += size_t(Split);
} else {
std::string Data(Diff, 0);
f.seekg(ssize_t(Sent), std::ios_base::beg);
f.read(&Data[0], ssize_t(Diff));
f.seekg(int64_t(Sent), std::ios_base::beg);
f.read(&Data[0], int64_t(Diff));
STCPSend(c, Data);
Sent += Diff;
}
@ -93,7 +100,7 @@ bool STCPRecv(Client* c) {
char buf[200];
size_t len = 200;
ZeroMemory(buf, len);
ssize_t BytesRcv = recv(c->GetTCPSock(), buf, len, 0);
int64_t BytesRcv = recv(c->GetTCPSock(), buf, len, 0);
if (BytesRcv == 0) {
if (c->GetStatus() > -1)
c->SetStatus(-1);

View File

@ -11,7 +11,14 @@ void TCPSend(Client*c,const std::string&Data){
Assert(c);
if(c == nullptr)return;
std::string Send = "\n" + Data.substr(0,Data.find(char(0))) + "\n";
ssize_t Sent = send(c->GetTCPSock(), Send.c_str(), size_t(Send.size()), 0);
#ifdef WIN32
int Sent;
int len = static_cast<int>(Send.size());
#else
int64_t Sent;
size_t len = Send.size();
#endif // WIN32
Sent = send(c->GetTCPSock(), Send.c_str(), len, 0);
if (Sent == 0){
if(c->GetStatus() > -1)c->SetStatus(-1);
}else if (Sent < 0) {
@ -37,7 +44,7 @@ void TCPRcv(Client*c){
char buf[4096];
size_t len = 4096;
ZeroMemory(buf, len);
ssize_t BytesRcv = recv(c->GetTCPSock(), buf, len,0);
int64_t BytesRcv = recv(c->GetTCPSock(), buf, len,0);
if (BytesRcv == 0){
debug(Sec("(TCP) Connection closing..."));
if(c->GetStatus() > -1)c->SetStatus(-1);

View File

@ -42,7 +42,15 @@ void UDPSend(Client* c, std::string Data) {
std::string CMP(Comp(Data));
Data = "ABG:" + CMP;
}
ssize_t sendOk = sendto(UDPSock, Data.c_str(), Data.size(), 0, (sockaddr*)&Addr, AddrSize);
#ifdef WIN32
int sendOk;
int len = static_cast<int>(Data.size());
#else
int64_t sendOk;
size_t len = Data.size();
#endif // WIN32
sendOk = sendto(UDPSock, Data.c_str(), len, 0, (sockaddr*)&Addr, AddrSize);
#ifdef WIN32
if (sendOk != 0) {
debug(Sec("(UDP) Send Failed Code : ") + std::to_string(WSAGetLastError()));
@ -166,7 +174,7 @@ std::string UDPRcvFromClient(sockaddr_in& client) {
size_t clientLength = sizeof(client);
ZeroMemory(&client, clientLength);
std::string Ret(10240, 0);
ssize_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&client, (socklen_t*)&clientLength);
int64_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&client, (socklen_t*)&clientLength);
if (Rcv == -1) {
#ifdef WIN32
error(Sec("(UDP) Error receiving from Client! Code : ") + std::to_string(WSAGetLastError()));