static void port_server_shutdown(PortServer * server) {
    PortConnection * conn;

    /* It seems we need to use shutdown to unblock threads blocked on recv/send */
    if (server->sock != -1) {
        shutdown(server->sock, SHUT_RDWR);
        if (closesocket(server->sock) == -1) perror("closesocket");
        server->sock = -1;
        list_remove(&server->link);
        /* Closing socket is enough; the various port connections
         * will be deleted when server deletion will be detected. In this
         * case this API will be called again.
         */
        return;
    }

    for (conn = server->list; conn != NULL; ) {
        PortConnection * next_conn;
        next_conn = conn->next;
        port_connection_close(conn);
        conn = next_conn;
    }


    if (server->list != NULL) return;    /* Wait for all port connections to be closed */
    if (server->accept_in_progress) return;        /* Wait for accept request to be aborted */

    channel_unlock_with_msg(server->channel, channel_lock_svr_msg);
    if (server->redir_info) free_port_redirection_info(server->redir_info);
    loc_free(server->addr_buf);
    loc_free(server);
}
Пример #2
0
static void cache_notify_event(void * args) {
    unsigned i;
    WaitingCacheClient * buf = (WaitingCacheClient *)args;
    for (i = 0; buf[i].client != NULL; i++) {
        current_client = buf[i];
        run_cache_client(1);
        if (buf[i].channel != NULL) channel_unlock_with_msg(buf[i].channel, channel_lock_msg);
    }
    loc_free(buf);
}
Пример #3
0
static void terminal_exited(void * args) {
    Terminal * term = (Terminal *)args;
    Trap trap;

    if (set_trap(&trap)) {
        send_event_terminal_exited(&term->bcg->out, term);
        clear_trap(&trap);
    }
    else {
        trace(LOG_ALWAYS, "Exception sending terminal exited event: %d %s",
            trap.error, errno_to_str(trap.error));
    }

    list_remove(&term->link);
    channel_unlock_with_msg(term->channel, TERMINALS);
    loc_free(term);
}
Пример #4
0
void cache_notify(AbstractCache * cache) {
    unsigned i;
    unsigned cnt = cache->wait_list_cnt;

    assert(is_dispatch_thread());
    if (cnt == 0) return;
    list_remove(&cache->link);
    cache->wait_list_cnt = 0;
    if (wait_list_max < cnt) {
        wait_list_max = cnt;
        wait_list_buf = (WaitingCacheClient *)loc_realloc(wait_list_buf, cnt * sizeof(WaitingCacheClient));
    }
    memcpy(wait_list_buf, cache->wait_list_buf, cnt * sizeof(WaitingCacheClient));
    for (i = 0; i < cnt; i++) {
        current_client = wait_list_buf[i];
        run_cache_client(1);
        if (wait_list_buf[i].channel != NULL) channel_unlock_with_msg(wait_list_buf[i].channel, channel_lock_msg);
    }
}