Esempio n. 1
0
/**
 * Disconnect and clean up
 *
 * @param icb The connection control block
 */
static void
cleanup_disconnect(connection_t *cxn)
{
    uint8_t *data;
    biglist_t *ble;

    cxn->status.disconnect_count++;

    /* Close this socket. */
    if (cxn->sd >= 0) {
        ind_soc_socket_unregister(cxn->sd);
        close(cxn->sd);
    }
    cxn->sd = -1;

    cxn->generation_id++;

    /* @fixme Is it possible there's a message that should be processed? */
    LOG_VERBOSE(cxn, "Closing connection, current read buf has %d bytes",
                cxn->read_bytes);
    cxn->read_bytes = 0;
    /* Clear write queue */
    BIGLIST_FOREACH_DATA(ble, cxn->output_list, uint8_t *, data) {
        LOG_TRACE(cxn, "Freeing outgoing msg %p", data);
        INDIGO_MEM_FREE(data);
    }
    biglist_free(cxn->output_list);
    cxn->output_list = NULL;

    cxn->bytes_enqueued = 0;
    cxn->pkts_enqueued = 0;
    cxn->output_head_offset = 0;
}
int
biglist_locked_remove_link_free(biglist_locked_t* bl, biglist_t* blink)
{
    biglist_lock(bl);
    bl->list = biglist_remove_link(bl->list, blink);
    biglist_unlock(bl);
    biglist_free(blink);
    return 0;
}