server fix bind() when 5075 in use
This commit is contained in:
+4
-2
@@ -305,10 +305,12 @@ Server::Pvt::Pvt(Config&& conf)
|
||||
acceptor_loop.call([this, &dummy](){
|
||||
// from acceptor worker
|
||||
|
||||
bool firstiface = true;
|
||||
for(const auto& addr : effective.interfaces) {
|
||||
interfaces.emplace_back(addr, effective.tcp_port, this);
|
||||
if(effective.tcp_port==0)
|
||||
interfaces.emplace_back(addr, effective.tcp_port, this, firstiface);
|
||||
if(firstiface || effective.tcp_port==0)
|
||||
effective.tcp_port = interfaces.back().bind_addr.port();
|
||||
firstiface = false;
|
||||
}
|
||||
|
||||
for(const auto& addr : effective.beaconDestinations) {
|
||||
|
||||
+2
-2
@@ -508,7 +508,7 @@ void ServerConn::bevWriteS(struct bufferevent *bev, void *ptr)
|
||||
}
|
||||
}
|
||||
|
||||
ServIface::ServIface(const std::string& addr, unsigned short port, server::Server::Pvt *server)
|
||||
ServIface::ServIface(const std::string& addr, unsigned short port, server::Server::Pvt *server, bool fallback)
|
||||
:server(server)
|
||||
,bind_addr(AF_INET, addr.c_str(), port)
|
||||
,sock(AF_INET, SOCK_STREAM, 0)
|
||||
@@ -520,7 +520,7 @@ ServIface::ServIface(const std::string& addr, unsigned short port, server::Serve
|
||||
try {
|
||||
sock.bind(bind_addr);
|
||||
} catch(std::system_error& e) {
|
||||
if(e.code().value()==SOCK_EADDRINUSE && bind_addr.port()!=0) {
|
||||
if(fallback && e.code().value()==SOCK_EADDRINUSE) {
|
||||
bind_addr.setPort(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-1
@@ -168,7 +168,7 @@ struct ServIface
|
||||
evsocket sock;
|
||||
evlisten listener;
|
||||
|
||||
ServIface(const std::string& addr, unsigned short port, server::Server::Pvt *server);
|
||||
ServIface(const std::string& addr, unsigned short port, server::Server::Pvt *server, bool fallback);
|
||||
|
||||
static void onConnS(struct evconnlistener *listener, evutil_socket_t sock, struct sockaddr *peer, int socklen, void *raw);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user