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

C example interrupt.c does not match with the description #798

Open
franzhollerer opened this issue Mar 19, 2020 · 0 comments
Open

C example interrupt.c does not match with the description #798

franzhollerer opened this issue Mar 19, 2020 · 0 comments

Comments

@franzhollerer
Copy link
Contributor

franzhollerer commented Mar 19, 2020

According the description in section Handling Interrupt Signals the signal handler sets the global variable s_interrupted.

The program provides s_catch_signals(), which traps Ctrl-C (SIGINT) and SIGTERM. When either
of these signals arrive, the s_catch_signals() handler sets the global variable s_interrupted.
Thanks to your signal handler, your application will not die automatically. Instead, you have a
chance to clean up and exit gracefully. 

However, the C example implements a different approach. It uses a pipe instead of the global variable.

From interrupt.c:

//  Shows how to handle Ctrl-C

#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>

#include <zmq.h>

//  Signal handling
//
//  Create a self-pipe and call s_catch_signals(pipe's writefd) in your application
//  at startup, and then exit your main loop if your pipe contains any data.
//  Works especially well with zmq_poll.

#define S_NOTIFY_MSG " "
#define S_ERROR_MSG "Error while writing to self-pipe.\n"
static int s_fd;
static void s_signal_handler (int signal_value)
{
    int rc = write (s_fd, S_NOTIFY_MSG, sizeof(S_NOTIFY_MSG));
    if (rc != sizeof(S_NOTIFY_MSG)) {
        write (STDOUT_FILENO, S_ERROR_MSG, sizeof(S_ERROR_MSG)-1);
        exit(1);
    }
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant