473,230 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

select call is timing out? im stumped

ok ill start off with a little background. I work for a company which makes heavy duty wireless routers/bridges, which work over long distances. Up to 30miles. Now each of our units comes with a scan utility, which can be used to default and change the ip of units. A quick example, say your on a network of You obviously wont be able to comminicate with our unit on your network if the units ip is The scan utility uses broadcasts to let recieve info about the unit and let you change a few things so that you will be able to connect to it. I hope thats clear enough.

Now, im working on a linux version of the client side scan utility. Now what this does is bind a udp socket to each network card installed on the computer. It then procedes to send broadcast probes out each socket.

My problem is in the thread which waits to recieve a probe response from our units when they recieve a broadcast. Im using select() to wait for a response on one of those sockets and then respond. Ive used a packet capture program to capture the packets, so I know that the probe goes out, and the unit sends the appropriate response back to the computer. So the select call should show that their is information waiting on whichever socket it came in on. However it times out instead. About 3/4 of the time this works fine. Heres the code for the problem area.
Expand|Select|Wrap|Line Numbers
  1.         FD_ZERO(&readSet);                      
  2.         NumOfSockets = maxSocket = 0;
  3.         for(int i=0; i<6; i++)            // get all valid sockets from socket array
  4.         {                                       // and add them to select call
  5.             if(socketDescriptor[i] != 0x0)
  6.             {
  7.                 FD_SET(socketDescriptor[i], &readSet);
  8.                 NumOfSockets++;
  9.                 if(maxSocket<socketDescriptor[i])
  10.                 {
  11.                     maxSocket = socketDescriptor[i];
  12.                 }
  13.             }
  14.         }
  15.         time.tv_sec = 1;
  16.         time.tv_usec = 0;
  17.         // wait up to 1 second for a response from the unit
  18.         active = select(maxSocket+1, &readSet, NULL, NULL, &time);
  19.         if (active > 0) 
  20.         {
  21.             UnitDetected=1;
  22.             for(int i=0; i<6; i++)
  23.             {
  24.                 if(socketDescriptor[i]==0)//added to handle a bug which occured if the first nic didnt have a unit attached
  25.                 {
  26.                     continue;
  27.                 }
  28.                 else if (FD_ISSET(socketDescriptor[i], &readSet))
  29.                 {
  30.                     UnitDetected=1;        // if a unit responds, turn this flag on
  31.                       if (recv(socketDescriptor[i], buf, MAX_LINE, 0) < 0) 
  32.                 {    
  33.                         perror("Recv info: ");
  34.                         continue;
  35.                 }
  36.                                   test = (A_UINT16 *)buf;
  37.                                   if(ntohs(*test)==PROBE_RESPONSE_MSG)
  38.                                   {
  39.                                              // does stuff, when probe is recieved.
  40.                                   }
  41.                                   else if(ntohs(*test)==COMMAND_RESPONSE_MSG)
  42.                                   {
  43.                                   // does stuff when a command response is recieved
  44.                                   }
  45.                                   else
  46.                                   {
  47.                         cout << "Invalid unit response" << endl;
  48.                         ProbeRDY = 0;    //set flag off
  49.                         CmdRDY = 0;        //set flag off
  50.                     }
  51.             }
  52.         }
  53.         else if (active == 0)
  54.         {
  55.             cerr << "Select call timed out . . ." << endl;
  56.             ProbeRDY = 0;
  57.             CmdRDY = 0;
  58.         }
  59.         else
  60.         {
  61.             perror("select: ");
  62.                 UnitDetected = 0;
  63.             ProbeRDY = 0;
  64.             CmdRDY = 0;
  65.         }
  66.     }

Sorry for the length! I tried to shorten it as much as possible. Any idea's or possible work arounds would be helpfull, thanks!
Aug 24 '06 #1
2 3849
i added some code to double check that each socket is actually timing out, in the part that handles timeouts in the above code. So far that seems like its solved the problem, but i havent had time to really test it yet. It seems to me like the select call has a few problems. I might just write my own select method to simplify things if it is a problem with select()
Aug 25 '06 #2
Hi Ashaman0,

does select parameter 'readSet' in your sample contains the data it receives from the socket? Am a bit confuse about this function. I really need help.

Jan 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: pbbriggs | last post by:
I will try to be as descriptive as possible, but this error has me stumped and I am not sure what relevant info to include.... I am running Access XP on a Windows XP machine. I initially began...
by: Terencetrent | last post by:
I having been using Access '97/2002 for about 4 years now and have never really had the need or the time to learn visual basic. Well, I think the time has finally come. I need help with Visual...
by: David | last post by:
I am using ADO to run some SQL statements in Access. First, I run query to create a table using SELECT . . . INTO Table A. Then, I run a query to SELECT . . . FROM Table A to get some data and...
by: Brian | last post by:
Hello all - I am trying to Insert a new record to an Access 2002 database. Following the insert, I need to obtain the primary key of the inserted row (person_ID) which is an Autonumber field. I...
by: C.Joseph Drayton | last post by:
I have a problem that I am hoping someone can help me with. First let me describe the problem. I have an HTML form that in one field has an onBlur call to a JavaScript function. When you exit the...
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option...
by: Ron Garret | last post by:
Here's my code. It's a teeny weeny little HTTP server. (I'm not really trying to reinvent the wheel here. What I'm really doing is writing a dispatching proxy server, but this is the shortest...
by: Richard Cranium | last post by:
Hello, I have an interesting problem: I've got one thread in my program meant to maintain a timing subsystem and to do network I/O. It uses the select() system call to either wait for I/O or...
by: BD | last post by:
Hi, all. My background is more Oracle than db2. My skills at SQL tuning are quite limited. I'm running 8.2 on Windows. I'm tasked with some SQL optimization, and am doing some explain plans...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.