feat: improved ServerNode scriptability
This commit is contained in:
parent
cfb901ec46
commit
6add0813d1
4 changed files with 42 additions and 18 deletions
|
|
@ -99,10 +99,10 @@ void receive_thread_entry() {
|
|||
}
|
||||
}
|
||||
|
||||
void open() {
|
||||
bool open() {
|
||||
if (service) {
|
||||
print_error("Server: Detected attempt to open duplicate Server, exiting without action.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
print_line("Server: Starting");
|
||||
service.emplace();
|
||||
|
|
@ -111,7 +111,7 @@ void open() {
|
|||
} catch (...) {
|
||||
service.reset();
|
||||
print_line("Server: Failed to create context");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
print_line("Server: Created zmq context");
|
||||
try {
|
||||
|
|
@ -121,7 +121,7 @@ void open() {
|
|||
service->context.reset();
|
||||
service.reset();
|
||||
print_line("Server: Failed to create socket");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
print_line("Server: Created socket");
|
||||
try {
|
||||
|
|
@ -133,12 +133,13 @@ void open() {
|
|||
service->context.reset();
|
||||
service.reset();
|
||||
print_line("Server: Failed to bind socket");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
print_line("Server: Bound socket");
|
||||
receive_thread.emplace(receive_thread_entry);
|
||||
assert(receive_thread->joinable());
|
||||
print_line("Server: Startup complete!");
|
||||
return true;
|
||||
}
|
||||
|
||||
void close() {
|
||||
|
|
@ -170,16 +171,22 @@ void close() {
|
|||
}
|
||||
|
||||
bool has_client() {
|
||||
if (service) {
|
||||
std::scoped_lock lock{ service->mtx };
|
||||
return service->client.has_value();
|
||||
} else {
|
||||
if (!service) {
|
||||
return false;
|
||||
}
|
||||
std::scoped_lock lock{ service->mtx };
|
||||
return service->client.has_value();
|
||||
}
|
||||
|
||||
bool is_running() {
|
||||
return service.has_value();
|
||||
}
|
||||
|
||||
namespace receive {
|
||||
bool new_clues(Vector<NetworkData::ClueID> &out) {
|
||||
if (!service) {
|
||||
return false;
|
||||
}
|
||||
std::scoped_lock lock{ service->mtx };
|
||||
bool const has_new{ !service->new_clues.is_empty() };
|
||||
if (has_new) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue