AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/addons/web/nx_tcpserver.c
UINT _nx_tcpserver_delete(NX_TCPSERVER *server_ptr)
{
UINT            i;
NX_TCP_SOCKET  *socket_ptr;

    /* Terminate server thread. */
    tx_thread_terminate(&server_ptr -> nx_tcpserver_thread);

    /* Delete server thread. */
    tx_thread_delete(&server_ptr -> nx_tcpserver_thread);

    /* Delete the event flag group */
    tx_event_flags_delete(&server_ptr -> nx_tcpserver_event_flags);

    /* Deactivate and delete timer. */
    tx_timer_deactivate(&server_ptr -> nx_tcpserver_timer);
    tx_timer_delete(&server_ptr -> nx_tcpserver_timer);

    /* Delete all opened sockets. */
    for(i = 0; i < server_ptr -> nx_tcpserver_sessions_count; i++)
    {

        /* Get socket pointer. */
        socket_ptr = &server_ptr -> nx_tcpserver_sessions[i].nx_tcp_session_socket;

        /* Disconnect the socket. */
        nx_tcp_socket_disconnect(socket_ptr, NX_NO_WAIT);

        /* unaccept the socket. */
        nx_tcp_server_socket_unaccept(socket_ptr);

        /* Delete the socket. */
        nx_tcp_socket_delete(socket_ptr);
    }

    /* Return successful compeletion. */
    return NX_SUCCESS;
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_tcpserver_delete                                 PORTABLE C     */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function is called by an application to clean up a previously  */
/*    created socket server. It cleans up the server thread and closes    */
/*    deletes all internal TCP sockets and TLS sessions.                  */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    server_ptr                            Pointer to server structure   */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    status                                Completion status             */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    tx_thread_terminate                   Stop server thread            */
/*    tx_thread_delete                      Stop server timeout timer     */
/*    tx_event_flags_delete                 Delete server event flags     */
/*    tx_timer_deactivate                   Deactivate timeout timer      */
/*    tx_timer_delete                       Delete timeout timer          */
/*    nx_tcp_socket_disconnect              Disconnect TCP sockets        */
/*    nx_tcp_server_socket_unaccept         Stop listening on TCP sockets */
/*    nx_tcp_socket_delete                  Delete TCP socket             */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*   Application code                                                     */
/*                                                                        */
/*  RELEASE HISTORY                                                       */
/*                                                                        */
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
/*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
/*                                            resulting in version 6.1    */
/*                                                                        */
/**************************************************************************/
FUNCTION                                               RELEASE

_nx_tcpserver_delete                                 PORTABLE C
6.1
AUTHOR

Yuxin Zhou, Microsoft Corporation

DESCRIPTION

This function is called by an application to clean up a previously
created socket server. It cleans up the server thread and closes
deletes all internal TCP sockets and TLS sessions.

INPUT

server_ptr                            Pointer to server structure

OUTPUT

status                                Completion status

CALLS

tx_thread_terminate                   Stop server thread
tx_thread_delete                      Stop server timeout timer
tx_event_flags_delete                 Delete server event flags
tx_timer_deactivate                   Deactivate timeout timer
tx_timer_delete                       Delete timeout timer
nx_tcp_socket_disconnect              Disconnect TCP sockets
nx_tcp_server_socket_unaccept         Stop listening on TCP sockets
nx_tcp_socket_delete                  Delete TCP socket

CALLED BY

Application code

RELEASE HISTORY

DATE              NAME                      DESCRIPTION

05-19-2020     Yuxin Zhou               Initial Version 6.0
09-30-2020     Yuxin Zhou               Modified comment(s),
resulting in version 6.1
FUNCTION RELEASE _nx_tcpserver_delete PORTABLE C 6 . 1 AUTHOR Yuxin Zhou Microsoft Corporation DESCRIPTION This function is called by an application to clean up a previously created socket server . It cleans up the server thread and closes deletes all internal TCP sockets and TLS sessions . INPUT server_ptr Pointer to server structure OUTPUT status Completion status CALLS tx_thread_terminate Stop server thread tx_thread_delete Stop server timeout timer tx_event_flags_delete Delete server event flags tx_timer_deactivate Deactivate timeout timer tx_timer_delete Delete timeout timer nx_tcp_socket_disconnect Disconnect TCP sockets nx_tcp_server_socket_unaccept Stop listening on TCP sockets nx_tcp_socket_delete Delete TCP socket CALLED BY Application code RELEASE HISTORY DATE NAME DESCRIPTION 05 - 19 - 2020 Yuxin Zhou Initial Version 6 . 0 09 - 30 - 2020 Yuxin Zhou Modified comment ( s ) resulting in version 6 . 1
UINT _nx_tcpserver_delete(NX_TCPSERVER *server_ptr)
{
UINT            i;
NX_TCP_SOCKET  *socket_ptr;
    tx_thread_terminate(&server_ptr -> nx_tcpserver_thread);
    tx_thread_delete(&server_ptr -> nx_tcpserver_thread);
    tx_event_flags_delete(&server_ptr -> nx_tcpserver_event_flags);
    tx_timer_deactivate(&server_ptr -> nx_tcpserver_timer);
    tx_timer_delete(&server_ptr -> nx_tcpserver_timer);
    for(i = 0; i < server_ptr -> nx_tcpserver_sessions_count; i++)
    {
        socket_ptr = &server_ptr -> nx_tcpserver_sessions[i].nx_tcp_session_socket;
        nx_tcp_socket_disconnect(socket_ptr, NX_NO_WAIT);
        nx_tcp_server_socket_unaccept(socket_ptr);
        nx_tcp_socket_delete(socket_ptr);
    }
    return NX_SUCCESS;
}
UINT _nx_tcpserver_delete ( NX_TCPSERVER * server_ptr ) { UINT i ; NX_TCP_SOCKET * socket_ptr ; tx_thread_terminate ( & server_ptr -> nx_tcpserver_thread ) ; tx_thread_delete ( & server_ptr -> nx_tcpserver_thread ) ; tx_event_flags_delete ( & server_ptr -> nx_tcpserver_event_flags ) ; tx_timer_deactivate ( & server_ptr -> nx_tcpserver_timer ) ; tx_timer_delete ( & server_ptr -> nx_tcpserver_timer ) ; for ( i = 0 ; i < server_ptr -> nx_tcpserver_sessions_count ; i ++ ) { socket_ptr = & server_ptr -> nx_tcpserver_sessions [ i ] . nx_tcp_session_socket ; nx_tcp_socket_disconnect ( socket_ptr , NX_NO_WAIT ) ; nx_tcp_server_socket_unaccept ( socket_ptr ) ; nx_tcp_socket_delete ( socket_ptr ) ; } return NX_SUCCESS ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE
/* Terminate server thread. */ /* Delete server thread. */ /* Delete the event flag group */ /* Deactivate and delete timer. */ /* Delete all opened sockets. */ /* Get socket pointer. */ /* Disconnect the socket. */ /* unaccept the socket. */ /* Delete the socket. */ /* Return successful compeletion. */