Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zloop: ignore EINTR from poll if nonstop is enabled #2285

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/zloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,10 @@ zloop_start (zloop_t *self)
}
rc = zmq_poll (self->pollset, (int) self->poll_size, s_tickless (self));
if (rc == -1 || (zsys_interrupted && !self->nonstop)) {
if (errno == EINTR && self->nonstop) {
rc = 0;
continue;
}
if (self->verbose) {
if (rc == -1)
zsys_debug ("zloop: interrupted: %s", strerror (errno));
Expand Down Expand Up @@ -915,6 +919,22 @@ s_timer_event5 (zloop_t *loop, int timer_id, void *arg)
return 0;
}

static void
s_raise_sigint_actor (zsock_t *pipe, void *args)
{
zsock_signal (pipe, 0);
assert (zsys_interrupted == 0);
zsock_wait (pipe);
zclock_sleep (100);
#if defined (__WINDOWS__)
assert (GenerateConsoleCtrlEvent (CTRL_C_EVENT, 0) != 0);
#else
assert (kill (getpid(), SIGINT) == 0);
#endif
zclock_sleep (100);
assert (zsys_interrupted != 0);
}

void
zloop_test (bool verbose)
{
Expand Down Expand Up @@ -976,6 +996,34 @@ zloop_test (bool verbose)
assert (timer_event_called);
zsys_interrupted = 0;

// Check that SIGINT terminates loop if nonstop is not set
zloop_destroy (&loop);
zactor_t *raise_sigint_actor = zactor_new (s_raise_sigint_actor, NULL);
assert (raise_sigint_actor);
loop = zloop_new ();
zloop_set_nonstop (loop, false);
timer_event_called = false;
zloop_timer (loop, 1000, 1, s_timer_event3, &timer_event_called);
zsock_signal (raise_sigint_actor, 0);
zloop_start (loop);
zactor_destroy (&raise_sigint_actor);
assert (!timer_event_called);
zsys_interrupted = 0;

// Check that SIGINT does not terminate the loop if nonstop is set
zloop_destroy (&loop);
raise_sigint_actor = zactor_new (s_raise_sigint_actor, NULL);
assert (raise_sigint_actor);
loop = zloop_new ();
zloop_set_nonstop (loop, true);
timer_event_called = false;
zloop_timer (loop, 500, 1, s_timer_event3, &timer_event_called);
zsock_signal (raise_sigint_actor, 0);
zloop_start (loop);
zactor_destroy (&raise_sigint_actor);
assert (timer_event_called);
zsys_interrupted = 0;

// Check if reader removed in timer is not called
zloop_destroy (&loop);
loop = zloop_new ();
Expand Down
8 changes: 4 additions & 4 deletions src/zsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ zsock_vsend (void *self, const char *picture, va_list argptr)
zframe_t *frame = zlistx_pack (list);
zmsg_append (msg, &frame);
}
#endif
#endif
else
if (*picture == 'm') {
zframe_t *frame;
Expand Down Expand Up @@ -1171,7 +1171,7 @@ zsock_vrecv (void *self, const char *picture, va_list argptr)
}
zframe_destroy (&frame);
}
#ifdef CZMQ_BUILD_DRAFT_API
#ifdef CZMQ_BUILD_DRAFT_API
else
if (*picture == 'l') {
zframe_t *frame = zmsg_pop (msg);
Expand Down Expand Up @@ -2205,7 +2205,7 @@ zsock_test (bool verbose)
#ifdef ZMQ_STREAM
zsock_t *streamrecv = zsock_new(ZMQ_STREAM);
assert (streamrecv);
port = zsock_bind(streamrecv, "tcp://*:*");
port = zsock_bind(streamrecv, "tcp://127.0.0.1:*");
assert(port > 0);

zsock_t *streamsender = zsock_new(ZMQ_STREAM);
Expand Down Expand Up @@ -2398,7 +2398,7 @@ zsock_test (bool verbose)
char* message;
message = zstr_recv (gather);
assert (streq(message, "HELLO"));
zstr_free (&message);
zstr_free (&message);

zsock_destroy (&gather);
zsock_destroy (&scatter);
Expand Down
Loading