diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-03-11 20:45:43 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-03-11 20:45:43 +0200 |
commit | 618314985d6a632ccfd2001d969d32a5ee6e4ca1 (patch) | |
tree | 94faf77b08206466fb55f80448b02c557e734881 /src/connection.cpp | |
parent | d1d83d7e7f5e2e7cbef5272eda9c580129e301a3 (diff) | |
download | minetest-618314985d6a632ccfd2001d969d32a5ee6e4ca1.tar.gz minetest-618314985d6a632ccfd2001d969d32a5ee6e4ca1.tar.bz2 minetest-618314985d6a632ccfd2001d969d32a5ee6e4ca1.zip |
Proper handling of failing to bind server socket
Diffstat (limited to 'src/connection.cpp')
-rw-r--r-- | src/connection.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/connection.cpp b/src/connection.cpp index 60c99dc73..58a0fb2bd 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -986,8 +986,16 @@ nextpeer: void Connection::serve(u16 port) { dout_con<<getDesc()<<" serving at port "<<port<<std::endl; - m_socket.Bind(port); - m_peer_id = PEER_ID_SERVER; + try{ + m_socket.Bind(port); + m_peer_id = PEER_ID_SERVER; + } + catch(SocketException &e){ + // Create event + ConnectionEvent e; + e.bindFailed(); + putEvent(e); + } } void Connection::connect(Address address) @@ -1597,6 +1605,9 @@ u32 Connection::Receive(u16 &peer_id, SharedBuffer<u8> &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"); |