FreeRTOS_recv timeout issue

Is there something I’m missing that FreeRTOS_recv doesn’t seem to honor the timeout?

I need a rather low timeout for non blocking operation, and have done as follows.

static TickType_t xIoRcvTimeOut = 10;//ticks I assume
ret = FreeRTOS_connect(xSocket, (struct freertos_sockaddr *)&serveraddr, sizeof(serveraddr));
FreeRTOS_setsockopt(xSocket, 0, FREERTOS_SO_RCVTIMEO, &xIoRcvTimeOut, sizeof(xIoRcvTimeOut));

If I don’t set after opening, the socket won’t connect.

Sorry, I think this is another issue, disregard.

Hello Erik,

Maybe your problem is solved, but here is some general information about FreeRTOS_connect() and timeouts:

Before FreeRTOS_connect() is called, configure FREERTOS_SO_SNDTIMEO.
Before FreeRTOS_accept() is called, configure FREERTOS_SO_RCVTIMEO.

Time-out values are always provided in number of clock-ticks. pdMS_TO_TICKS() translates from milli-seconds to ticks.

You can call FreeRTOS_connect() in a non-blocking way and call it repeatedly. Once connected, it will return either 0 or -pdFREERTOS_ERRNO_EALREADY.
It will return -pdFREERTOS_ERRNO_EINPROGRESS when it is still working on it.

This is an example of connecting, along with setting the time-outs::

    static TickType_t xConnectTimeout = pdMS_TO_TICKS( 15000U ); /* 15 seconds */
    
    FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xConnectTimeout, sizeof( xConnectTimeout ) );
    ret = FreeRTOS_connect(xSocket, ( struct freertos_sockaddr * ) &serveraddr, sizeof( serveraddr ) );
    if( ( ret == -pdFREERTOS_ERRNO_EALREADY ) || ( ret == 0U )
    {
    static TickType_t xSendTimeout = pdMS_TO_TICKS( 2000U );
    static TickType_t xRecvTimeout = pdMS_TO_TICKS( 2000U );

        FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeout, sizeof( xSendTimeout ) );
        FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xRecvTimeout, sizeof( xRecvTimeout ) );
        /* Now the communication can begin. */
    }