Is an interrupt on client connection possible?

jpan127
Posts: 8
Joined: Sat Aug 26, 2017 10:11 pm

Is an interrupt on client connection possible?

Postby jpan127 » Mon Jan 08, 2018 3:33 am

Hopefully this isn't too stupid of a question, but I was wondering if I create a TCP socket as a server, listening for connections, is there an ISR for a client connection?

I would like to have a high priority task listening for connections, blocked on a semaphore. The semaphore would give from ISR when a client attempts to connect, unblocking this task and allowing it to service the client.

Thanks!

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Is an interrupt on client connection possible?

Postby ESP_Angus » Mon Jan 08, 2018 6:08 am

Hi jpan227,

What you probably want is "select", which is the standard BSD sockets way to wait for something to happen on a socket (or group of sockets).

Unfortunately all of the ESP-IDF examples which use select() use it with UDP sockets, not TCP. However if you google you should be able to find a lot of sample code (written for Linux or similar OSes) which can be easily adapted to work in ESP-IDF.

Angus

jpan127
Posts: 8
Joined: Sat Aug 26, 2017 10:11 pm

Re: Is an interrupt on client connection possible?

Postby jpan127 » Tue Jan 09, 2018 5:14 am

Hi, thanks!

I will take a deeper look into how it works.
Off the top of your head, do you have an idea of how it can be used? It seems like I would still need to poll for select() right?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Is an interrupt on client connection possible?

Postby ESP_Angus » Tue Jan 09, 2018 11:23 pm

jpan127 wrote:Hi, thanks!

I will take a deeper look into how it works.
Off the top of your head, do you have an idea of how it can be used?
Sure, here's some basic demo code. Copy it over main/main.c in the idf-template repo to build it:
https://gist.github.com/projectgus/9e62 ... cad4a155ba

This is mostly cribbed from the the Wikipedia BSD sockets server example. It will need some extending to (for example) support multiple concurrent connections, but BSD sockets programming is well documented.
It seems like I would still need to poll for select() right?
No. select() allows you to suspend the task until one of the sockets you are waiting on is ready (or until an optional timeout expires).

jpan127
Posts: 8
Joined: Sat Aug 26, 2017 10:11 pm

Re: Is an interrupt on client connection possible?

Postby jpan127 » Wed Jan 10, 2018 4:23 am

Oh wow that is awesome. How does this interact with freertos? What if the task is the lowest priority? Does it work the same way as a semaphore?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Is an interrupt on client connection possible?

Postby ESP_Angus » Wed Jan 10, 2018 5:24 am

jpan127 wrote:Oh wow that is awesome. How does this interact with freertos? What if the task is the lowest priority? Does it work the same way as a semaphore?
Yes, internally select() is in fact blocking on a semaphore. The calling task's priority will determine if it preempts other tasks or not, when data is available.

Note that TCP/IP stack handling also happens in a task, so you should orient any priorities relative to the TCP/IP task priority (ESP_TASK_TCPIP_PRIO ie 18). TCP/IP task can migrate between the two cores.

jpan127
Posts: 8
Joined: Sat Aug 26, 2017 10:11 pm

Re: Is an interrupt on client connection possible?

Postby jpan127 » Thu Jan 11, 2018 4:39 am

Ah, thank you so much, you've been a lot of help!

Who is online

Users browsing this forum: No registered users and 113 guests