473,500 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FD_SET has unknown sockfd

FD_SET( listener, &master );
fdmax = listener;
FD_ZERO( &readfds );
FD_ZERO( &master );
FD_SET( STDIN, &master ); // STDIN is now among the set of fds that
we pool for incoming data
FD_SET( listener, &master );
fdmax = listener;

for ( ;; ) {

if ( !FD_ISSET( STDIN, &master) && (peer.getBufferSTDIN() ==
false) ) {
FD_SET( STDIN, &master );
if ( fdmax < STDIN ) {
fdmax = STDIN;
cout << "fdmax < STDIN" << endl;
}
}
readfds = master; // since readfds change with every select,
// copy master into readfds to tell
select() which sockets we are
// interested in

// select returns the number of descriptors contained in the
descriptor sets
numFDInSet = select( fdmax+1, &readfds, NULL, NULL, &tv );
// ...
for ( int i = 0; i < fdmax + 1; i++ ) {
if (FD_ISSET(i, &readfds)) { // data coming in
from either STDIN or sockfds
if ( i == STDIN && (peer.getBufferSTDIN() ==
false) ) {
// ...
}
else if ( i == listener ) {
cout << "listener has sockfd:" << listener << endl;
// ...
}
else if ( i == sockfd ) {
FD_CLR( sockfd, &master );
if ( close(sockfd) != 0 )
{
cerr << "Error closing gossip
reply socket" << strerror(errno) << endl;
}
// ...
sockfd = peer.gossip( peerInfo );
FD_SET( sockfd, &master);
if ( fdmax < sockfd ) {
fdmax = sockfd;
}
else {
// ...
FD_CLR( sockfd, &master );
if ( close(sockfd) != 0 ) {
$
cerr << "Error closing
gossip reply socket" << strerror(errno) << endl; $
}

//...
sockfd = peer.gossip( peerInfo );
$
FD_SET( sockfd, &master);
if ( fdmax < sockfd ) {
fdmax = sockfd;
}
}
}
else {
// ...
FD_CLR( sockfd, &master );
if ( close(sockfd) != 0 ) {
cerr << "Error closing gossip
reply socket" << strerror(errno) << endl; $
}
}// else
}
else {
cout << endl << "received input from unknown
socket: " << i << endl << endl;

if ( FD_ISSET(listener, &readfds) ) {
cout << "listener socket " << i << " is in
the FD_SET, listener is socket " << listener << en$
}
else {
cout << "listener is not in the set" <<
endl;
}
}//else

My questions:
#1) Now focus on the last section. listener prints 5 (i.e. I am
always listening on socket 5), but I somehow got input coming in from
socket 7. I have not explicitly add socket 7 (i.e. i == 7) to my FD_SET.
How did socket 7 get added to FD_SET?

#2) Even more strangely, FD_ISSET(listener, &readfds) returns true,
meaning that listener (aka socket 5) is in my FD_SET. But if listener is
in my FD_SET, the case (i == listener) would have been executed; but
instead the control falls through to the else clause in #1.
Can you please explain this why the else clause is executed instead of (i
== listener)?

Thanks for your help. Any suggestion for a fix (i.e. I intend to listen
on socket 5 [ aka listener] for incoming input) is appreciated.

Jul 23 '05 #1
1 2709
William schrieb:
[spaghetti code snipped]
My questions:
#1) Now focus on the last section. listener prints 5 (i.e. I am
always listening on socket 5), but I somehow got input coming in from
socket 7. I have not explicitly add socket 7 (i.e. i == 7) to my FD_SET.
How did socket 7 get added to FD_SET?


Hard to tell from the code. I'd start by refactoring it to remove the
excessive levels of indentation. Also it would be much more readable if
long lines were properly split and not auto-wrapped.
And then, the problem is off-topic in a C++-language newsgroup. You've
already posted it to comp.unix.programmer. If you absolutely feel the
need to post to multiple groups, then check if it's on topic in all of
them and CROSSpost, don't MULTIpost.

Cheers,
Malte
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
982
by: Eugen Walcher | last post by:
Hello All, I'm getting this error in my error_log in apache. Can anyone offer any assistance in fixing the problem? I'm using RH 9 with apache 2.0.53 and PHP v4.3.11
3
3356
by: Marcus | last post by:
I'm running into a situation that has me adding a value of "Unknown" to a reference table. I am being pulled between two trains of thought, and was curious to get other's input on in. I give an...
3
23442
by: chris | last post by:
Here is my code for the call to ioctl: for ( ; ; ) { if ( (buf = malloc(len)) == NULL) errQuit("malloc error while allocating ifconf buffer"); ifc.ifc_len = len; ifc.ifc_buf = buf; if...
9
10694
by: Klaus Johannes Rusch | last post by:
IE7 returns "unknown" instead of "undefined" when querying the type of an unknown property of an object, for example document.write(typeof window.missingproperty); Has "unknown" been defined...
1
6345
by: joret | last post by:
Hi! I work with CBuilder 6.0 and triying to use ptypes. I´m having the following error: winsock2.h(109): E2238 Multiple declaration for 'fd_set' winsock.h(54): E2344 Earlier declaration ...
1
4566
by: tactech | last post by:
Hello Can somebody help me and tell me why I can’t change the background color of the second PN2 panel. I get this error about unknown source Exception in thread "AWT-EventQueue-1"...
11
4188
by: David Mathog | last post by:
There was an editing error in one of my programs giving this line (two left parentheses, one right): FD_SET((ncmd->cmd_in_fd,&read_set); When compiled with gcc -Wall -pedantic -stc=c99 ...
2
7368
by: Calvin Cheng | last post by:
Hi, I am attempting to convert a bunch of .txt files into html using the docutils package. It works for most of the txt files except for the index.txt file which gives 2 errors: (1)...
4
4022
by: omono84 | last post by:
I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net. The aim is that I click on the open button to find...
0
7018
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...
0
7232
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...
1
6906
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...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
316
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...

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.