[ ]
 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]

Socket_t FreeRTOS_accept( Socket_t xServerSocket,
                           struct freertos_sockaddr *pxAddress,
                           socklen_t *pxAddressLength );

Accept a connection on a TCP socket.

The socket must first have been successfully created by a call to FreeRTOS_socket(), bound to a port using a call to FreeRTOS_bind(), and placed into the Listening state using a call to FreeRTOS_listen(),

By default a new socket (a child socket) will be created to handle any accepted connections. The new socket will be returned by FreeRTOS_accept(), and can be used immediately. The child socket inherits all the properties from the parent socket.

Optionally the FREERTOS_SO_REUSE_LISTEN_SOCKET parameter can be used with a call to FreeRTOS_setsockopt() to configure the parent socket to handle any accepted connections itself - without creating a child socket for this purpose. This is a useful way to save resources when the socket will only handle a single connection at a time. For example, if the socket is used to implement a telnet server that only permits one simultaneous connection.

FreeRTOS_accept() has an optional timeout. The timeout defaults to ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME, and is modified using the FREERTOS_SO_RCVTIMEO parameter in a call to FreeRTOS_setsockopt(). If the accept operation does not succeed immediately then the calling RTOS task will be held in the Blocked state (so that other RTOS tasks can execute) until either a connection is accepted, or the timeout expires. Parameters:

xServerSocket   The handle of the listening socket on which new connections are to be accepted.

pxAddress   A pointer to a freertos_sockaddr structure that will be filled (by FreeRTOS_accept()) with the IP address and port number of the socket from which a connection was accepted.

pxAddressLength   Not currently used, but should be set to sizeof( struct freertos_sockaddr ) to ensure future compatibility.


If a connection from a remote socket is accepted and a new local socket is created to handle the accepted connection then a handle to the new socket is returned.

If xServerSocket is not a valid TCP socket then then FREERTOS_INVALID_SOCKET is returned.

If xServerSocket is not in the Listening state (see FreeRTOS_listen()) then FREERTOS_INVALID_SOCKET is returned.

If a timeout occurs before a connection from a remote socket is accepted then NULL is returned.

Note that, because FreeRTOS does not implement errno, the behaviour in the presence of an error is necessarily different to that of connect() functions that are fully compliant with the expected Berkeley sockets behaviour.

Example usage:

See the "Creating, configuring and binding a TCP server socket" source code example in the "Creating Configuring and Binding TCP Client and Server Sockets" section of the FreeRTOS+TCP networking tutorial.

[ 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.