[Orxonox-commit 2697] r7402 - code/branches/ipv6/src/libraries/network
adrfried at orxonox.net
adrfried at orxonox.net
Sat Sep 11 02:31:40 CEST 2010
Author: adrfried
Date: 2010-09-11 02:31:39 +0200 (Sat, 11 Sep 2010)
New Revision: 7402
Modified:
code/branches/ipv6/src/libraries/network/ClientConnection.cc
code/branches/ipv6/src/libraries/network/LANDiscoverable.cc
code/branches/ipv6/src/libraries/network/LANDiscovery.cc
code/branches/ipv6/src/libraries/network/ServerConnection.cc
Log:
add some error messages in orxonox network code
Modified: code/branches/ipv6/src/libraries/network/ClientConnection.cc
===================================================================
--- code/branches/ipv6/src/libraries/network/ClientConnection.cc 2010-09-10 22:34:00 UTC (rev 7401)
+++ code/branches/ipv6/src/libraries/network/ClientConnection.cc 2010-09-11 00:31:39 UTC (rev 7402)
@@ -47,7 +47,7 @@
{
this->serverAddress_ = new ENetAddress();
//set standard address and port
- enet_address_set_host(this->serverAddress_, "127.0.0.1");
+ enet_address_set_host(this->serverAddress_, "127.0.0.1"); // TODO: check for IPv6 and connect to ::1 instead
serverAddress_->port = NETWORK_PORT;
}
@@ -58,7 +58,8 @@
}
void ClientConnection::setServerAddress( const std::string& serverAddress ) {
- enet_address_set_host (this->serverAddress_, serverAddress.c_str());
+ if (enet_address_set_host (this->serverAddress_, serverAddress.c_str()) < 0)
+ COUT(1) << "Error: Could not resolve \"" << serverAddress << "\"." << std::endl;
}
void ClientConnection::setPort( unsigned int port ) {
@@ -72,14 +73,22 @@
this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0, 0);
if ( this->host_ == NULL )
{
- COUT(2) << "ClientConnection: host_ == NULL" << std::endl;
+ COUT(1) << "ClientConnection: host_ == NULL" << std::endl;
// error handling
return false;
}
+ assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
+ if (this->host_->socket4 == ENET_SOCKET_NULL)
+ COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
+ else if (this->host_->socket6 == ENET_SOCKET_NULL)
+ COUT(2) << "Warning: IPv6 Socket failed." << std::endl;
+ else
+ COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
+
this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS, 0);
if ( this->server_==NULL )
{
- COUT(2) << "ClientConnection: server == NULL" << std::endl;
+ COUT(1) << "ClientConnection: server_ == NULL" << std::endl;
// error handling
return false;
}
Modified: code/branches/ipv6/src/libraries/network/LANDiscoverable.cc
===================================================================
--- code/branches/ipv6/src/libraries/network/LANDiscoverable.cc 2010-09-10 22:34:00 UTC (rev 7401)
+++ code/branches/ipv6/src/libraries/network/LANDiscoverable.cc 2010-09-11 00:31:39 UTC (rev 7402)
@@ -69,6 +69,8 @@
bindAddress.port = LAN_DISCOVERY_PORT;
assert( this->host_ == 0 );
this->host_ = enet_host_create( &bindAddress, 10, 0, 0, 0 );
+ if ( this->host_ == NULL )
+ COUT(1) << "LANDiscoverable: host_ == NULL" << std::endl;
}
else
{
Modified: code/branches/ipv6/src/libraries/network/LANDiscovery.cc
===================================================================
--- code/branches/ipv6/src/libraries/network/LANDiscovery.cc 2010-09-10 22:34:00 UTC (rev 7401)
+++ code/branches/ipv6/src/libraries/network/LANDiscovery.cc 2010-09-11 00:31:39 UTC (rev 7402)
@@ -42,6 +42,8 @@
LANDiscovery::LANDiscovery()
{
this->host_ = enet_host_create(NULL, 10, 0, 0, 0 );
+ if ( this->host_ == NULL )
+ COUT(1) << "LANDiscovery: host_ == NULL" << std::endl;
}
LANDiscovery::~LANDiscovery()
@@ -61,10 +63,14 @@
/* IPv4 */
address.host = ENET_HOST_BROADCAST;
peer = enet_host_connect(this->host_, &address, 0, 0);
+ if (peer == NULL)
+ COUT(1) << "Error: Could not send LAN discovery to IPv4 Broadcast." << std::endl;
/* IPv6 */
enet_address_set_host(&address, "ff02::1"); // TODO: use a multicast group
peer = enet_host_connect(this->host_, &address, 0, 0);
+ if (peer == NULL)
+ COUT(1) << "Error: Could not send LAN discovery to IPv6 Multicast." << std::endl;
ENetEvent event;
while( enet_host_service(this->host_, &event, 1000 ) )
Modified: code/branches/ipv6/src/libraries/network/ServerConnection.cc
===================================================================
--- code/branches/ipv6/src/libraries/network/ServerConnection.cc 2010-09-10 22:34:00 UTC (rev 7401)
+++ code/branches/ipv6/src/libraries/network/ServerConnection.cc 2010-09-11 00:31:39 UTC (rev 7402)
@@ -55,7 +55,8 @@
}
void ServerConnection::setBindAddress( const std::string& bindAddress ) {
- enet_address_set_host (this->bindAddress_, bindAddress.c_str());
+ if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
+ COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl;
}
void ServerConnection::setPort( unsigned int port ) {
@@ -65,9 +66,19 @@
bool ServerConnection::openListener() {
this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0);
if ( this->host_ == NULL )
- return false;
+ {
+ COUT(1) << "ServerConnection: host_ == NULL" << std::endl;
+ return false;
+ }
+ assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
+ if (this->host_->socket4 == ENET_SOCKET_NULL)
+ COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
+ else if (this->host_->socket6 == ENET_SOCKET_NULL)
+ COUT(2) << "Warning: IPv6 Socket failed." << std::endl;
else
- return true;
+ COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
+
+ return true;
}
bool ServerConnection::closeListener() {
More information about the Orxonox-commit
mailing list