Skip to content

Commit

Permalink
Let the OS choose the server port whenever it's not given.
Browse files Browse the repository at this point in the history
This was already the case when no configuration file was provided,
the behavior is now extended to the configuration files where the port
is not given.
This is needed to be able to run tests that use config files in parallel
reliably.
  • Loading branch information
Juan Hernando committed Oct 27, 2015
1 parent 594998e commit 41db4c1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
34 changes: 15 additions & 19 deletions eq/fabric/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,27 @@ bool Client::connectServer( co::NodePtr server )
if( server->isConnected( ))
return true;

co::ConnectionDescriptionPtr connDesc;
if( server->getConnectionDescriptions().empty( ))
if( !server->getConnectionDescriptions().empty( ))
return connect( server );

co::ConnectionDescriptionPtr connDesc( new co::ConnectionDescription );
connDesc->port = EQ_DEFAULT_PORT;
const std::string& globalServer = Global::getServer();
const char* envServer = getenv( "EQ_SERVER" );
std::string address = !globalServer.empty() ? globalServer :
envServer ? envServer : "localhost";
if( !connDesc->fromString( address ))
{
connDesc = new co::ConnectionDescription;
connDesc->port = EQ_DEFAULT_PORT;

const std::string& globalServer = Global::getServer();
const char* envServer = getenv( "EQ_SERVER" );
std::string address = !globalServer.empty() ? globalServer :
envServer ? envServer : "localhost";

if( !connDesc->fromString( address ))
LBWARN << "Can't parse server address " << address << std::endl;
LBASSERT( address.empty( ));
LBDEBUG << "Connecting server " << connDesc->toString() << std::endl;

server->addConnectionDescription( connDesc );
LBWARN << "Can't parse server address " << address << std::endl;
return false;
}
LBDEBUG << "Connecting server " << connDesc->toString() << std::endl;
server->addConnectionDescription( connDesc );

if( connect( server ))
return true;

if( connDesc ) // clean up
server->removeConnectionDescription( connDesc );

server->removeConnectionDescription( connDesc );
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion eq/fabric/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# define EQ_DEFAULT_PORT (4242)
#else
// #241: Avoid using privilege ports below 1024
# define EQ_DEFAULT_PORT ( (getuid() % 64511) + 1024 )
# define EQ_DEFAULT_PORT (( getuid() % 64511 ) + 1024 )
#endif

namespace eq
Expand Down
2 changes: 1 addition & 1 deletion eq/server/convert11Visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ConvertTo11Visitor : public ServerVisitor
LBINFO << "Adding default server connection for multi-node config"
<< std::endl;
co::ConnectionDescriptionPtr desc = new co::ConnectionDescription;
desc->port = EQ_DEFAULT_PORT;
desc->port = 0; // Let the OS choose the port.
server->addConnectionDescription( desc );
}
return TRAVERSE_CONTINUE;
Expand Down
2 changes: 1 addition & 1 deletion eq/server/loader.y
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ serverConnection: EQTOKEN_CONNECTION
'{' {
connectionDescription = new eq::server::ConnectionDescription;
connectionDescription->setHostname( "" );
connectionDescription->port = EQ_DEFAULT_PORT;
connectionDescription->port = 0; // OS chosen port
}
connectionFields '}'
{
Expand Down
4 changes: 2 additions & 2 deletions tools/server/eqServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
* by the Free Software Foundation.
*
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Expand Down

0 comments on commit 41db4c1

Please sign in to comment.