Poll: Should I implement this change?
You do not have permission to vote in this poll.
Do it
100.00%
3 100.00%
Don't do it
0%
0 0%
Total 3 vote(s) 100%
* You voted for this item. [Show Results]

Threading revision in cClientHandle
#3
Actually, it gets even better, we don't need a pair of threads, we can do with just one thread for both reading and writing. I hope my thinking is correct on this one, please correct me if you find anything bad in this:

1. Put clients' sockets into the Read and Error sets (signalled when there's incoming data or the socket is lost)
2, Wait for the select() to return, with arbitrary timeout.
3, When it returns, check the sockets for incoming data, and read it.
4, If there are any packets queued for sending, perform a write-check:
5, Put all sockets into a Write set (signalled when writing is available) and call select() with zero timeout
6, Sockets that can be written to get the packets from the queue written to them
7, Go to 1 again

This should handle reading efficiently, but has a problem with writing - when a packet is queued, this loop will still wait for incoming data in step 1. So we need a way to unblock the select() call in #1. We do this by creating a loopback socket (localhost to localhost) and sending data over it , when a packet is queued. This Control socket is the reason for the "minus one" in FD_SETSIZE - 1.

Also, we need to handle socket adding and removing, this will use the same mechanism - using the Control socket to "unblock" the select() call.
Reply
Thanks given by:


Messages In This Thread
Threading revision in cClientHandle - by xoft - 02-03-2012, 07:02 PM
RE: Threading revision in cClientHandle - by xoft - 02-06-2012, 03:04 AM
RE: Threading revision in cClientHandle - by xoft - 02-08-2012, 08:10 PM
RE: Threading revision in cClientHandle - by xoft - 02-08-2012, 10:52 PM
RE: Threading revision in cClientHandle - by xoft - 02-09-2012, 03:24 AM



Users browsing this thread: 1 Guest(s)