mirror of
https://codeberg.org/scip/udpxd.git
synced 2025-12-16 11:30:57 +01:00
added commentary to the longjmp() stuff, so I understand it later, what it does
This commit is contained in:
17
net.c
17
net.c
@@ -363,6 +363,7 @@ void handle_outside(int inside, int outside, host_t *outside_h) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* stores system specific information, used by longjmp(), see below */
|
||||||
jmp_buf JumpBuffer;
|
jmp_buf JumpBuffer;
|
||||||
|
|
||||||
/* runs forever, handles incoming requests on the inside and answers on the outside */
|
/* runs forever, handles incoming requests on the inside and answers on the outside */
|
||||||
@@ -370,10 +371,19 @@ int main_loop(int listensocket, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
|||||||
int max, sender;
|
int max, sender;
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
|
|
||||||
|
/* we want to properly tear down running sessions when interrupted,
|
||||||
|
int_handler() will be called on INT or TERM signals */
|
||||||
signal(SIGINT, int_handler);
|
signal(SIGINT, int_handler);
|
||||||
signal(SIGTERM, int_handler);
|
signal(SIGTERM, int_handler);
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
/*
|
||||||
|
Normally returns 0, that is, if it's the first instruction after
|
||||||
|
entering the loop. However, it will return 1, when called from
|
||||||
|
longjmp(), which will be called by int_handler() if a SIGINT- or
|
||||||
|
TERM arrives. In that case we leave the loop, tear down
|
||||||
|
everything and exit.
|
||||||
|
*/
|
||||||
if (setjmp(JumpBuffer) == 1) {
|
if (setjmp(JumpBuffer) == 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -402,14 +412,17 @@ int main_loop(int listensocket, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
|||||||
client_clean(0);
|
client_clean(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we came here via signal handler,
|
/* we came here via signal handler, clean up */
|
||||||
clean up */
|
|
||||||
close(listensocket);
|
close(listensocket);
|
||||||
client_clean(1);
|
client_clean(1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Handle SIGINT- and TERM, call longjmp(), which jumps right into the
|
||||||
|
main loop, where it causes the loop to be left.
|
||||||
|
*/
|
||||||
void int_handler(int sig) {
|
void int_handler(int sig) {
|
||||||
signal(sig, SIG_IGN);
|
signal(sig, SIG_IGN);
|
||||||
longjmp(JumpBuffer, 1);
|
longjmp(JumpBuffer, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user