Fix failure to set TCP_NODELAY on Windows

On Windows setting TCP_NODELAY after non-blocking connect fails
at least on Windows 7.
pull/46/head
Tatsuhiro Tsujikawa 2013-02-03 19:09:06 +09:00
parent 1c9cfccac4
commit 98e7018599
6 changed files with 10 additions and 12 deletions

View File

@ -95,7 +95,6 @@ Command* FtpInitiateConnectionCommand::createNextCommand
getCuid(), addr.c_str(), port)); getCuid(), addr.c_str(), port));
createSocket(); createSocket();
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getSocket()->setTcpNodelay(true);
getRequest()->setConnectedAddrInfo(hostname, addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port);
if(proxyMethod == V_GET) { if(proxyMethod == V_GET) {
@ -164,7 +163,6 @@ Command* FtpInitiateConnectionCommand::createNextCommand
getCuid(), addr.c_str(), port)); getCuid(), addr.c_str(), port));
createSocket(); createSocket();
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getSocket()->setTcpNodelay(true);
FtpNegotiationCommand* c = FtpNegotiationCommand* c =
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(), new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(), getRequestGroup(), getDownloadEngine(),

View File

@ -682,8 +682,7 @@ bool FtpNegotiationCommand::preparePasvConnect() {
dataAddr.first.c_str(), dataAddr.first.c_str(),
pasvPort_)); pasvPort_));
dataSocket_.reset(new SocketCore()); dataSocket_.reset(new SocketCore());
dataSocket_->establishConnection(dataAddr.first, pasvPort_); dataSocket_->establishConnection(dataAddr.first, pasvPort_, false);
dataSocket_->setTcpNodelay(true);
disableReadCheckSocket(); disableReadCheckSocket();
setWriteCheckSocket(dataSocket_); setWriteCheckSocket(dataSocket_);
sequence_ = SEQ_SEND_REST_PASV; sequence_ = SEQ_SEND_REST_PASV;
@ -705,7 +704,6 @@ bool FtpNegotiationCommand::resolveProxy()
proxyAddr_.c_str(), proxyReq->getPort())); proxyAddr_.c_str(), proxyReq->getPort()));
dataSocket_.reset(new SocketCore()); dataSocket_.reset(new SocketCore());
dataSocket_->establishConnection(proxyAddr_, proxyReq->getPort()); dataSocket_->establishConnection(proxyAddr_, proxyReq->getPort());
dataSocket_->setTcpNodelay(true);
disableReadCheckSocket(); disableReadCheckSocket();
setWriteCheckSocket(dataSocket_); setWriteCheckSocket(dataSocket_);
SharedHandle<SocketRecvBuffer> socketRecvBuffer SharedHandle<SocketRecvBuffer> socketRecvBuffer
@ -741,7 +739,6 @@ bool FtpNegotiationCommand::sendTunnelRequest()
getCuid(), getCuid(),
proxyAddr_.c_str(), proxyReq->getPort())); proxyAddr_.c_str(), proxyReq->getPort()));
dataSocket_->establishConnection(proxyAddr_, proxyReq->getPort()); dataSocket_->establishConnection(proxyAddr_, proxyReq->getPort());
dataSocket_->setTcpNodelay(true);
return false; return false;
} }
} }
@ -870,7 +867,6 @@ bool FtpNegotiationCommand::waitConnection()
disableReadCheckSocket(); disableReadCheckSocket();
setReadCheckSocket(getSocket()); setReadCheckSocket(getSocket());
dataSocket_ = serverSocket_->acceptConnection(); dataSocket_ = serverSocket_->acceptConnection();
dataSocket_->setTcpNodelay(true);
sequence_ = SEQ_NEGOTIATION_COMPLETED; sequence_ = SEQ_NEGOTIATION_COMPLETED;
return false; return false;
} }

View File

@ -82,7 +82,6 @@ Command* HttpInitiateConnectionCommand::createNextCommand
getCuid(), addr.c_str(), port)); getCuid(), addr.c_str(), port));
createSocket(); createSocket();
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getSocket()->setTcpNodelay(true);
getRequest()->setConnectedAddrInfo(hostname, addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port);
if(proxyMethod == V_TUNNEL) { if(proxyMethod == V_TUNNEL) {
@ -140,7 +139,6 @@ Command* HttpInitiateConnectionCommand::createNextCommand
getCuid(), addr.c_str(), port)); getCuid(), addr.c_str(), port));
createSocket(); createSocket();
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getSocket()->setTcpNodelay(true);
getRequest()->setConnectedAddrInfo(hostname, addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port);
} else { } else {

View File

@ -82,7 +82,7 @@ bool PeerInitiateConnectionCommand::executeInternal() {
getPeer()->getPort())); getPeer()->getPort()));
createSocket(); createSocket();
getSocket()->establishConnection(getPeer()->getIPAddress(), getSocket()->establishConnection(getPeer()->getIPAddress(),
getPeer()->getPort()); getPeer()->getPort(), false);
if(mseHandshakeEnabled_) { if(mseHandshakeEnabled_) {
InitiatorMSEHandshakeCommand* c = InitiatorMSEHandshakeCommand* c =
new InitiatorMSEHandshakeCommand(getCuid(), requestGroup_, getPeer(), new InitiatorMSEHandshakeCommand(getCuid(), requestGroup_, getPeer(),

View File

@ -409,7 +409,8 @@ int SocketCore::getPeerInfo(std::pair<std::string, uint16_t>& peerinfo) const
return sockaddr.storage.ss_family; return sockaddr.storage.ss_family;
} }
void SocketCore::establishConnection(const std::string& host, uint16_t port) void SocketCore::establishConnection(const std::string& host, uint16_t port,
bool tcpNodelay)
{ {
closeConnection(); closeConnection();
std::string error; std::string error;
@ -461,6 +462,9 @@ void SocketCore::establishConnection(const std::string& host, uint16_t port)
sockfd_ = fd; sockfd_ = fd;
// make socket non-blocking mode // make socket non-blocking mode
setNonBlockingMode(); setNonBlockingMode();
if(tcpNodelay) {
setTcpNodelay(true);
}
if(connect(fd, rp->ai_addr, rp->ai_addrlen) == -1 && if(connect(fd, rp->ai_addr, rp->ai_addrlen) == -1 &&
SOCKET_ERRNO != A2_EINPROGRESS) { SOCKET_ERRNO != A2_EINPROGRESS) {
errNum = SOCKET_ERRNO; errNum = SOCKET_ERRNO;

View File

@ -207,8 +207,10 @@ public:
* the connection is established. * the connection is established.
* @param host hostname or ip address to connect to * @param host hostname or ip address to connect to
* @param port service port number to connect to * @param port service port number to connect to
* @param tcpNodelay true to disable Nagle algorithm
*/ */
void establishConnection(const std::string& host, uint16_t port); void establishConnection(const std::string& host, uint16_t port,
bool tcpNodelay = true);
void setNonBlockingMode(); void setNonBlockingMode();