C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 02-15-2005, 07:39 PM   #1
Registered User
 
Join Date: Sep 2003
Posts: 224
How select() works

Hello,
Can someone please explain to me how select() works? I don't understand how it handles multiple sockets. In fact, I don't understand how multiple clients can log onto to a server that only uses select() to handle the clients.

This is in relation to my DNS Message Format topic.
Thanks,
Yasir
Yasir_Malik is offline   Reply With Quote
Old 02-15-2005, 08:15 PM   #2
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
http://www.ecst.csuchico.edu/~beej/g...ed.html#select

Basically you setup a list of sockets to monitor. you then call select with this list as a parameter. select() simply checks to see if its avialable to be written to or read from depending on which parameter it is. If it is, it modifies the list and checks the next socket in the list.

When select is done you then step through the list and check to see if a particular socket is avialable and if it is you do whatever operator you wanna do.
Thantos is offline   Reply With Quote
Old 02-17-2005, 10:17 PM   #3
the lowly newb
 
Join Date: Jan 2005
Location: IL
Posts: 49
is select non-blocking, and does it work in windows?
__________________
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life."

"They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance."

"Light thinks it travels faster than anything but it is wrong. No matter how fast light travels, it finds the darkness has always got there first, and is waiting for it."
[all]- Terry Pratchett
variable is offline   Reply With Quote
Old 02-17-2005, 10:35 PM   #4
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
select has a time out parameter. So technically it is blocking while its executing you can setup a low time out so it doesn't block for too long

It does work in windows.
Thantos is offline   Reply With Quote
Old 02-18-2005, 03:34 AM   #5
Registered User
 
Join Date: Dec 2004
Posts: 95
*But there's better, more elegant methods available on Windows - select() is essentially there for portability.
azteched is offline   Reply With Quote
Old 02-18-2005, 03:54 AM   #6
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,657
> It does work in windows.
But it only works on socket descriptors.
The Unix/Linux version of select works on any descriptor (eg. stdin)
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 02-18-2005, 07:46 AM   #7
the lowly newb
 
Join Date: Jan 2005
Location: IL
Posts: 49
ah, ok; then would it be better to use asynchronous sockets winsock. if so, could someone send me a link to asynchonous winsock sockets. i read those beej tutorials, but he seems to concentrate on linux so no winsock.

thanks
__________________
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life."

"They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance."

"Light thinks it travels faster than anything but it is wrong. No matter how fast light travels, it finds the darkness has always got there first, and is waiting for it."
[all]- Terry Pratchett
variable is offline   Reply With Quote
Old 02-18-2005, 11:02 AM   #8
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
Look at the links page at the top of the forum.
Thantos is offline   Reply With Quote
Old 03-05-2005, 10:50 AM   #9
Registered User
 
Join Date: Sep 2003
Posts: 224
I've used select() to monitor file descriptors ready for reading. I can't think of an example where I would monitor sockets ready for writing. Can someone please give me an example?

Thanks,
Yasir
Yasir_Malik is offline   Reply With Quote
Old 03-05-2005, 10:56 AM   #10
Registered User
 
Join Date: Dec 2004
Posts: 95
When using non-blocking sockets, you'd monitor via select() or whatever, because there's no point in looping waiting for send() not to fail with EWOULDBLOCK.
azteched is offline   Reply With Quote
Old 03-05-2005, 04:13 PM   #11
* Death to Visual Basic *
 
Devil Panther's Avatar
 
Join Date: Aug 2001
Posts: 768
Quote:
select has a time out parameter. So technically it is blocking while its executing you can setup a low time out so it doesn't block for too long

Can someone please post some code on how to setup the timeout value?

Thank you.
__________________
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

http://www.Bloodware.net - Developing free software for the community.
Devil Panther is offline   Reply With Quote
Old 03-05-2005, 04:30 PM   #12
C++ Beginner
 
Join Date: Sep 2004
Posts: 136
Beej gives great examples on how to use the timout parameter in slect() -- look in his site.
Kybo_Ren is offline   Reply With Quote
Old 03-05-2005, 06:40 PM   #13
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
man select
Thantos is offline   Reply With Quote
Old 03-06-2005, 12:48 AM   #14
* Death to Visual Basic *
 
Devil Panther's Avatar
 
Join Date: Aug 2001
Posts: 768
you were talking only about the select() timeout?!

I thought you were talking about sockets in general, because I really need to find a way to set a timeout for connect()... that default one minute is killing me.

oh well, thanks anyway.
__________________
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

http://www.Bloodware.net - Developing free software for the community.
Devil Panther is offline   Reply With Quote
Old 03-06-2005, 04:54 AM   #15
Registered User
 
Join Date: Dec 2004
Posts: 95
Make the socket non-blocking?
azteched is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in select() in a Multiprotocol client zealot Networking/Device Communication 2 04-09-2009 12:45 PM
select and EINTR mynickmynick C Programming 6 07-29-2008 05:03 AM
What would I use in place of select() Overworked_PhD Linux Programming 3 06-21-2008 12:50 PM
Directional Keys - Useing in Console RoD C++ Programming 38 10-06-2002 04:42 PM
scandir select function dsl24 C Programming 3 04-12-2002 10:58 AM


All times are GMT -6. The time now is 05:06 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22