mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Proper handling of failing to bind server socket
This commit is contained in:
parent
d1d83d7e7f
commit
618314985d
4 changed files with 51 additions and 2 deletions
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue