Is it ok to call accept() in a child task that did NOT create the listening socket?

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it ok to call accept() in a child task that did NOT create the listening socket?

Jump to solution
241 Views
theJoel
Contributor III

Is it ok to call accept() in a child task that did NOT create the listening socket?

The MQX example code I've seen for daemon type servers (a server task (daemon) owns the listening socket and spawns a child task to connect with new clients) always has the server task accept() the connection. Then the server task calls RTCS_detachsock() before spawning the child task, which calls RTCS_attachsock().

Are the RTCS_attachsock() and RTCS_detachsock() calls strictly necessary? Can the child task call accept() with the handle of the listening socket? It seems like this would automatically give ownership of the new socket to the child. But, I'm anticipating some kind of gotcha...

Cheers,

+Joel.

Labels (1)
0 Kudos
1 Solution
86 Views
Garabo
NXP TechSupport
NXP TechSupport

Hi Joel,

Well,

The function RTCS_detachsock() removes the calling task from the socket’s list of owners. The RTCS_attachsock() adds the calling task to the socket’s list of owners.

For sure you could move the accept() to the child. To do this you will then listen for the socket activities. This can be done with the RTCS_selectall() or RTCS_selectset(). After the activity is presented you can then spam the child, pass the socket as a parameter and then you should be able to perform the accept.

Hope this answer your question.


Have a great day,
Garabo

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
3 Replies
87 Views
Garabo
NXP TechSupport
NXP TechSupport

Hi Joel,

Well,

The function RTCS_detachsock() removes the calling task from the socket’s list of owners. The RTCS_attachsock() adds the calling task to the socket’s list of owners.

For sure you could move the accept() to the child. To do this you will then listen for the socket activities. This can be done with the RTCS_selectall() or RTCS_selectset(). After the activity is presented you can then spam the child, pass the socket as a parameter and then you should be able to perform the accept.

Hope this answer your question.


Have a great day,
Garabo

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
86 Views
theJoel
Contributor III

Great! Thanks.

I don't expect the attach/detach has a lot of overhead, but for this style of server (listen(), then spawn child) I don't see a good reason to not let the child do the accept() directly.

Cheers,

+Joel.

86 Views
Garabo
NXP TechSupport
NXP TechSupport

Hi Joel,

Sure, every implementation has it's specific requirements. If it works better for you then you have no issues moving the accept() call.

Good luck!

Have a great day,
Garabo

0 Kudos