diff options
author | Gordon Sim <gsim@apache.org> | 2008-08-05 17:03:16 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2008-08-05 17:03:16 +0000 |
commit | bd47fd629bb2356df93af70b174a6a070f3a58cc (patch) | |
tree | c92b2cc932fe806ce9e41521de9f4d01557ec2ba /cpp/src/qpid/sys | |
parent | 6bed4cf29dda54560af44d16143fa4b24b65245b (diff) | |
download | qpid-python-bd47fd629bb2356df93af70b174a6a070f3a58cc.tar.gz |
* revised approach for setting tcp-nodelay on client to avoid breaking platform abstractions
* added ability to set tcp-nodelay on server side of the socket also
Merged from r682785.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@682791 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys')
-rw-r--r-- | cpp/src/qpid/sys/Socket.h | 8 | ||||
-rw-r--r-- | cpp/src/qpid/sys/TCPIOPlugin.cpp | 14 | ||||
-rw-r--r-- | cpp/src/qpid/sys/posix/Socket.cpp | 9 |
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 |