mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-09-27 09:23:21 +03:00
misc: fix minor bugs (#906)
## Link to GitHub Issue or related Pull Request, if one exists n/a ## Description of change Fix hang when a DLL using the SDK calls `log_fatal` (deadlock) Fix spicecfg crashing if API server fails to bind (make websocket teardown conditional) ## Testing
This commit is contained in:
@@ -93,6 +93,7 @@ Controller::Controller(unsigned short port, std::string password, bool pretty)
|
||||
// bind socket to address
|
||||
if (bind(this->server, (sockaddr *) &server_address, sizeof(sockaddr)) == -1) {
|
||||
log_warning("api", "could not bind socket on port {}: {}", port, get_last_error_string());
|
||||
closesocket(this->server);
|
||||
this->server = INVALID_SOCKET;
|
||||
if (!cfg::CONFIGURATOR_STANDALONE) {
|
||||
log_fatal("api", "failed to start server");
|
||||
@@ -103,6 +104,7 @@ Controller::Controller(unsigned short port, std::string password, bool pretty)
|
||||
// set socket to listen
|
||||
if (listen(this->server, server_backlog) == -1) {
|
||||
log_warning("api", "could not listen to socket on port {}: {}", port, get_last_error_string());
|
||||
closesocket(this->server);
|
||||
this->server = INVALID_SOCKET;
|
||||
if (!cfg::CONFIGURATOR_STANDALONE) {
|
||||
log_fatal("api", "failed to start server");
|
||||
@@ -446,7 +448,9 @@ void Controller::free_socket() {
|
||||
this->server = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
this->websocket->free_socket();
|
||||
if (this->websocket) {
|
||||
this->websocket->free_socket();
|
||||
}
|
||||
|
||||
for (auto &s : this->serial) {
|
||||
s->free_port();
|
||||
|
||||
@@ -41,21 +41,21 @@ namespace api {
|
||||
bool pretty;
|
||||
|
||||
// server
|
||||
WebSocketController *websocket;
|
||||
WebSocketController *websocket = nullptr;
|
||||
std::vector<SerialController *> serial;
|
||||
std::vector<std::thread> server_workers;
|
||||
std::vector<std::thread> server_handlers;
|
||||
std::mutex server_handlers_m;
|
||||
std::vector<api::ClientState *> client_states;
|
||||
std::mutex client_states_m;
|
||||
SOCKET server;
|
||||
SOCKET server = INVALID_SOCKET;
|
||||
void server_worker();
|
||||
void connection_handler(ClientState client_state);
|
||||
|
||||
public:
|
||||
|
||||
// state
|
||||
bool server_running;
|
||||
bool server_running = false;
|
||||
|
||||
// constructor / destructor
|
||||
Controller(unsigned short port, std::string password, bool pretty);
|
||||
|
||||
@@ -225,6 +225,7 @@ sdk_log(
|
||||
log_warning(facility_str.c_str(), "{}", message);
|
||||
break;
|
||||
case SPICE_SDK_LOG_LEVEL_FATAL:
|
||||
lock.unlock();
|
||||
log_fatal(facility_str.c_str(), "{}", message);
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user