LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-13-2004, 10:29 PM   #1
JanusPaul
Member
 
Registered: Nov 2004
Location: Houston, Texas
Distribution: Ubuntu, Debian, Solaris, Free BSD
Posts: 82

Rep: Reputation: 15
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
 
Old 11-13-2004, 11:50 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
There are socket libraries that work that way, but first you should make sure that's really the best method for your particular task.
 
Old 11-14-2004, 12:01 AM   #3
JanusPaul
Member
 
Registered: Nov 2004
Location: Houston, Texas
Distribution: Ubuntu, Debian, Solaris, Free BSD
Posts: 82

Original Poster
Rep: Reputation: 15
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.
 
Old 11-14-2004, 03:33 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Check out the select() function. It can wait forever waiting for data to be available. No wasted CPU cycles.
 
Old 11-14-2004, 10:33 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Select() is a bit complex, so you may want to read "man 2 select_tut" which is a tutorial for select() and includes examples.
 
Old 11-14-2004, 11:44 AM   #6
JanusPaul
Member
 
Registered: Nov 2004
Location: Houston, Texas
Distribution: Ubuntu, Debian, Solaris, Free BSD
Posts: 82

Original Poster
Rep: Reputation: 15
Sweet, O.o, thanks for the help *checks select() out*
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i send a file using linux sockets?? crapodino Programming 2 10-09-2005 11:17 PM
how to sendto() on packet sockets in linux? kiba Programming 3 10-29-2003 11:46 AM
Linux sockets linlai Programming 2 07-16-2002 02:51 PM
sockets in linux 2.4.2 kernel arumash Linux - Networking 1 06-29-2002 09:21 PM
Sockets in Linux GhostBoot Linux - Networking 1 05-18-2001 12:36 PM


All times are GMT -5. The time now is 08:23 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration