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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
1,610 次查看
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.

标签 (1)
标记 (4)
0 项奖励
回复
1 解答
1,455 次查看
Luis_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!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,456 次查看
Luis_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!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
1,455 次查看
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.

1,455 次查看
Luis_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 项奖励
回复