2008-02-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Make listening socket non-block mode.
	* src/FtpConnection.cc
	* src/FtpNegotiationCommand.{h, cc}
	* src/PeerListenCommand.cc
	
	Fixed the bug that cause slow ftp negotiation.
	* src/FtpNegotiationCommand.{h, cc}
pull/1/head
Tatsuhiro Tsujikawa 2008-02-19 13:36:39 +00:00
parent 766e092af3
commit 80bc9a8a21
5 changed files with 43 additions and 6 deletions

View File

@ -1,3 +1,13 @@
2008-02-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Make listening socket non-block mode.
* src/FtpConnection.cc
* src/FtpNegotiationCommand.{h, cc}
* src/PeerListenCommand.cc
Fixed the bug that cause slow ftp negotiation.
* src/FtpNegotiationCommand.{h, cc}
2008-02-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added basic tag to --enable-dht, --dht-listen-port option.

View File

@ -109,7 +109,8 @@ SocketHandle FtpConnection::sendPort() const
SocketHandle serverSocket;
serverSocket->bind(0);
serverSocket->beginListen();
serverSocket->setNonBlockingMode();
std::pair<std::string, int32_t> addrinfo;
socket->getAddrInfo(addrinfo);
int32_t ipaddr[4];

View File

@ -246,7 +246,7 @@ bool FtpNegotiationCommand::recvSize() {
sequence = SEQ_FILE_PREPARATION;
disableReadCheckSocket();
setWriteCheckSocket(dataSocket);
//setWriteCheckSocket(dataSocket);
//e->noWait = true;
return false;
@ -261,7 +261,13 @@ bool FtpNegotiationCommand::recvSize() {
return true;
}
void FtpNegotiationCommand::afterFileAllocation()
{
setReadCheckSocket(socket);
}
bool FtpNegotiationCommand::sendPort() {
afterFileAllocation();
serverSocket = ftp->sendPort();
sequence = SEQ_RECV_PORT;
return false;
@ -280,6 +286,7 @@ bool FtpNegotiationCommand::recvPort() {
}
bool FtpNegotiationCommand::sendPasv() {
afterFileAllocation();
ftp->sendPasv();
sequence = SEQ_RECV_PASV;
return false;
@ -347,12 +354,24 @@ bool FtpNegotiationCommand::recvRetr() {
if(status != 150 && status != 125) {
throw new DlAbortEx(EX_BAD_STATUS, status);
}
if(e->option->get(PREF_FTP_PASV) != V_TRUE) {
assert(serverSocket->getSockfd() != -1);
dataSocket = serverSocket->acceptConnection();
if(e->option->getAsBool(PREF_FTP_PASV)) {
sequence = SEQ_NEGOTIATION_COMPLETED;
return false;
} else {
disableReadCheckSocket();
setReadCheckSocket(serverSocket);
sequence = SEQ_WAIT_CONNECTION;
return false;
}
sequence = SEQ_NEGOTIATION_COMPLETED;
}
bool FtpNegotiationCommand::waitConnection()
{
disableReadCheckSocket();
setReadCheckSocket(socket);
dataSocket = serverSocket->acceptConnection();
dataSocket->setBlockingMode();
sequence = SEQ_NEGOTIATION_COMPLETED;
return false;
}
@ -399,6 +418,8 @@ bool FtpNegotiationCommand::processSequence(const SegmentHandle& segment) {
return sendRetr();
case SEQ_RECV_RETR:
return recvRetr();
case SEQ_WAIT_CONNECTION:
return waitConnection();
default:
abort();
}

View File

@ -65,6 +65,7 @@ private:
SEQ_RECV_REST,
SEQ_SEND_RETR,
SEQ_RECV_RETR,
SEQ_WAIT_CONNECTION,
SEQ_NEGOTIATION_COMPLETED,
SEQ_RETRY,
SEQ_HEAD_OK,
@ -91,8 +92,11 @@ private:
bool recvRest();
bool sendRetr();
bool recvRetr();
bool waitConnection();
bool processSequence(const SharedHandle<Segment>& segment);
void afterFileAllocation();
SharedHandle<SocketCore> dataSocket;
SharedHandle<SocketCore> serverSocket;
int32_t sequence;

View File

@ -70,6 +70,7 @@ int32_t PeerListenCommand::bindPort(IntSequence& seq)
try {
socket->bind(port);
socket->beginListen();
socket->setNonBlockingMode();
logger->info(MSG_LISTENING_PORT,
cuid, port);
return port;