mirror of
https://github.com/open-goal/jak-project
synced 2026-05-31 01:16:12 -04:00
7b6d732a77
* goalc: cleanup goalc's main method and add nrepl listener socket * deps: add standalone ASIO for sockets * lint: formatting * common: make a common interface for creating a server socket * goalc: setup new repl server * deps: remove asio * goalc: debug issues, nrepl is working again * git: rename files * attempt to fix linux function call * test * scripts: make the error message even more obvious.... * goalc: make suggested changes, still can't reconnect properly * game: pull out single-client logic from XSocketServer * nrepl: supports multiple clients and disconnection/reconnects * goalc: some minor fixes for tests * goalc: save repl history when the compiler reloads * common: add include for linux networking * a few small changes to fix tests * is it the assert? * change thread start order and add a print to an assert Co-authored-by: water <awaterford111445@gmail.com>
39 lines
938 B
C++
39 lines
938 B
C++
#pragma once
|
|
|
|
#include "common/cross_sockets/XSocket.h"
|
|
|
|
#include <thread>
|
|
#include "common/common_types.h"
|
|
#include <functional>
|
|
#include <mutex>
|
|
|
|
/// @brief A cross platform generic socket server implementation
|
|
class XSocketServer {
|
|
public:
|
|
static constexpr int DEF_BUFFER_SIZE = 32 * 1024 * 1024;
|
|
XSocketServer(std::function<bool()> shutdown_callback,
|
|
int _tcp_port,
|
|
int _buffer_size = DEF_BUFFER_SIZE);
|
|
virtual ~XSocketServer();
|
|
|
|
XSocketServer(const XSocketServer&) = delete;
|
|
XSocketServer& operator=(const XSocketServer&) = delete;
|
|
|
|
bool init_server();
|
|
void shutdown_server();
|
|
void close_server_socket();
|
|
|
|
// Abstract methods -- use-case dependent
|
|
virtual void post_init() = 0;
|
|
|
|
protected:
|
|
int tcp_port;
|
|
struct sockaddr_in addr = {};
|
|
int listening_socket = -1;
|
|
std::vector<char> buffer;
|
|
|
|
bool server_initialized = false;
|
|
|
|
std::function<bool()> want_exit_callback;
|
|
};
|