[ ]
 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Homepage FreeRTOS Labs FreeRTOS+TCP FreeRTOS+FAT Contact / Enquiries

FreeRTOS+TCP is still in the lab
FreeRTOS+TCP is already used in commercial products and we encourage you to try it yourself. Be aware however that we are still refining its design, and the source code and documentation do not yet meet Real Time Engineers Ltd's strict quality standards.
Please use the forum for support, feedback and ideas, or contact us directly if you have a specific business interest.


[FreeRTOS+TCP API Reference]

BaseType_t FreeRTOS_closesocket( Socket_t xSocket );

Close a socket.

The function is named FreeRTOS_closesocket() rather than simply FreeRTOS_close() to avoid potential name space collisions with functions in FreeRTOS+IO.

A socket should be shutdown gracefully before it is closed, and cannot be used after it has been closed.


xSocket   The handle of the socket being closed. The socket must have already been created (see FreeRTOS_socket()), and cannot be used after it has been closed.


0 is always returned.

Although FreeRTOS+TCP does not [currently] use the return value in a meaningful way, the return value is included in the function prototype to ensure consistency with the expected standard Berkeley sockets API, and to ensure compatibility with future versions of FreeRTOS+TCP.

Example usage:

/* FreeRTOS+TCP sockets include. */
#define "FreeRTOS_sockets.h"

void aFunction( void )
Socket_t xSocket;

    /* Create a socket. */

    if( xSocket != FREERTOS_INVALID_SOCKET )
         * The socket can now be used...

         /* . . . */

         /* Initialise a shutdown before closing the socket. */
         FreeRTOS_shutdown( xSocket );

        /* Wait for the socket to disconnect gracefully (indicated by FreeRTOS_recv()
        returning a FREERTOS_EINVAL error) before closing the socket. */
        while( FreeRTOS_recv( xSocket, pcBufferToTransmit, xTotalLengthToSend, 0 ) >= 0 )
            /* Wait for shutdown to complete.  If a receive block time is used then
            this delay will not be necessary as FreeRTOS_recv() will place the RTOS task
            into the Blocked state anyway. */
            vTaskDelay( pdTICKS_TO_MS( 250 ) );

            /* Note - real applications should implement a timeout here, not just
            loop forever. */

         /* Close the socket again. */
         FreeRTOS_closesocket( xSocket );

Example use of the FreeRTOS_closesocket() API function

[ Back to the top ]    [ About FreeRTOS ]    [ FreeRTOS Labs Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.