Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/openw3d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
--target
scripts
bandtest
scontrol
wwsaveload
wwmath
wwutil
Expand Down
23 changes: 14 additions & 9 deletions Code/SControl/servercontrolsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
#include "servercontrolsocket.h"
#include "systimer.h"
#include <algorithm>
#include <thread>

#ifdef _WIN32
typedef int socklen_t;
#endif

/*
** All instances are tracked here.
Expand Down Expand Up @@ -155,8 +160,8 @@ bool ServerControlSocketClass::Open(int port, bool loopback, unsigned int ip)
}

DebugString(("ServerControlSocketClass - About to bind the UDP socket to port %d\n", port));
if (bind (Socket, (LPSOCKADDR)&addr, sizeof(addr) ) == SOCKET_ERROR) {
DebugString(("ServerControlSocketClass - bind failed with error code %d\n", WSAGetLastError()));
if (bind (Socket, (sockaddr*)&addr, sizeof(addr) ) == SOCKET_ERROR) {
DebugString(("ServerControlSocketClass - bind failed with error code %d\n", LAST_ERROR));
Close();
return(false);
}
Expand Down Expand Up @@ -315,7 +320,7 @@ void ServerControlSocketClass::Discard_Out_Buffers(void)
void ServerControlSocketClass::Clear_Socket_Error(void)
{
unsigned int error_code;
int length = 4;
socklen_t length = sizeof(error_code);

if (Socket != INVALID_SOCKET) {
getsockopt (Socket, SOL_SOCKET, SO_ERROR, (char*)&error_code, &length);
Expand Down Expand Up @@ -733,7 +738,7 @@ void ServerControlSocketClass::Service(void)
{
u_long bytes;
struct sockaddr_in addr;
int addr_len;
socklen_t addr_len;
WinsockBufferType *packet;
int result;
unsigned int timeout_check = TIMEGETTIME();
Expand All @@ -748,7 +753,7 @@ void ServerControlSocketClass::Service(void)
break;
}
times++;
Sleep(0);
std::this_thread::yield();

/*
**
Expand Down Expand Up @@ -778,7 +783,7 @@ void ServerControlSocketClass::Service(void)
** Call recvfrom function to get the outstanding packet.
*/
addr_len = sizeof(addr);
result = recvfrom(Socket, (char*)ReceiveBuffer, sizeof(ReceiveBuffer), 0, (LPSOCKADDR)&addr, &addr_len);
result = recvfrom(Socket, (char*)ReceiveBuffer, sizeof(ReceiveBuffer), 0, (sockaddr*)&addr, &addr_len);

/*
** See if we got an error.
Expand Down Expand Up @@ -864,7 +869,7 @@ void ServerControlSocketClass::Service(void)
break;
}
times++;
Sleep(0);
std::this_thread::yield();

/*
** Get a pointer to the first packet.
Expand All @@ -888,7 +893,7 @@ void ServerControlSocketClass::Service(void)
/*
** Send it.
*/
result = sendto(Socket, ((char const *)packet->Buffer) - sizeof(packet->CRC), packet->BufferLen + sizeof(packet->CRC), 0, (LPSOCKADDR)&addr, sizeof (addr));
result = sendto(Socket, ((char const *)packet->Buffer) - sizeof(packet->CRC), packet->BufferLen + sizeof(packet->CRC), 0, (const sockaddr*)&addr, sizeof (addr));

if (result == SOCKET_ERROR){
if (LAST_ERROR != WSAEWOULDBLOCK) {
Expand All @@ -900,7 +905,7 @@ void ServerControlSocketClass::Service(void)
** No more room for outgoing packets.
*/
DebugString(("ServerControlSocketClass - sendto returned WSAEWOULDBLOCK\n"));
Sleep(0);
std::this_thread::yield();
}
break;
}
Expand Down
Loading