mirror of
https://github.com/open-goal/jak-project.git
synced 2024-11-27 00:10:31 +00:00
a few small changes to fix tests
This commit is contained in:
parent
d1513bd06b
commit
e80a011a86
@ -3,6 +3,7 @@
|
||||
#include "third-party/fmt/core.h"
|
||||
|
||||
#include "common/cross_sockets/XSocket.h"
|
||||
#include "common/util/Assert.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define NOMINMAX
|
||||
@ -21,7 +22,9 @@ XSocketServer::XSocketServer(std::function<bool()> shutdown_callback,
|
||||
}
|
||||
|
||||
XSocketServer::~XSocketServer() {
|
||||
shutdown_server();
|
||||
if (listening_socket >= 0) {
|
||||
close_server_socket();
|
||||
}
|
||||
}
|
||||
|
||||
void XSocketServer::shutdown_server() {
|
||||
@ -81,6 +84,7 @@ bool XSocketServer::init_server() {
|
||||
}
|
||||
|
||||
void XSocketServer::close_server_socket() {
|
||||
ASSERT(listening_socket >= 0);
|
||||
close_socket(listening_socket);
|
||||
listening_socket = -1;
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ class XSocketServer {
|
||||
std::vector<char> buffer;
|
||||
|
||||
bool server_initialized = false;
|
||||
bool client_connected = false;
|
||||
|
||||
std::function<bool()> want_exit_callback;
|
||||
};
|
||||
|
@ -29,6 +29,7 @@ Deci2Server::~Deci2Server() {
|
||||
accept_thread.join();
|
||||
accept_thread_running = false;
|
||||
}
|
||||
|
||||
close_socket(accepted_socket);
|
||||
}
|
||||
|
||||
@ -42,15 +43,14 @@ void Deci2Server::post_init() {
|
||||
void Deci2Server::accept_thread_func() {
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
while (!kill_accept_thread) {
|
||||
if (accepted_socket == -1) {
|
||||
accepted_socket = accept_socket(listening_socket, (sockaddr*)&addr, &addr_len);
|
||||
accepted_socket = accept_socket(listening_socket, (sockaddr*)&addr, &addr_len);
|
||||
if (accepted_socket >= 0) {
|
||||
set_socket_timeout(accepted_socket, 100000);
|
||||
u32 versions[2] = {versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR};
|
||||
write_to_socket(accepted_socket, (char*)&versions, 8);
|
||||
write_to_socket(accepted_socket, (char*)&versions, 8); // todo, check result?
|
||||
client_connected = true;
|
||||
return; // stop accepting connections
|
||||
return;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(50000));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,5 +37,7 @@ class Deci2Server : public XSocketServer {
|
||||
std::thread accept_thread;
|
||||
std::mutex server_mutex;
|
||||
|
||||
bool client_connected = false;
|
||||
|
||||
void accept_thread_func();
|
||||
};
|
||||
|
@ -54,8 +54,11 @@ std::optional<std::string> ReplServer::get_msg() {
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for activity on _something_
|
||||
auto activity = select(max_sd + 1, &read_sockets, NULL, NULL, NULL);
|
||||
// Wait for activity on _something_, with a timeout so we don't get stuck here on exit.
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 100000;
|
||||
auto activity = select(max_sd + 1, &read_sockets, NULL, NULL, &timeout);
|
||||
|
||||
if (activity < 0) { // TODO - || error!
|
||||
return std::nullopt;
|
||||
|
Loading…
Reference in New Issue
Block a user