Skip to content

Commit

Permalink
Removed EQ_DEFAULT_PORT
Browse files Browse the repository at this point in the history
The OS will always choose the server port.
This is needed to be able to run tests that use config files in parallel
reliably. This change also removes a spurious error trying to connect
to the default port, where no server will be listening anymore.
  • Loading branch information
Juan Hernando committed Oct 26, 2015
1 parent 594998e commit ee6a861
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
33 changes: 16 additions & 17 deletions eq/fabric/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,30 @@ bool Client::connectServer( co::NodePtr server )
if( server->isConnected( ))
return true;

co::ConnectionDescriptionPtr connDesc;
if( server->getConnectionDescriptions().empty( ))
{
connDesc = new co::ConnectionDescription;
connDesc->port = EQ_DEFAULT_PORT;
if( !server->getConnectionDescriptions().empty( ))
return connect( server );

const std::string& globalServer = Global::getServer();
const char* envServer = getenv( "EQ_SERVER" );

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

if( !connDesc->fromString( address ))
LBWARN << "Can't parse server address " << address << std::endl;
LBASSERT( address.empty( ));
LBDEBUG << "Connecting server " << connDesc->toString() << std::endl;
co::ConnectionDescriptionPtr connDesc( new co::ConnectionDescription );
std::string address = !globalServer.empty() ? globalServer : envServer;

server->addConnectionDescription( connDesc );
if( !connDesc->fromString( address ))
{
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
7 changes: 0 additions & 7 deletions eq/fabric/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
#include <lunchbox/uint128_t.h>
#include <lunchbox/visitorResult.h>

#ifdef _WIN32
# define EQ_DEFAULT_PORT (4242)
#else
// #241: Avoid using privilege ports below 1024
# define EQ_DEFAULT_PORT ( (getuid() % 64511) + 1024 )
#endif

namespace eq
{
namespace fabric
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
6 changes: 6 additions & 0 deletions tools/server/eqServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
compound { channel \"channel\" wall { bottom_left [ -.8 -.5 -1 ] \
bottom_right [ .8 -.5 -1 ] \
top_left [ -.8 .5 -1 ] }}}}"
#ifdef _WIN32
# define EQ_DEFAULT_PORT (4242)
#else
// #241: Avoid using privilege ports below 1024
# define EQ_DEFAULT_PORT ( (getuid() % 64511) + 1024 )
#endif

int main( const int argc, char** argv )
{
Expand Down

0 comments on commit ee6a861

Please sign in to comment.