Interrupt on process terminated
Interrupt any blocking call on process terminated, like on server_stop(). This allows to interrupt any blocking accept() with correct synchronization without additional complexity.
This commit is contained in:
parent
f488cbd7e7
commit
37c840a4c8
1 changed files with 7 additions and 10 deletions
|
@ -511,8 +511,8 @@ server_connect_to(struct server *server, struct server_info *info) {
|
||||||
if (!net_close(server->server_socket)) {
|
if (!net_close(server->server_socket)) {
|
||||||
LOGW("Could not close server socket on connect");
|
LOGW("Could not close server socket on connect");
|
||||||
}
|
}
|
||||||
// Do not attempt to close it again on server_destroy()
|
|
||||||
server->server_socket = SC_INVALID_SOCKET;
|
// server_socket is never used anymore
|
||||||
} else {
|
} else {
|
||||||
uint32_t attempts = 100;
|
uint32_t attempts = 100;
|
||||||
sc_tick delay = SC_TICK_FROM_MS(100);
|
sc_tick delay = SC_TICK_FROM_MS(100);
|
||||||
|
@ -573,14 +573,11 @@ static void
|
||||||
server_on_terminated(void *userdata) {
|
server_on_terminated(void *userdata) {
|
||||||
struct server *server = userdata;
|
struct server *server = userdata;
|
||||||
|
|
||||||
// No need for synchronization, server_socket is initialized before the
|
// If the server process dies before connecting to the server socket,
|
||||||
// observer thread is created.
|
// then the client will be stuck forever on accept(). To avoid the problem,
|
||||||
if (server->server_socket != SC_INVALID_SOCKET) {
|
// wake up the accept() call (or any other) when the server dies, like on
|
||||||
// If the server process dies before connecting to the server socket,
|
// stop() (it is safe to call interrupt() twice).
|
||||||
// then the client will be stuck forever on accept(). To avoid the
|
sc_intr_interrupt(&server->intr);
|
||||||
// problem, wake up the accept() call when the server dies.
|
|
||||||
net_interrupt(server->server_socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
server->cbs->on_disconnected(server, server->cbs_userdata);
|
server->cbs->on_disconnected(server, server->cbs_userdata);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue