mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-04 00:47:23 +00:00
- remove unused atomic_queue module
- change network error message format to (MESSAGE) - (ID) (Origin)
This commit is contained in:
parent
cc1c0d4a48
commit
ee28f963da
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -10,6 +10,3 @@
|
|||||||
[submodule "include/easyloggingpp"]
|
[submodule "include/easyloggingpp"]
|
||||||
path = include/easyloggingpp
|
path = include/easyloggingpp
|
||||||
url = https://github.com/amrayn/easyloggingpp.git
|
url = https://github.com/amrayn/easyloggingpp.git
|
||||||
[submodule "include/atomic_queue"]
|
|
||||||
path = include/atomic_queue
|
|
||||||
url = https://github.com/max0x7ba/atomic_queue.git
|
|
||||||
|
@ -31,14 +31,14 @@ void Server::TCPClientMain() {
|
|||||||
SOCKADDR_IN ServerAddr;
|
SOCKADDR_IN ServerAddr;
|
||||||
TCPSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
TCPSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (TCPSocket == -1) {
|
if (TCPSocket == -1) {
|
||||||
LOG(ERROR) << "Socket failed! Error code: " << GetSocketApiError();
|
LOG(ERROR) << GetSocketApiError() << " TCP Socket";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char optval = 0;
|
const char optval = 0;
|
||||||
int status = ::setsockopt(TCPSocket, SOL_SOCKET, SO_DONTLINGER, &optval,
|
int status = ::setsockopt(TCPSocket, SOL_SOCKET, SO_DONTLINGER, &optval,
|
||||||
sizeof(optval));
|
sizeof(optval));
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
LOG(INFO) << "Failed to set DONTLINGER: " << GetSocketApiError();
|
LOG(INFO) << GetSocketApiError() << " TCP DONTLINGER";
|
||||||
}
|
}
|
||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(Port);
|
ServerAddr.sin_port = htons(Port);
|
||||||
@ -46,7 +46,7 @@ void Server::TCPClientMain() {
|
|||||||
status = connect(TCPSocket, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr));
|
status = connect(TCPSocket, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr));
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
UStatus = "Connection Failed!";
|
UStatus = "Connection Failed!";
|
||||||
LOG(ERROR) << "Connect failed! Error code: " << GetSocketApiError();
|
LOG(ERROR) << GetSocketApiError() << " TCP Connect";
|
||||||
Terminate.store(true);
|
Terminate.store(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ void Server::TCPClientMain() {
|
|||||||
|
|
||||||
void Server::StartUDP() {
|
void Server::StartUDP() {
|
||||||
if (TCPConnection.joinable() && !UDPConnection.joinable()) {
|
if (TCPConnection.joinable() && !UDPConnection.joinable()) {
|
||||||
LOG(INFO) << "Connecting UDP";
|
LOG(INFO) << "Starting UDP";
|
||||||
UDPConnection = std::thread(&Server::UDPMain, this);
|
UDPConnection = std::thread(&Server::UDPMain, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ void Server::UDPSend(std::string Data) {
|
|||||||
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0,
|
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0,
|
||||||
(sockaddr*)UDPSockAddress.get(), sizeof(sockaddr_in));
|
(sockaddr*)UDPSockAddress.get(), sizeof(sockaddr_in));
|
||||||
if (sendOk == SOCKET_ERROR)
|
if (sendOk == SOCKET_ERROR)
|
||||||
LOG(ERROR) << "UDP Socket Error Code : " << GetSocketApiError();
|
LOG(ERROR) << GetSocketApiError() << " UDP Send";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::UDPParser(std::string Packet) {
|
void Server::UDPParser(std::string Packet) {
|
||||||
@ -100,7 +100,10 @@ void Server::UDPRcv() {
|
|||||||
if (UDPSocket == -1) return;
|
if (UDPSocket == -1) return;
|
||||||
int32_t Rcv = recvfrom(UDPSocket, &Ret[0], 10240, 0, (sockaddr*)&FromServer,
|
int32_t Rcv = recvfrom(UDPSocket, &Ret[0], 10240, 0, (sockaddr*)&FromServer,
|
||||||
&clientLength);
|
&clientLength);
|
||||||
if (Rcv == SOCKET_ERROR) return;
|
if (Rcv == SOCKET_ERROR) {
|
||||||
|
LOG(ERROR) << GetSocketApiError() << " UDP Rcv";
|
||||||
|
return;
|
||||||
|
}
|
||||||
UDPParser(Ret.substr(0, Rcv));
|
UDPParser(Ret.substr(0, Rcv));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +158,7 @@ void Server::SendLarge(std::string Data) {
|
|||||||
|
|
||||||
std::string Server::GetSocketApiError() {
|
std::string Server::GetSocketApiError() {
|
||||||
// This will provide us with the error code and an error message, all in one.
|
// This will provide us with the error code and an error message, all in one.
|
||||||
// The resulting format is "<CODE> - <MESSAGE>"
|
// The resulting format is "<MESSAGE> - <CODE>"
|
||||||
int err;
|
int err;
|
||||||
char msgbuf[256];
|
char msgbuf[256];
|
||||||
msgbuf[0] = '\0';
|
msgbuf[0] = '\0';
|
||||||
@ -167,7 +170,7 @@ std::string Server::GetSocketApiError() {
|
|||||||
msgbuf, sizeof(msgbuf), nullptr);
|
msgbuf, sizeof(msgbuf), nullptr);
|
||||||
|
|
||||||
if (*msgbuf) {
|
if (*msgbuf) {
|
||||||
return std::to_string(WSAGetLastError()) + " - " + std::string(msgbuf);
|
return std::string(msgbuf) + " - " + std::to_string(WSAGetLastError());
|
||||||
} else {
|
} else {
|
||||||
return std::to_string(WSAGetLastError());
|
return std::to_string(WSAGetLastError());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user