Re: Unidentified Socket Found in FD_SET
From: Malte Starostik (malte_at_starostik.de)
Date: 03/28/05
- Previous message: William: "Unidentified Socket Found in FD_SET"
- In reply to: William: "Unidentified Socket Found in FD_SET"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Mar 2005 06:28:53 +0200
William schrieb:
> For the following code:
>
> FD_ZERO( &readfds );
> FD_ZERO( &master );
> FD_SET( STDIN, &master ); // STDIN is now among the set of fds that we pool for incoming data
STDIN is #defined to 0 I assume? There's STDIN_FILENO already.
>
> FD_SET( listener, &master );
> fdmax = listener;
>
> for ( ;; ) {
>
> if ( !FD_ISSET( STDIN, &master) && (peer.getBufferSTDIN() == false) ) {
> FD_SET( STDIN, &master );
> if ( fdmax < STDIN ) {
This won't ever be true unless listener is an invalid fd (-1)
> 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) ) {
peer.getBufferSTDIN() was already a prerequisite for STDIN to be
included in the set. Only needed if it can have changed meanwhile.
> // ...
> }
> 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 {
^^^^^ this doesn't seem to make sense
> // ...
> 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 );
^^^^^ this doesn't seem to make sense
either, as this block is not related to sockfd
> if ( close(sockfd) != 0 ) {
> cerr << "Error closing gossip reply socket" << strerror(errno) << endl;
> }
> }// else
> }
> else {
this block is reached when if(FD_ISSET(i, &readfds)) above is false
> 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 << endl;
> }
> else {
> cout << "listener is not in the set" << endl;
> }
> }//else
} // missing closing brace of for loop
I might very well have mis-counted the braces. You really should
refactor that code and see if the problem persists :-)
Cheers,
Malte
- Previous message: William: "Unidentified Socket Found in FD_SET"
- In reply to: William: "Unidentified Socket Found in FD_SET"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|