![]() |
| | #1 |
| Registered User Join Date: Sep 2003
Posts: 224
| How select() works 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 | |
| | #2 |
| & the hat of GPL slaying 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 | |
| | #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 | |
| | #4 |
| & the hat of GPL slaying 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 | |
| | #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 | |
| | #6 |
| and the hat of Jobseeking 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) |
| Salem is offline | |
| | #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 | |
| | #8 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| Look at the links page at the top of the forum. |
| Thantos is offline | |
| | #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 | |
| | #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 | |
| | #11 | |
| * Death to Visual Basic * Join Date: Aug 2001
Posts: 768
| Quote:
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 | |
| | #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 | |
| | #13 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| man select |
| Thantos is offline | |
| | #14 |
| * Death to Visual Basic * 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 | |
| | #15 |
| Registered User Join Date: Dec 2004
Posts: 95
| Make the socket non-blocking? |
| azteched is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |