You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2008/08/05 18:45:24 UTC

svn commit: r682785 - in /incubator/qpid/branches/qpid.0-10/cpp/src/qpid: broker/Broker.cpp broker/Broker.h client/ConnectionSettings.cpp client/ConnectionSettings.h client/Connector.cpp sys/Socket.h sys/TCPIOPlugin.cpp sys/posix/Socket.cpp

Author: gsim
Date: Tue Aug  5 09:45:23 2008
New Revision: 682785

URL: http://svn.apache.org/viewvc?rev=682785&view=rev
Log:
* 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


Modified:
    incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.cpp
    incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.h
    incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.cpp
    incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.h
    incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/Connector.cpp
    incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/Socket.h
    incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/TCPIOPlugin.cpp
    incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/posix/Socket.cpp

Modified: incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.cpp?rev=682785&r1=682784&r2=682785&view=diff
==============================================================================
--- incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.cpp (original)
+++ incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.cpp Tue Aug  5 09:45:23 2008
@@ -88,7 +88,8 @@
     realm("QPID"),
     replayFlushLimit(0),
     replayHardLimit(0),
-    queueLimit(100*1048576/*100M default limit*/)
+    queueLimit(100*1048576/*100M default limit*/),
+    tcpNoDelay(false)
 {
     int c = sys::SystemInfo::concurrency();
     workerThreads=c+1;
@@ -112,7 +113,8 @@
         ("mgmt-pub-interval", optValue(mgmtPubInterval, "SECONDS"), "Management Publish Interval")
         ("auth", optValue(auth, "yes|no"), "Enable authentication, if disabled all incoming connections will be trusted")
         ("realm", optValue(realm, "REALM"), "Use the given realm when performing authentication")
-        ("default-queue-limit", optValue(queueLimit, "BYTES"), "Default maximum size for queues (in bytes)");
+        ("default-queue-limit", optValue(queueLimit, "BYTES"), "Default maximum size for queues (in bytes)")
+        ("tcp-nodelay", optValue(tcpNoDelay), "Set TCP_NODELAY on TCP connections");
 }
 
 const std::string empty;

Modified: incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.h?rev=682785&r1=682784&r2=682785&view=diff
==============================================================================
--- incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.h (original)
+++ incubator/qpid/branches/qpid.0-10/cpp/src/qpid/broker/Broker.h Tue Aug  5 09:45:23 2008
@@ -85,6 +85,7 @@
         size_t replayFlushLimit;
         size_t replayHardLimit;
         uint queueLimit;
+        bool tcpNoDelay;
     };
     
     virtual ~Broker();

Modified: incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.cpp?rev=682785&r1=682784&r2=682785&view=diff
==============================================================================
--- incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.cpp (original)
+++ incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.cpp Tue Aug  5 09:45:23 2008
@@ -21,10 +21,8 @@
 #include "ConnectionSettings.h"
 
 #include "qpid/log/Logger.h"
-#include "qpid/sys/posix/check.h"
+#include "qpid/sys/Socket.h"
 #include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
 
 namespace qpid {
 namespace client {
@@ -45,13 +43,11 @@
 
 ConnectionSettings::~ConnectionSettings() {}
 
-void ConnectionSettings::configurePosixTcpSocket(int fd) const
+void ConnectionSettings::configureSocket(qpid::sys::Socket& socket) const
 {
     if (tcpNoDelay) {
-        int flag = 1;
-        int result = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
-        QPID_POSIX_CHECK(result);
-        QPID_LOG(debug, "Set TCP_NODELAY");
+        socket.setTcpNoDelay(tcpNoDelay);
+        QPID_LOG(info, "Set TCP_NODELAY");
     }
 }
 

Modified: incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.h?rev=682785&r1=682784&r2=682785&view=diff
==============================================================================
--- incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.h (original)
+++ incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/ConnectionSettings.h Tue Aug  5 09:45:23 2008
@@ -25,26 +25,31 @@
 #include "qpid/Options.h"
 #include "qpid/log/Options.h"
 #include "qpid/Url.h"
-#include "qpid/sys/Socket.h"
 
 #include <iostream>
 #include <exception>
 
 namespace qpid {
+
+namespace sys {
+class Socket;
+}
+
 namespace client {
 
 /**
  * Settings for a Connection.
  */
-struct ConnectionSettings : public sys::Socket::Configuration {
+struct ConnectionSettings {
 
     ConnectionSettings();
     virtual ~ConnectionSettings();
 
     /**
-     * Applies any tcp specific options to the sockets file descriptor
+     * Allows socket to be configured; default only sets tcp-nodelay
+     * based on the flag set. Can be overridden.
      */
-    virtual void configurePosixTcpSocket(int fd) const;
+    virtual void configureSocket(qpid::sys::Socket&) const;
 
     /**
      * The host (or ip address) to connect to (defaults to 'localhost').

Modified: incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/Connector.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/Connector.cpp?rev=682785&r1=682784&r2=682785&view=diff
==============================================================================
--- incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/Connector.cpp (original)
+++ incubator/qpid/branches/qpid.0-10/cpp/src/qpid/client/Connector.cpp Tue Aug  5 09:45:23 2008
@@ -60,7 +60,7 @@
       impl(cimpl)
 {
     QPID_LOG(debug, "Connector created for " << version);
-    socket.configure(settings);
+    settings.configureSocket(socket);
 }
 
 Connector::~Connector() {

Modified: incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/Socket.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/Socket.h?rev=682785&r1=682784&r2=682785&view=diff
==============================================================================
--- incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/Socket.h (original)
+++ incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/Socket.h Tue Aug  5 09:45:23 2008
@@ -108,13 +108,7 @@
     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*);

Modified: incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/TCPIOPlugin.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/TCPIOPlugin.cpp?rev=682785&r1=682784&r2=682785&view=diff
==============================================================================
--- incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/TCPIOPlugin.cpp (original)
+++ incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/TCPIOPlugin.cpp Tue Aug  5 09:45:23 2008
@@ -34,12 +34,13 @@
 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*,
@@ -63,21 +64,26 @@
         // 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,

Modified: incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/posix/Socket.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/posix/Socket.cpp?rev=682785&r1=682784&r2=682785&view=diff
==============================================================================
--- incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/posix/Socket.cpp (original)
+++ incubator/qpid/branches/qpid.0-10/cpp/src/qpid/sys/posix/Socket.cpp Tue Aug  5 09:45:23 2008
@@ -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>
@@ -276,9 +277,13 @@
     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