Exemple #1
0
void *udp_server(void *arg) {
    sock_t *s = (sock_t *) arg;
    ssize_t received;
#ifdef PACKETS_PER_SECOND
    uint32_t packets = 0, prev_packets = 0;
    uint32_t epoch, prev_epoch = 0;
#endif
    char buf[MAX_CHUNK_SIZE]; // unused, but makes recv() happy
    while (not_aborted()) {
        received = recv(s->socket, buf, MAX_CHUNK_SIZE, 0);
#ifdef PACKETS_PER_SECOND
        if ((epoch = time(0)) != prev_epoch) {
            SAY("packets: %d", packets - prev_packets);
            prev_epoch = epoch;
            prev_packets = packets;
        }
        packets++;
#endif
        if (received < 0)
            break;
        buf_to_blob_enqueue(buf,received);
    }
    WARN_ERRNO("recv failed");
    set_aborted();
    pthread_exit(NULL);
}
Exemple #2
0
gboolean
ggg_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
    GncGWENGui *gui = user_data;

    g_return_val_if_fail(gui, FALSE);

    ENTER("gui=%p, state=%d", gui, gui->state);

    if (gui->state == RUNNING)
    {
        const char *still_running_msg =
            _("The Online Banking job is still running; are you "
              "sure you want to cancel?");
        if (!gnc_verify_dialog(gui->dialog, FALSE, "%s", still_running_msg))
            return FALSE;

        set_aborted(gui);
    }

    hide_dialog(gui);

    LEAVE(" ");
    return TRUE;
}
Exemple #3
0
static void sig_handler(int signum) {
    switch(signum) {
        case SIGHUP:
            set_abort_bits(RELOAD);
            break;
        case SIGTERM:
        case SIGINT:
            set_aborted();
            break;
        default:
            WARN("IGNORE: unexpected signal %d", signum);
    }
}
Exemple #4
0
void
ggg_abort_clicked_cb(GtkButton *button, gpointer user_data)
{
    GncGWENGui *gui = user_data;

    g_return_if_fail(gui && gui->state == RUNNING);

    ENTER("gui=%p", gui);

    set_aborted(gui);

    LEAVE(" ");
}
Exemple #5
0
static void
cm_close_handler(gpointer user_data)
{
    GncGWENGui *gui = user_data;

    g_return_if_fail(gui);

    ENTER("gui=%p", gui);

    /* FIXME */
    set_aborted(gui);

    LEAVE(" ");
}
Exemple #6
0
void *tcp_server(void *arg) {
    sock_t *s = (sock_t *) arg;
    int i,fd,try_to_read,received;
    struct tcp_client *clients,*client;
    struct pollfd *pfds = NULL;
    volatile nfds_t nfds;
    setnonblocking(s->socket);

    nfds = 1;
    pfds = mallocz_or_die(nfds * sizeof(struct pollfd));
    pfds->fd = s->socket;
    pfds->events = POLLIN;
    clients = NULL;
    RELAY_ATOMIC_AND( RECEIVED_STATS.active_connections, 0);
    int rc;
    for (;;) {
        rc = poll(pfds,nfds,CONFIG.polling_interval_ms);
        if (rc == -1) {
            if (rc == EINTR)
                continue;
            WARN_ERRNO("poll");
            goto out;
        }
        for (i = 0; i < nfds; i++) {
            if (!pfds[i].revents)
                continue;
            if (pfds[i].fd == s->socket) {
                fd = accept(s->socket, NULL, NULL);
                if (fd == -1) {
                    WARN_ERRNO("accept");
                    goto out;
                }
                setnonblocking(fd);
                RELAY_ATOMIC_INCREMENT( RECEIVED_STATS.active_connections, 1 );
                pfds = realloc_or_die(pfds, (nfds + 1) * sizeof(*pfds));
                clients = realloc_or_die(clients,(nfds + 1) * sizeof(*clients));

                clients[nfds].pos = 0;
                clients[nfds].buf = mallocz_or_die(ASYNC_BUFFER_SIZE);
//                WARN("[%d] CREATE %p fd: %d",i,clients[nfds].buf,fd);
                pfds[nfds].fd  = fd;
                pfds[nfds].events = POLLIN;
                pfds[nfds].revents = 0;
                nfds++;
            } else {
                client = &clients[i];
                try_to_read = ASYNC_BUFFER_SIZE - client->pos; // try to read as much as possible
                if (try_to_read <= 0) {
                    WARN("disconnecting, try to read: %d, pos: %d", try_to_read, client->pos);
                    goto disconnect;
                }
                received = recv(pfds[i].fd, client->buf + client->pos, try_to_read,0);
                if (received <= 0) {
                    if (received == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
                        continue;

                disconnect:
                    shutdown(pfds[i].fd,SHUT_RDWR);
                    close(pfds[i].fd);
//                    WARN("[%d] DESTROY %p %d %d fd: %d vs %d",i,client->buf,client->x,i,pfds[i].fd,client->fd);
                    free(client->buf);

                    // shft left
                    memcpy(pfds + i,pfds + i + 1, (nfds - i - 1) * sizeof(struct pollfd));
                    memcpy(clients + i,clients + i + 1, (nfds - i - 1) * sizeof(struct tcp_client));

                    nfds--;
                    pfds = realloc_or_die(pfds, nfds * sizeof(struct pollfd));
                    clients = realloc_or_die(clients, nfds * sizeof(struct tcp_client));
                    RELAY_ATOMIC_DECREMENT( RECEIVED_STATS.active_connections, 1 );
                    continue;
                }
                client->pos += received;

            try_to_consume_one_more:

                if (client->pos < EXPECTED_HEADER_SIZE)
                    continue;

                if (EXPECTED(client) > MAX_CHUNK_SIZE) {
                    WARN("received frame (%d) > MAX_CHUNK_SIZE(%d)",EXPECTED(client),MAX_CHUNK_SIZE);
                    goto disconnect;
                }
                if (client->pos >= EXPECTED(client) + EXPECTED_HEADER_SIZE) {
                    buf_to_blob_enqueue(client->buf,EXPECTED(client));

                    client->pos -= EXPECTED(client) + EXPECTED_HEADER_SIZE;
                    if (client->pos < 0) {
                        WARN("BAD PACKET wrong 'next' position(< 0) pos: %d expected packet size:%d header_size: %d",
                             client->pos, EXPECTED(client),EXPECTED_HEADER_SIZE);
                        goto disconnect;
                    }
                    if (client->pos > 0) {
                        // [ h ] [ h ] [ h ] [ h ] [ D ] [ D ] [ D ] [ h ] [ h ] [ h ] [ h ] [ D ]
                        //                                                                     ^ pos(12)
                        // after we remove the first packet + header it becomes:
                        // [ h ] [ h ] [ h ] [ h ] [ D ] [ D ] [ D ] [ h ] [ h ] [ h ] [ h ] [ D ]
                        //                           ^ pos (5)
                        // and then we copy from header + data, to position 0, 5 bytes
                        //
                        // [ h ] [ h ] [ h ] [ h ] [ D ]
                        //                           ^ pos (5)
                        memmove(client->buf,
                                client->buf + EXPECTED_HEADER_SIZE + EXPECTED(client),
                                client->pos);
                        if (client->pos >= EXPECTED_HEADER_SIZE)
                            goto try_to_consume_one_more;
                    }
                }
            }
        }
    }
out:
    for (i = 0; i < nfds; i++) {
        if (pfds[i].fd != s->socket)
            free(clients[i].buf);
        shutdown(pfds[i].fd, SHUT_RDWR);
        close(pfds[i].fd);
    }
    free(pfds);
    free(clients);
    set_aborted();
    pthread_exit(NULL);
}
Exemple #7
0
void WorkGangBarrierSync::abort() {
  MutexLockerEx x(monitor(), Mutex::_no_safepoint_check_flag);
  set_aborted();
  monitor()->notify_all();
}