diff options
Diffstat (limited to 'src/net/connectionhandler.cpp')
-rw-r--r-- | src/net/connectionhandler.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp index 4edb1fd2..ee98a18b 100644 --- a/src/net/connectionhandler.cpp +++ b/src/net/connectionhandler.cpp @@ -36,16 +36,20 @@ #endif bool ConnectionHandler::startListen(enet_uint16 port, - const std::string &listenHost) + const std::string &hostname) { + // Remember unresolved host for debugging purposes. + this->hostname = hostname; + // Bind the server to the default localhost. + ENetAddress address; address.host = ENET_HOST_ANY; address.port = port; - if (!listenHost.empty()) - enet_address_set_host(&address, listenHost.c_str()); + if (!hostname.empty()) + enet_address_set_host(&address, hostname.c_str()); - LOG_INFO("Listening on " << listenHost << ":" << port << "..."); + LOG_INFO("Listening on " << hostname << ":" << port << "..."); #if defined(ENET_VERSION) && ENET_VERSION >= ENET_CUTOFF host = enet_host_create( &address /* the address to bind the server host to */, @@ -86,6 +90,11 @@ void ConnectionHandler::stopListen() // FIXME: memory leak on NetComputers } +enet_uint16 ConnectionHandler::getPort() const +{ + return host ? host->address.port : 0; +} + void ConnectionHandler::flush() { enet_host_flush(host); @@ -93,9 +102,11 @@ void ConnectionHandler::flush() void ConnectionHandler::process(enet_uint32 timeout) { + enet_host_service(host, nullptr, timeout); + ENetEvent event; // Process Enet events and do not block. - while (enet_host_service(host, &event, timeout) > 0) { + while (enet_host_check_events(host, &event) > 0) { switch (event.type) { case ENET_EVENT_TYPE_CONNECT: { |