Fixed server crash
This commit is contained in:
parent
cbfd27b954
commit
004ec89f44
@ -204,8 +204,10 @@ void ConnectedClient::uninit(bool blocking) {
|
|||||||
network.fileDescriptor = 0;
|
network.fileDescriptor = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_lock elock{this->network.event_mutex};
|
||||||
auto read_event = std::exchange(this->network.readEvent, nullptr);
|
auto read_event = std::exchange(this->network.readEvent, nullptr);
|
||||||
auto write_event = std::exchange(this->network.writeEvent, nullptr);
|
auto write_event = std::exchange(this->network.writeEvent, nullptr);
|
||||||
|
elock.unlock();
|
||||||
|
|
||||||
if(blocking) {
|
if(blocking) {
|
||||||
if(read_event) event_del_block(read_event);
|
if(read_event) event_del_block(read_event);
|
||||||
@ -214,6 +216,8 @@ void ConnectedClient::uninit(bool blocking) {
|
|||||||
if(read_event) event_del_noblock(read_event);
|
if(read_event) event_del_noblock(read_event);
|
||||||
if(write_event) event_del_noblock(write_event);
|
if(write_event) event_del_noblock(write_event);
|
||||||
}
|
}
|
||||||
|
if(read_event) event_free(read_event);
|
||||||
|
if(write_event) event_free(write_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LicenseServer::handleEventRead(int fd, short, void* ptrServer) {
|
void LicenseServer::handleEventRead(int fd, short, void* ptrServer) {
|
||||||
@ -229,12 +233,20 @@ void LicenseServer::handleEventRead(int fd, short, void* ptrServer) {
|
|||||||
if(read < 0){
|
if(read < 0){
|
||||||
if(errno == EWOULDBLOCK) return;
|
if(errno == EWOULDBLOCK) return;
|
||||||
logError(LOG_LICENSE_CONTROLL, "Invalid read. Disconnecting remote client. Message: {}/{}", errno, strerror(errno));
|
logError(LOG_LICENSE_CONTROLL, "Invalid read. Disconnecting remote client. Message: {}/{}", errno, strerror(errno));
|
||||||
|
{
|
||||||
|
std::lock_guard elock{client->network.event_mutex};
|
||||||
|
if(client->network.readEvent)
|
||||||
event_del_noblock(client->network.readEvent);
|
event_del_noblock(client->network.readEvent);
|
||||||
|
}
|
||||||
server->closeConnection(client);
|
server->closeConnection(client);
|
||||||
return;
|
return;
|
||||||
} else if(read == 0) {
|
} else if(read == 0) {
|
||||||
logMessage(LOG_LICENSE_CONTROLL, "[CLIENT][" + client->address() + "] Received EOF for client. Removing client.");
|
logMessage(LOG_LICENSE_CONTROLL, "[CLIENT][" + client->address() + "] Received EOF for client. Removing client.");
|
||||||
|
{
|
||||||
|
std::lock_guard elock{client->network.event_mutex};
|
||||||
|
if(client->network.readEvent)
|
||||||
event_del_noblock(client->network.readEvent);
|
event_del_noblock(client->network.readEvent);
|
||||||
|
}
|
||||||
server->closeConnection(client);
|
server->closeConnection(client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ namespace license {
|
|||||||
struct {
|
struct {
|
||||||
sockaddr_in remoteAddr;
|
sockaddr_in remoteAddr;
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
|
|
||||||
|
std::mutex event_mutex{};
|
||||||
event* readEvent = nullptr; /* protected via state_lock (check state and the use these variables) */
|
event* readEvent = nullptr; /* protected via state_lock (check state and the use these variables) */
|
||||||
event* writeEvent = nullptr;
|
event* writeEvent = nullptr;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user