LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linux Sockets (https://www.linuxquestions.org/questions/programming-9/linux-sockets-254560/)

JanusPaul 11-13-2004 10:29 PM

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

itsme86 11-13-2004 11:50 PM

There are socket libraries that work that way, but first you should make sure that's really the best method for your particular task.

JanusPaul 11-14-2004 12:01 AM

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.

itsme86 11-14-2004 03:33 AM

Check out the select() function. It can wait forever waiting for data to be available. No wasted CPU cycles.

Hko 11-14-2004 10:33 AM

Select() is a bit complex, so you may want to read "man 2 select_tut" which is a tutorial for select() and includes examples.

JanusPaul 11-14-2004 11:44 AM

Sweet, O.o, thanks for the help *checks select() out*


All times are GMT -5. The time now is 10:47 PM.