STCP/mysock_api.c
int myclose(mysocket_t sd)
{
    mysock_context_t *ctx = _mysock_get_context(sd);

    DEBUG_LOG(("***myclose(%d)***\n", sd));
    MYSOCK_CHECK(ctx != NULL, EBADF);

    /* stcp_wait_for_event() needs to wake up on a socket close request */
    PTHREAD_CALL(pthread_mutex_lock(&ctx->data_ready_lock));
    ctx->close_requested = TRUE;
    PTHREAD_CALL(pthread_mutex_unlock(&ctx->data_ready_lock));
    PTHREAD_CALL(pthread_cond_broadcast(&ctx->data_ready_cond));

    /* block until STCP thread exits */
    if (ctx->transport_thread_started)
    {
        assert(!ctx->listening);
        assert(ctx->is_active || ctx->listen_sd != -1);
        PTHREAD_CALL(pthread_join(ctx->transport_thread, NULL));
        ctx->transport_thread_started = FALSE;
    }

    _network_stop_recv_thread(ctx);

    if (ctx->listening)
    {
        /* remove entry from SYN demultiplexing table */
        _mysock_close_passive_socket(ctx);
    }

    /* free all resources associated with this mysocket */
    _mysock_free_context(ctx);

    DEBUG_LOG(("myclose(%d) returning...\n", sd));
    return 0;
}
/* close the given mysocket.  note that the semantics of myclose() differ
 * slightly from a regular close(); STCP doesn't implement TIME_WAIT, so
 * myclose() simply discards all knowledge of the connection once the
 * connection is terminated.
 */
close the given mysocket.  note that the semantics of myclose() differ
slightly from a regular close(); STCP doesn't implement TIME_WAIT, so
myclose() simply discards all knowledge of the connection once the
connection is terminated.
close the given mysocket . note that the semantics of myclose () differ slightly from a regular close () ; STCP doesn ' t implement TIME_WAIT so myclose () simply discards all knowledge of the connection once the connection is terminated .
int myclose(mysocket_t sd)
{
    mysock_context_t *ctx = _mysock_get_context(sd);
    DEBUG_LOG(("***myclose(%d)***\n", sd));
    MYSOCK_CHECK(ctx != NULL, EBADF);
    PTHREAD_CALL(pthread_mutex_lock(&ctx->data_ready_lock));
    ctx->close_requested = TRUE;
    PTHREAD_CALL(pthread_mutex_unlock(&ctx->data_ready_lock));
    PTHREAD_CALL(pthread_cond_broadcast(&ctx->data_ready_cond));
    if (ctx->transport_thread_started)
    {
        assert(!ctx->listening);
        assert(ctx->is_active || ctx->listen_sd != -1);
        PTHREAD_CALL(pthread_join(ctx->transport_thread, NULL));
        ctx->transport_thread_started = FALSE;
    }
    _network_stop_recv_thread(ctx);
    if (ctx->listening)
    {
        _mysock_close_passive_socket(ctx);
    }
    _mysock_free_context(ctx);
    DEBUG_LOG(("myclose(%d) returning...\n", sd));
    return 0;
}
int myclose ( mysocket_t sd ) { mysock_context_t * ctx = _mysock_get_context ( sd ) ; DEBUG_LOG ( ( " \n " , sd ) ) ; MYSOCK_CHECK ( ctx != NULL , EBADF ) ; PTHREAD_CALL ( pthread_mutex_lock ( & ctx -> data_ready_lock ) ) ; ctx -> close_requested = TRUE ; PTHREAD_CALL ( pthread_mutex_unlock ( & ctx -> data_ready_lock ) ) ; PTHREAD_CALL ( pthread_cond_broadcast ( & ctx -> data_ready_cond ) ) ; if ( ctx -> transport_thread_started ) { assert ( ! ctx -> listening ) ; assert ( ctx -> is_active || ctx -> listen_sd != -1 ) ; PTHREAD_CALL ( pthread_join ( ctx -> transport_thread , NULL ) ) ; ctx -> transport_thread_started = FALSE ; } _network_stop_recv_thread ( ctx ) ; if ( ctx -> listening ) { _mysock_close_passive_socket ( ctx ) ; } _mysock_free_context ( ctx ) ; DEBUG_LOG ( ( " \n " , sd ) ) ; return 0 ; }
close the given mysocket.
close the given mysocket .
/* stcp_wait_for_event() needs to wake up on a socket close request */ /* block until STCP thread exits */ /* remove entry from SYN demultiplexing table */ /* free all resources associated with this mysocket */