Closing TCP connections

Discussion to talk about software related topics only.
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Closing TCP connections

Post by TomNB »

I don't quite understand what you are getting at in that paragraph, but I can tell you how I architect my code when using multiple sockets. I create a separate task with the select() call in it. select() only blocks when there is no activity, so it does not slow anything down, and all my other tasks run at full speed as well. Of course if your application has only one task and you use select(), it will block that task. So I use a combination of multiple tasks and one task that handles select().

The way select works is that it is a bit mask. Before calling select() you set the bits you want to monitor using FD_SET. FD_CLR, etc. Once select() returns that bit mask variable now contains the results, so you test the bit mask with FD_ISSET, etc. Before you call select() again, you need to clear and set the appropriate bits you want to monitor.

When you say that in your case you cannot use any functions that block and are using the low level functions you describe, it makes me wonder if there is some way it could be architected differently. If there is no such way, then is suppose the way you are doing it would be the best path.
Post Reply