Make server ignore if client closed connection

This commit is contained in:
Night Kaly 2024-09-20 18:24:01 +01:00
parent 68f5fd5f7c
commit c57ba8d2ec
Signed by: night0721
GPG key ID: 957D67B8DB7A119B

View file

@ -69,10 +69,12 @@ int authenticate_client(int clientfd, uint8_t *username)
return ZSM_STA_SUCCESS; return ZSM_STA_SUCCESS;
} }
failure:; failure:;
/*
packet_t *error_pkt = create_packet(ZSM_STA_UNAUTHORISED, ZSM_TYP_ERROR, packet_t *error_pkt = create_packet(ZSM_STA_UNAUTHORISED, ZSM_TYP_ERROR,
0, NULL, create_signature(NULL, 0, NULL)); 0, NULL, create_signature(NULL, 0, NULL));
send_packet(error_pkt, clientfd); send_packet(error_pkt, clientfd);
free_packet(error_pkt); free_packet(error_pkt);
*/
close(clientfd); close(clientfd);
return ZSM_STA_ERROR_AUTHENTICATE; return ZSM_STA_ERROR_AUTHENTICATE;
} }
@ -124,9 +126,16 @@ void *thread_worker(void *arg)
if (events[i].events & EPOLLIN) { if (events[i].events & EPOLLIN) {
/* Handle packet */ /* Handle packet */
packet_t pkt; packet_t pkt;
if (verify_packet(&pkt, client->fd) == 0) { int status = verify_packet(&pkt, client->fd);
if (status != ZSM_STA_SUCCESS) {
if (status == ZSM_STA_CLOSED_CONNECTION) {
/* TODO: Remove client from thread */
error(0, "Client closed connection");
} else {
error(0, "Error verifying packet"); error(0, "Error verifying packet");
} }
continue;
}
/* Message relay */ /* Message relay */
uint8_t to[MAX_NAME]; uint8_t to[MAX_NAME];