473,799 Members | 3,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select call is timing out? im stumped

7 New Member
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 192.168.100.0. You obviously wont be able to comminicate with our unit on your network if the units ip is 206.71.186.46. 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 3870
Ashaman0
7 New Member
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
montzter
15 New Member
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.

Thanks
Jan 19 '07 #3

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

Similar topics

3
2399
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 developing an app in Access 2000 but converted it several months ago to XP. So the app is now Access XP format also. My app is crashing on a regular basis, with the totally non-descript Microsoft error (Microsoft Access has encountered a...
4
2830
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 Basic code that will examine numeric value for a particular field in a query, and assign a new numeric vaule to that field. There are over 21 possible values and I am told that IIF statement will only handle 9 of the possibilities and that I need...
6
1720
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 the table is empty. This appears to be a timing issue because the second query works when I run it in ACCESS instead of in VB following the first statement.
7
4105
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 am using the following code (obtained from MSDN) to do this, but for some reason a value of 0 is returned. Why is 0 returned???? Dim newID As Integer = 0
7
10982
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 field, it calls the JavaScript routine, which in turn calls a PHP script. The PHP script runs returns the value needed. And returns to the JavaScript. The JavaScript function is then supposed to set alerts depending on the values returned from...
4
2278
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 value="2">2</option>
18
1513
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 way to illustrate the problem I'm having): from SocketServer import * from socket import * from select import select class myHandler(StreamRequestHandler):
2
3408
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 "time out" and "handle" some arbitrary "event". The timeout value for select() is calculated off of a list of "active timers" which contains all the necessary information to correctly guess
2
2501
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 on various queries.
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.