Signalling an empty socket set

Hi,

I’m using FreeRTOS-Plus-TCP and found a situation where I wanted to wait on an empty socket set (which the system supports) but then I wanted to signal the socket set to wake up the thread to check for new connections and there currently isn’t a way to do this.

So I added the following function locally:

#if ( ipconfigSUPPORT_SIGNALS != 0 ) && ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )

/**
 * @brief Send a signal to the task which waits on this socket set.
 *        The socket set will receive an event of the type 'eSOCKET_INTR'.
 *
 * @param[in] pxSocketSet: The socket set that will be signalled.
 */
    BaseType_t FreeRTOS_SignalSocketSet( SocketSet_t pxSocketSet )
    {
        BaseType_t xReturn;

        if( pxSocketSet == NULL )
        {
            xReturn = -pdFREERTOS_ERRNO_EINVAL;
        }
        else if(pxSocketSet->xSelectGroup != NULL )
        {
            ( void ) xEventGroupSetBits( pxSocketSet->xSelectGroup, ( EventBits_t ) eSELECT_INTR );
            xReturn = 0;
        }
        return xReturn;
    }

#endif /* ipconfigSUPPORT_SIGNALS && ipconfigSUPPORT_SELECT_FUNCTION */

This does exactly what I want, preventing my code from having to have a secondary wait system when no connections are active.

Might be of use to others.

Cheers

Nigel

Correction/simplification:

#if ( ipconfigSUPPORT_SIGNALS != 0 ) && ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )

/**
 * @brief Send a signal to the task which waits on this socket set.
 *        The socket set will receive an event of the type 'eSOCKET_INTR'.
 *
 * @param[in] pxSocketSet: The socket set that will be signalled.
 */
    BaseType_t FreeRTOS_SignalSocketSet( SocketSet_t pxSocketSet )
    {
        BaseType_t xReturn = -pdFREERTOS_ERRNO_EINVAL;

        if (( pxSocketSet != NULL ) && (pxSocketSet->xSelectGroup != NULL ))
        {
            ( void ) xEventGroupSetBits( pxSocketSet->xSelectGroup, ( EventBits_t ) eSELECT_INTR );
            xReturn = 0;
        }

        return xReturn;
    }

#endif /* ipconfigSUPPORT_SIGNALS && ipconfigSUPPORT_SELECT_FUNCTION */
3 Likes

Would you like to raise a pull request to +TCP with these changes? We are happy to have contributions to our libraries. Thanks for posting this :slight_smile:

I can also raise the PR if you’d prefer

@kanherea and @htibosch this might be of interest to you

Also @Shub since he has worked on the library very recently

Hi Kody,

Thanks for the reply. I’m not setup to use GitHub just now. Might not have time this week to set that up.

Cheers

Nigel

Hi Nigel,
As Kody already suggested, please share the change as a Pull Request. We would be happy to help you with the process and take in your contributions.

Cheers,
Shub