Introduce free_ipc_client
This commit is contained in:
parent
715cea61af
commit
b0bbe53d04
37
src/ipc.c
37
src/ipc.c
|
@ -38,6 +38,16 @@ static void set_nonblock(int sockfd) {
|
||||||
err(-1, "Could not set O_NONBLOCK");
|
err(-1, "Could not set O_NONBLOCK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void free_ipc_client(ipc_client *client) {
|
||||||
|
close(client->fd);
|
||||||
|
for (int i = 0; i < client->num_events; i++){
|
||||||
|
free(client->events[i]);
|
||||||
|
}
|
||||||
|
free(client->events);
|
||||||
|
TAILQ_REMOVE(&all_clients, client, clients);
|
||||||
|
free(client);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sends the specified event to all IPC clients which are currently connected
|
* Sends the specified event to all IPC clients which are currently connected
|
||||||
* and subscribed to this kind of event.
|
* and subscribed to this kind of event.
|
||||||
|
@ -99,12 +109,7 @@ void ipc_shutdown(shutdown_reason_t reason) {
|
||||||
while (!TAILQ_EMPTY(&all_clients)) {
|
while (!TAILQ_EMPTY(&all_clients)) {
|
||||||
current = TAILQ_FIRST(&all_clients);
|
current = TAILQ_FIRST(&all_clients);
|
||||||
shutdown(current->fd, SHUT_RDWR);
|
shutdown(current->fd, SHUT_RDWR);
|
||||||
close(current->fd);
|
free_ipc_client(current);
|
||||||
for (int i = 0; i < current->num_events; i++)
|
|
||||||
free(current->events[i]);
|
|
||||||
free(current->events);
|
|
||||||
TAILQ_REMOVE(&all_clients, current, clients);
|
|
||||||
free(current);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1247,25 +1252,21 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If not, there was some kind of error. We don’t bother
|
/* If not, there was some kind of error. We don’t bother and close the
|
||||||
* and close the connection */
|
* connection. Delete the client from the list of clients. */
|
||||||
close(w->fd);
|
bool closed = false;
|
||||||
|
|
||||||
/* Delete the client from the list of clients */
|
|
||||||
ipc_client *current;
|
ipc_client *current;
|
||||||
TAILQ_FOREACH(current, &all_clients, clients) {
|
TAILQ_FOREACH(current, &all_clients, clients) {
|
||||||
if (current->fd != w->fd)
|
if (current->fd != w->fd)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int i = 0; i < current->num_events; i++)
|
free_ipc_client(current);
|
||||||
free(current->events[i]);
|
closed = true;
|
||||||
free(current->events);
|
|
||||||
/* We can call TAILQ_REMOVE because we break out of the
|
|
||||||
* TAILQ_FOREACH afterwards */
|
|
||||||
TAILQ_REMOVE(&all_clients, current, clients);
|
|
||||||
free(current);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!closed) {
|
||||||
|
close(w->fd);
|
||||||
|
}
|
||||||
|
|
||||||
ev_io_stop(EV_A_ w);
|
ev_io_stop(EV_A_ w);
|
||||||
free(w);
|
free(w);
|
||||||
|
|
Loading…
Reference in New Issue