summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/sys')
-rw-r--r--cpp/src/qpid/sys/Socket.h8
-rw-r--r--cpp/src/qpid/sys/TCPIOPlugin.cpp14
-rw-r--r--cpp/src/qpid/sys/posix/Socket.cpp9
3 files changed, 18 insertions, 13 deletions
diff --git a/cpp/src/qpid/sys/Socket.h b/cpp/src/qpid/sys/Socket.h
index 45a8bb588e..dd7ef9a96d 100644
--- a/cpp/src/qpid/sys/Socket.h
+++ b/cpp/src/qpid/sys/Socket.h
@@ -98,13 +98,7 @@ public:
int read(void *buf, size_t count) const;
int write(const void *buf, size_t count) const;
- struct Configuration
- {
- virtual void configurePosixTcpSocket(int fd) const = 0;
- virtual ~Configuration() {}
- };
-
- void configure(const Configuration&);
+ void setTcpNoDelay(bool nodelay) const;
private:
Socket(IOHandlePrivate*);
diff --git a/cpp/src/qpid/sys/TCPIOPlugin.cpp b/cpp/src/qpid/sys/TCPIOPlugin.cpp
index 4b661f1713..f38cf88e45 100644
--- a/cpp/src/qpid/sys/TCPIOPlugin.cpp
+++ b/cpp/src/qpid/sys/TCPIOPlugin.cpp
@@ -35,12 +35,13 @@ namespace qpid {
namespace sys {
class AsynchIOProtocolFactory : public ProtocolFactory {
+ const bool tcpNoDelay;
Socket listener;
const uint16_t listeningPort;
std::auto_ptr<AsynchAcceptor> acceptor;
public:
- AsynchIOProtocolFactory(int16_t port, int backlog);
+ AsynchIOProtocolFactory(int16_t port, int backlog, bool nodelay);
void accept(Poller::shared_ptr, ConnectionCodec::Factory*);
void connect(Poller::shared_ptr, const std::string& host, int16_t port,
ConnectionCodec::Factory*,
@@ -64,21 +65,26 @@ static class TCPIOPlugin : public Plugin {
// Only provide to a Broker
if (broker) {
const broker::Broker::Options& opts = broker->getOptions();
- ProtocolFactory::shared_ptr protocol(new AsynchIOProtocolFactory(opts.port, opts.connectionBacklog));
+ ProtocolFactory::shared_ptr protocol(new AsynchIOProtocolFactory(opts.port, opts.connectionBacklog, opts.tcpNoDelay));
QPID_LOG(info, "Listening on TCP port " << protocol->getPort());
broker->registerProtocolFactory(protocol);
}
}
} tcpPlugin;
-AsynchIOProtocolFactory::AsynchIOProtocolFactory(int16_t port, int backlog) :
- listeningPort(listener.listen(port, backlog))
+AsynchIOProtocolFactory::AsynchIOProtocolFactory(int16_t port, int backlog, bool nodelay) :
+ tcpNoDelay(nodelay), listeningPort(listener.listen(port, backlog))
{}
void AsynchIOProtocolFactory::established(Poller::shared_ptr poller, const Socket& s,
ConnectionCodec::Factory* f, bool isClient) {
AsynchIOHandler* async = new AsynchIOHandler(s.getPeerAddress(), f);
+ if (tcpNoDelay) {
+ s.setTcpNoDelay(tcpNoDelay);
+ QPID_LOG(info, "Set TCP_NODELAY on connection to " << s.getPeerAddress());
+ }
+
if (isClient)
async->setClient();
AsynchIO* aio = new AsynchIO(s,
diff --git a/cpp/src/qpid/sys/posix/Socket.cpp b/cpp/src/qpid/sys/posix/Socket.cpp
index 65345219f0..415d5293ef 100644
--- a/cpp/src/qpid/sys/posix/Socket.cpp
+++ b/cpp/src/qpid/sys/posix/Socket.cpp
@@ -29,6 +29,7 @@
#include <sys/socket.h>
#include <sys/errno.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <netdb.h>
#include <cstdlib>
#include <string.h>
@@ -251,9 +252,13 @@ int Socket::getError() const
return result;
}
-void Socket::configure(const Configuration& c)
+void Socket::setTcpNoDelay(bool nodelay) const
{
- c.configurePosixTcpSocket(impl->fd);
+ 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