Wake thread on TCP packet recieve

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
cohuc_3807591
Level 3
Level 3
5 likes given First like given

I have an application that will receive infrequent commands over at TCP connection. I was wondering if there was a way to have a thread that handles the packet wake up at a packet reception event? The only packets it will receive will be commands, so the thread could wake up at any packet, not just TCP.

Follow up - is there an API to allow for explicit wakeup/send to sleep of a created thread?

Thanks!

0 Likes
1 Solution

Use asynchronous callbacks instead of busy loop to receive data.

You can reference tcp_server_async snip code as reference.

View solution in original post

4 Replies
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

hello:

< have a thread that handles the packet wake up at a packet reception event.  >

for this line:    Do you mean: 1. our board is in sleep mode.

                                              2.  keep the connection, will receive TCP packet from other client .

                                            3.  a packet reception event will wake up the board, then deal with all the packets?

Hi ZhengbaoZ_96​, thanks for the reply and follow up question.

The answer is option 2: the board will be awake and functioning - it will have other threads running and doing tasks. I just want to send the thread responsible for the TCP receive to sleep and have it be woken up by the (VERY infrequent) command packets.

0 Likes

Use asynchronous callbacks instead of busy loop to receive data.

You can reference tcp_server_async snip code as reference.

Exactly what I needed, thanks axel.lin_1746341

0 Likes