From 79c59dcbf49cc237354497f1f36d03d68ba5646f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 11 Sep 2011 00:13:09 +0900 Subject: [PATCH] Cleanup log message for binding server socket. Cleaned up log message for binding server socket. After binding BitTorrent TCP port, add the socket to DownloadEngine to check readability. This was missing for long time. --- src/DHTConnectionImpl.cc | 7 +++---- src/HttpListenCommand.cc | 14 +++----------- src/PeerListenCommand.cc | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/DHTConnectionImpl.cc b/src/DHTConnectionImpl.cc index 86f04f72..104a9d3f 100644 --- a/src/DHTConnectionImpl.cc +++ b/src/DHTConnectionImpl.cc @@ -76,7 +76,7 @@ bool DHTConnectionImpl::bind bool DHTConnectionImpl::bind(uint16_t& port, const std::string& addr) { - int ipv = family_ == AF_INET?4:6; + const int ipv = (family_ == AF_INET) ? 4 : 6; try { if(addr.empty()) { socket_->bind(A2STR::NIL, port, family_); @@ -87,11 +87,10 @@ bool DHTConnectionImpl::bind(uint16_t& port, const std::string& addr) std::pair svaddr; socket_->getAddrInfo(svaddr); port = svaddr.second; - A2_LOG_NOTICE(fmt("IPv%d DHT: listening to port %d", ipv, port)); + A2_LOG_NOTICE(fmt("IPv%d DHT: listening to port %u", ipv, port)); return true; } catch(RecoverableException& e) { - A2_LOG_ERROR_EX(fmt("Failed to bind for IPv%d DHT. port=%u", ipv, port), - e); + A2_LOG_ERROR_EX(fmt("IPv%d DHT: failed to bind port %u", ipv, port), e); } return false; } diff --git a/src/HttpListenCommand.cc b/src/HttpListenCommand.cc index 6874a20c..2b01c894 100644 --- a/src/HttpListenCommand.cc +++ b/src/HttpListenCommand.cc @@ -97,9 +97,7 @@ bool HttpListenCommand::bindPort(uint16_t port) e_->deleteSocketForReadCheck(serverSocket_, this); } serverSocket_.reset(new SocketCore()); - A2_LOG_INFO(fmt("CUID#%lld - Setting up HttpListenCommand for IPv%d", - getCuid(), - family_ == AF_INET?4:6)); + const int ipv = (family_ == AF_INET) ? 4 : 6; try { int flags = 0; if(e_->getOption()->getAsBool(PREF_RPC_LISTEN_ALL)) { @@ -111,16 +109,10 @@ bool HttpListenCommand::bindPort(uint16_t port) A2_LOG_INFO(fmt(MSG_LISTENING_PORT, getCuid(), port)); e_->addSocketForReadCheck(serverSocket_, this); + A2_LOG_NOTICE(fmt("IPv%d RPC: listening to port %u", ipv, port)); return true; } catch(RecoverableException& e) { - A2_LOG_ERROR(fmt("Failed to setup RPC server for IPv%d", - family_ == AF_INET?4:6)); - A2_LOG_ERROR_EX(fmt(MSG_BIND_FAILURE, - getCuid(), port), - e); - if(serverSocket_) { - e_->deleteSocketForReadCheck(serverSocket_, this); - } + A2_LOG_ERROR_EX(fmt("IPv%d RPC: failed to bind port %u", ipv, port), e); serverSocket_->closeConnection(); } return false; diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc index 526c9ca9..a0f95bda 100644 --- a/src/PeerListenCommand.cc +++ b/src/PeerListenCommand.cc @@ -61,7 +61,12 @@ PeerListenCommand::PeerListenCommand family_(family) {} -PeerListenCommand::~PeerListenCommand() {} +PeerListenCommand::~PeerListenCommand() +{ + if(socket_) { + e_->deleteSocketForReadCheck(socket_, this); + } +} bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq) { @@ -70,7 +75,7 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq) std::vector randPorts = seq.flush(); std::random_shuffle(randPorts.begin(), randPorts.end(), *SimpleRandomizer::getInstance().get()); - + const int ipv = (family_ == AF_INET) ? 4 : 6; for(std::vector::const_iterator portItr = randPorts.begin(), eoi = randPorts.end(); portItr != eoi; ++portItr) { if(!(0 < (*portItr) && (*portItr) <= 65535)) { @@ -81,15 +86,12 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq) socket_->bind(A2STR::NIL, port, family_); socket_->beginListen(); socket_->setNonBlockingMode(); - A2_LOG_NOTICE(fmt("IPv%d BitTorrent: listening to port %d", - family_ == AF_INET?4:6, port)); + e_->addSocketForReadCheck(socket_, this); + A2_LOG_NOTICE(fmt("IPv%d BitTorrent: listening to port %u", ipv, port)); return true; } catch(RecoverableException& ex) { - A2_LOG_ERROR(fmt("Failed to setup IPv%d BitTorrent server socket", - family_ == AF_INET?4:6)); - A2_LOG_ERROR_EX(fmt(MSG_BIND_FAILURE, - getCuid(), port), - ex); + A2_LOG_ERROR_EX(fmt("IPv%d BitTorrent: failed to bind port %u", + ipv, port), ex); socket_->closeConnection(); } }