Improved cleanup on close
This commit is contained in:
parent
32be1bc25b
commit
7aace4e904
1 changed files with 14 additions and 14 deletions
28
server.c
28
server.c
|
@ -73,6 +73,19 @@ void load_slide_content(const char *slides_path, char *output) {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clean up client resources */
|
||||||
|
void cleanup_client(struct Client *client) {
|
||||||
|
if (client->fd != -1) {
|
||||||
|
close(client->fd);
|
||||||
|
client->fd = -1;
|
||||||
|
}
|
||||||
|
if (strlen(client->repo_path) > 0) {
|
||||||
|
char rm_command[CMD_SIZE];
|
||||||
|
snprintf(rm_command, sizeof(rm_command), "rm -rf %s", client->repo_path);
|
||||||
|
system(rm_command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Handle client input and update slides */
|
/* Handle client input and update slides */
|
||||||
void handle_client_input(struct Client *client, char command) {
|
void handle_client_input(struct Client *client, char command) {
|
||||||
if (command == ' ') {
|
if (command == ' ') {
|
||||||
|
@ -81,8 +94,7 @@ void handle_client_input(struct Client *client, char command) {
|
||||||
execute_git_slides(client->repo_path, "prev");
|
execute_git_slides(client->repo_path, "prev");
|
||||||
} else if (command == 'q') {
|
} else if (command == 'q') {
|
||||||
clear_screen(client->fd);
|
clear_screen(client->fd);
|
||||||
close(client->fd);
|
cleanup_client(client);
|
||||||
client->fd = -1; /* Mark as disconnected */
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
snprintf(client->current_slide, BUFFER_SIZE, "Unknown command '%c'. Use SPACE, BACKSPACE, or Q.\n", command);
|
snprintf(client->current_slide, BUFFER_SIZE, "Unknown command '%c'. Use SPACE, BACKSPACE, or Q.\n", command);
|
||||||
|
@ -101,18 +113,6 @@ void send_welcome_message(struct Client *client) {
|
||||||
write(client->fd, client->current_slide, strlen(client->current_slide));
|
write(client->fd, client->current_slide, strlen(client->current_slide));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up client resources */
|
|
||||||
void cleanup_client(struct Client *client) {
|
|
||||||
if (client->fd != -1) {
|
|
||||||
close(client->fd);
|
|
||||||
client->fd = -1;
|
|
||||||
}
|
|
||||||
if (strlen(client->repo_path) > 0) {
|
|
||||||
char rm_command[CMD_SIZE];
|
|
||||||
snprintf(rm_command, sizeof(rm_command), "rm -rf %s", client->repo_path);
|
|
||||||
system(rm_command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int server_fd;
|
int server_fd;
|
||||||
|
|
Loading…
Reference in a new issue