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.getBuffer STDIN() ==
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.getBuffer STDIN() ==
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(listen er, &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(listen er, &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. 1 2718
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.progr ammer. 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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 example below.
1-) Adding "Unknown" to a reference table is bad. Doing so effectively
changes the Nullability option of every FK that references the table to
a NULLable FK relation.
2-) Simply adding a "Not Known/Undetermined" value to the...
|
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 (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
|
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 as a valid return value for the typeof
operator in a later version of ECMAScript or is this a JScript "feature"?
--
Klaus Johannes Rusch
|
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
of 'fd_set'
| |
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" java.lang.NullPointerException
at test$myFreakingListener.actionPerformed(test.java:34)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
|
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
it issued this warning for that line number:
|
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) <Error/3Unknown Directive type "toctree"
(2) (ERROR/3) Unknown interpreted text role "ref".
|
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 and open an unknown workbook that contains the data that I need to imput into my current workbook, once the unknown workbook is opened it should automatically select my range (number of columns known, but number of rows unknown- the number of rows...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |