LwIP websrv async communication

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LwIP websrv async communication

1,154 Views
xeos_jonathan
Contributor I

Hello,

Using the IMXRT1062, with SDK v2.9.1. It contains a websocket example via LwIP (lwip_httpsrv_freertos). In this example, data is send to the connected socket via the WS_Send function.

The parameter for the WS_Send function is WS_USER_CONTEXT_STRUCT:

 

/*
 * WebSocket data structure
 */
typedef struct ws_data_struct
{
    /* Pointer to user data. */
    uint8_t *data_ptr;
    /* Length of user data. */
    uint32_t length;
    /* Type of data. */
    WS_DATA_TYPE type;
} WS_DATA_STRUCT;

/*
 * Structure passed as parameter to user callbacks
 */
typedef struct ws_user_context_struct
{
    /* WebSocket handle. */
    uint32_t handle;
    /* Error code if error occurs. */
    WS_ERROR_CODE error;
    /* Data structure. */
    WS_DATA_STRUCT data;
    /* Flag signalizing end of message. */
    uint32_t fin_flag;
} WS_USER_CONTEXT_STRUCT;

 

The data is passed via data_ptr, and send to the socket task via sys_mbox_post.

Now my question:

How do you know that the data you pointed to in data_ptr has been send?
Since the WS_send function returns before the data has been send, how do I know when the data pointed to via data_ptr can be invalidated?

 

Do I put the data on the stack?

 

uint8_t data_to_send[2] = {..};
WS_USER_CONTEXT_STRUCT c;
c.data.data_ptr = data_to_send;
WS_send(&c);

 

Do I malloc it?

Or I'm I missing a point here?

Clearly, I need to manage the data correctly to make sure that the websocket is not using an old pointer to transmit data.

Thanks for you feedback,

Jonathan.

Labels (1)
0 Kudos
Reply
1 Reply

1,129 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Jonathan, 

The error checking is done through callbacks, the one that you need is ws_echo_error. For this callback to work properly, you will need to activate the DEBUG_WS macro. 

Regards,
Victor 

0 Kudos
Reply