summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2009-10-16 18:47:42 +0000
committerAndrew Stitcher <astitcher@apache.org>2009-10-16 18:47:42 +0000
commit2b04bc6dc46b3f761a239f41032258eb1d345fbf (patch)
tree407265a44af0f2a05349a56f31f952ab65267819
parent47e5f39e966a99dadf39d9fa30a456296442bbb6 (diff)
downloadqpid-python-2b04bc6dc46b3f761a239f41032258eb1d345fbf.tar.gz
Fixed tcp nodelay, broken by previous socket code shuffling
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@826031 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--cpp/src/qpid/client/ConnectionSettings.cpp2
-rw-r--r--cpp/src/qpid/sys/Socket.h5
-rw-r--r--cpp/src/qpid/sys/TCPIOPlugin.cpp2
-rw-r--r--cpp/src/qpid/sys/posix/Socket.cpp31
4 files changed, 24 insertions, 16 deletions
diff --git a/cpp/src/qpid/client/ConnectionSettings.cpp b/cpp/src/qpid/client/ConnectionSettings.cpp
index 35d78365ba..3ae4ee010a 100644
--- a/cpp/src/qpid/client/ConnectionSettings.cpp
+++ b/cpp/src/qpid/client/ConnectionSettings.cpp
@@ -47,7 +47,7 @@ ConnectionSettings::~ConnectionSettings() {}
void ConnectionSettings::configureSocket(qpid::sys::Socket& socket) const
{
if (tcpNoDelay) {
- socket.setTcpNoDelay(tcpNoDelay);
+ socket.setTcpNoDelay();
QPID_LOG(info, "Set TCP_NODELAY");
}
}
diff --git a/cpp/src/qpid/sys/Socket.h b/cpp/src/qpid/sys/Socket.h
index 76b993fd63..7b50c42a3c 100644
--- a/cpp/src/qpid/sys/Socket.h
+++ b/cpp/src/qpid/sys/Socket.h
@@ -45,6 +45,8 @@ public:
/** Set socket non blocking */
void setNonblocking() const;
+ QPID_COMMON_EXTERN void setTcpNoDelay() const;
+
QPID_COMMON_EXTERN void connect(const std::string& host, uint16_t port) const;
QPID_COMMON_EXTERN void connect(const SocketAddress&) const;
@@ -97,8 +99,6 @@ public:
QPID_COMMON_EXTERN int read(void *buf, size_t count) const;
QPID_COMMON_EXTERN int write(const void *buf, size_t count) const;
- QPID_COMMON_EXTERN void setTcpNoDelay(bool nodelay) const;
-
private:
/** Create socket */
void createSocket(const SocketAddress&) const;
@@ -106,6 +106,7 @@ private:
Socket(IOHandlePrivate*);
mutable std::string connectname;
mutable bool nonblocking;
+ mutable bool nodelay;
};
}}
diff --git a/cpp/src/qpid/sys/TCPIOPlugin.cpp b/cpp/src/qpid/sys/TCPIOPlugin.cpp
index 3377be98f1..d51893374a 100644
--- a/cpp/src/qpid/sys/TCPIOPlugin.cpp
+++ b/cpp/src/qpid/sys/TCPIOPlugin.cpp
@@ -84,7 +84,7 @@ void AsynchIOProtocolFactory::established(Poller::shared_ptr poller, const Socke
AsynchIOHandler* async = new AsynchIOHandler(s.getPeerAddress(), f);
if (tcpNoDelay) {
- s.setTcpNoDelay(tcpNoDelay);
+ s.setTcpNoDelay();
QPID_LOG(info, "Set TCP_NODELAY on connection to " << s.getPeerAddress());
}
diff --git a/cpp/src/qpid/sys/posix/Socket.cpp b/cpp/src/qpid/sys/posix/Socket.cpp
index 840d9d4b2a..7b906f33e8 100644
--- a/cpp/src/qpid/sys/posix/Socket.cpp
+++ b/cpp/src/qpid/sys/posix/Socket.cpp
@@ -98,12 +98,14 @@ std::string getService(int fd, bool local)
Socket::Socket() :
IOHandle(new IOHandlePrivate),
- nonblocking(false)
+ nonblocking(false),
+ nodelay(false)
{}
Socket::Socket(IOHandlePrivate* h) :
IOHandle(h),
- nonblocking(false)
+ nonblocking(false),
+ nodelay(false)
{}
void Socket::createSocket(const SocketAddress& sa) const
@@ -116,6 +118,7 @@ void Socket::createSocket(const SocketAddress& sa) const
try {
if (nonblocking) setNonblocking();
+ if (nodelay) setTcpNoDelay();
} catch (std::exception&) {
::close(s);
socket = -1;
@@ -134,8 +137,21 @@ void Socket::setTimeout(const Duration& interval) const
void Socket::setNonblocking() const {
int& socket = impl->fd;
- if (socket != -1) QPID_POSIX_CHECK(::fcntl(socket, F_SETFL, O_NONBLOCK));
nonblocking = true;
+ if (socket != -1) {
+ QPID_POSIX_CHECK(::fcntl(socket, F_SETFL, O_NONBLOCK));
+ }
+}
+
+void Socket::setTcpNoDelay() const
+{
+ int& socket = impl->fd;
+ nodelay = true;
+ if (socket != -1) {
+ int flag = 1;
+ int result = setsockopt(impl->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
+ QPID_POSIX_CHECK(result);
+ }
}
void Socket::connect(const std::string& host, uint16_t port) const
@@ -258,13 +274,4 @@ int Socket::getError() const
return result;
}
-void Socket::setTcpNoDelay(bool nodelay) const
-{
- if (nodelay) {
- int flag = 1;
- int result = setsockopt(impl->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
- QPID_POSIX_CHECK(result);
- }
-}
-
}} // namespace qpid::sys