Пример #1
0
static void ufd_handler(void *context, qd_user_fd_t *ufd)
{
    long    dir = (long) context;
    char    buffer;
    ssize_t len;
    static  int in_read  = 0;
    static  int in_write = 0;

    if (dir == 0) { // READ
        in_read++;
        assert(in_read == 1);
        if (!qd_user_fd_is_readable(ufd_read)) {
            sprintf(stored_error, "Expected Readable");
            qd_server_stop(qd);
        } else {
            len = read(fd[0], &buffer, 1);
            if (len == 1) {
                read_count++;
                if (read_count == OCTET_COUNT)
                    qd_server_stop(qd);
            }
            qd_user_fd_activate_read(ufd_read);
        }
        in_read--;
    } else {        // WRITE
        in_write++;
        assert(in_write == 1);
        if (!qd_user_fd_is_writeable(ufd_write)) {
            sprintf(stored_error, "Expected Writable");
            qd_server_stop(qd);
        } else {
            if (write(fd[1], "X", 1) < 0) abort();

            write_count++;
            if (write_count < OCTET_COUNT)
                qd_user_fd_activate_write(ufd_write);
        }
        in_write--;
    }
}
Пример #2
0
/**
 * This is the OS signal handler, invoked on an undetermined thread at a completely
 * arbitrary point of time.
 */
static void signal_handler(int signum)
{
    /* Ignore future signals, dispatch may already be freed */
    signal(SIGHUP,  SIG_IGN);
    signal(SIGQUIT, SIG_IGN);
    signal(SIGTERM, SIG_IGN);
    signal(SIGINT,  SIG_IGN);
    switch (signum) {
    case SIGINT:
        exit_with_sigint = 1;
        // fallthrough
    case SIGQUIT:
    case SIGTERM:
        qd_server_stop(dispatch); /* qpid_server_stop is signal-safe */
        break;
    default:
        break;
    }
}