Skip to content

Commit

Permalink
Merge pull request #504 from hernando/no_default_port
Browse files Browse the repository at this point in the history
Let the OS choose the server port when the config doesn't have one.
  • Loading branch information
eile committed Nov 3, 2015
2 parents 47b7446 + 42a4c98 commit 30c6a69
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 30c6a69

Please sign in to comment.