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.
pull/2/head
Tatsuhiro Tsujikawa 2011-09-11 00:13:09 +09:00
parent b775b19366
commit 79c59dcbf4
3 changed files with 17 additions and 24 deletions

View File

@ -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<std::string, uint16_t> 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;
}

View File

@ -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;

View File

@ -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<int32_t> randPorts = seq.flush();
std::random_shuffle(randPorts.begin(), randPorts.end(),
*SimpleRandomizer::getInstance().get());
const int ipv = (family_ == AF_INET) ? 4 : 6;
for(std::vector<int32_t>::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();
}
}