void tcp_server_free(tcp_server_ctx_t* ctx) { socketlist_free(ctx->client_sockets); if(ctx->data_destructor != NULL){ ctx->data_destructor(ctx->data); } free(ctx); }
/** * events_network_shutdown(void) * Clean up and free memory. This call is not necessary on program exit and * is only expected to be useful when checking for memory leaks. */ void events_network_shutdown(void) { /* If we're not initialized, do nothing. */ if (S == NULL) return; /* If we have any registered events, do nothing. */ if (nev > 0) return; /* Free the socket list. */ socketlist_free(S); S = NULL; }
void tcp_server_close_all(tcp_server_ctx_t* ctx) { if(ctx->listen_socket != 0){ close(ctx->listen_socket); ctx->listen_socket = 0; } socketlist_t* cursor = ctx->client_sockets; while(cursor != NULL){ if(cursor->socket != 0){ close(cursor->socket); } cursor = cursor->next; } socketlist_free(ctx->client_sockets); ctx->client_sockets = NULL; }