Linux Sockets
I've seen plenty of source code for an endless loop that constantly checks the SocketID for data/connections on a listening port, but is there anyway to do asyncronous sockets like Windows has? Like, where would I pass a CallBack pointer to?
Paul |
There are socket libraries that work that way, but first you should make sure that's really the best method for your particular task.
|
I think so...
Basically I want to have a single suspended thread bound/listening on port 9998, when a user connects, I would like to create for them a suspended thread, which will have a callback pointer to within the thread for the socket just for them. This is NOT for interactive gaming, the chat clients don't constantly have to send data. Therefore, having a suspended thread just waiting for a packet/async call to within the thread when they finally do send data, would prevent alot of CPU from being wasted in the meantime. I believe this beats constantly looping to check a socket for data/incoming connections.
|
Check out the select() function. It can wait forever waiting for data to be available. No wasted CPU cycles.
|
Select() is a bit complex, so you may want to read "man 2 select_tut" which is a tutorial for select() and includes examples.
|
Sweet, O.o, thanks for the help *checks select() out*
|
All times are GMT -5. The time now is 10:47 PM. |