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?

ソリューションへジャンプ
637件の閲覧回数
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 解決策
482件の閲覧回数
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 返答(返信)
483件の閲覧回数
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 件の賞賛
482件の閲覧回数
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.

482件の閲覧回数
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 件の賞賛