LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-26-2009, 10:01 AM   #1
Tejesh
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: 0
socket - select() timeout problem in Linux


Hi,

I am using the socket's select() function in Linux but i am facing a
problem i.e. in the timeout condition (if server is not present to
connect) then select() function has to return zero (as per man
description) but select() will not return zero (it will not wait to
get timeout and always return non zero value not as a error). But if i
test same thing in Windows then select() will return zero in timeout
condition...


can anyone tell me is there any problem with select() function in
Linux ??
 
Old 06-04-2009, 10:28 PM   #2
jdiggitydogg
Member
 
Registered: Sep 2007
Posts: 42

Rep: Reputation: 15
there is no problem with the select implementation in Linux. it sounds like you have looked at the man page, but have you experimented with the sample code in the man page?

Why not try this and see if your select is still not returning zero on timeout?

Code:
       #include <stdio.h>
       #include <sys/time.h>
       #include <sys/types.h>
       #include <unistd.h>

       int
       main(void) {
           fd_set rfds;
           struct timeval tv;
           int retval;

           /* Watch stdin (fd 0) to see when it has input. */
           FD_ZERO(&rfds);
           FD_SET(0, &rfds);

           /* Wait up to five seconds. */
           tv.tv_sec = 5;
           tv.tv_usec = 0;

           retval = select(1, &rfds, NULL, NULL, &tv);
           /* Don’t rely on the value of tv now! */

           if (retval == -1)
               perror("select()");
           else if (retval)
               printf("Data is available now.\n");
               /* FD_ISSET(0, &rfds) will be true. */
           else
               printf("No data within five seconds.\n");

           return 0;
       }
 
Old 06-10-2009, 04:38 AM   #3
Tejesh
LQ Newbie
 
Registered: May 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for reply..

Yes I checked with the test application and it seems tobe there is no problem with select() call.. I need to dig more in my code to find the exact problem... but do you have any idea what could be the problem ?
 
  


Reply

Tags
select, socket


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fix tcp select() with non-zero timeout for redhat 4.5 vilnius Linux - Newbie 1 10-01-2008 07:44 PM
Select() did not select my socket thvo Programming 1 05-08-2005 12:20 AM
select function as timeout? frostmagic Programming 2 02-09-2004 11:56 AM


All times are GMT -5. The time now is 08:47 AM.

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
Open Source Consulting | Domain Registration