From: Perttu Ahola Date: Sun, 11 Mar 2012 18:45:43 +0000 (+0200) Subject: Proper handling of failing to bind server socket X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=618314985d6a632ccfd2001d969d32a5ee6e4ca1;p=zefram%2Fminetest%2Fminetest_engine.git Proper handling of failing to bind server socket --- diff --git a/src/connection.cpp b/src/connection.cpp index 60c99dc7..58a0fb2b 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -986,8 +986,16 @@ nextpeer: void Connection::serve(u16 port) { dout_con< &data) if(m_bc_peerhandler) m_bc_peerhandler->deletingPeer(&tmp, e.timeout); continue; } + case CONNEVENT_BIND_FAILED: + throw ConnectionBindFailed("Failed to bind socket " + "(port already in use?)"); } } throw NoIncomingDataException("No incoming data"); diff --git a/src/connection.h b/src/connection.h index 6d26e2e3..b793f580 100644 --- a/src/connection.h +++ b/src/connection.h @@ -59,6 +59,14 @@ public: {} }; +class ConnectionBindFailed : public BaseException +{ +public: + ConnectionBindFailed(const char *s): + BaseException(s) + {} +}; + /*class ThrottlingException : public BaseException { public: @@ -424,6 +432,7 @@ enum ConnectionEventType{ CONNEVENT_DATA_RECEIVED, CONNEVENT_PEER_ADDED, CONNEVENT_PEER_REMOVED, + CONNEVENT_BIND_FAILED, }; struct ConnectionEvent @@ -447,6 +456,8 @@ struct ConnectionEvent return "CONNEVENT_PEER_ADDED"; case CONNEVENT_PEER_REMOVED: return "CONNEVENT_PEER_REMOVED"; + case CONNEVENT_BIND_FAILED: + return "CONNEVENT_BIND_FAILED"; } return "Invalid ConnectionEvent"; } @@ -470,6 +481,10 @@ struct ConnectionEvent timeout = timeout_; address = address_; } + void bindFailed() + { + type = CONNEVENT_BIND_FAILED; + } }; enum ConnectionCommandType{ diff --git a/src/server.cpp b/src/server.cpp index 767de035..63bf794a 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -109,6 +109,10 @@ void * ServerThread::Thread() { infostream<<"Server: PeerNotFoundException"<setAsyncFatalError(e.what()); + } } END_DEBUG_EXCEPTION_HANDLER(errorstream) @@ -837,6 +841,7 @@ Server::Server( m_path_world(path_world), m_path_config(path_config), m_gamespec(gamespec), + m_async_fatal_error(""), m_env(NULL), m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this), m_authmanager(path_world+DIR_DELIM+"auth.txt"), @@ -865,6 +870,9 @@ Server::Server( m_step_dtime_mutex.Init(); m_step_dtime = 0.0; + if(path_world == "") + throw ServerError("Supplied empty world path"); + if(!gamespec.isValid()) throw ServerError("Supplied invalid gamespec"); @@ -1079,6 +1087,8 @@ Server::~Server() void Server::start(unsigned short port) { DSTACK(__FUNCTION_NAME); + infostream<<"Starting server on port "< m_async_fatal_error; + // Some timers float m_liquid_transform_timer; float m_print_info_timer;