qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject svn commit: r682791 - in /incubator/qpid/trunk/qpid/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
Date Tue, 05 Aug 2008 17:03:16 GMT
Author: gsim
Date: Tue Aug  5 10:03:16 2008
New Revision: 682791

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

Merged from r682785.


Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?rev=682791&r1=682790&r2=682791&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Tue Aug  5 10:03:16 2008
@@ -89,7 +89,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;
@@ -113,7 +114,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/trunk/qpid/cpp/src/qpid/broker/Broker.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h?rev=682791&r1=682790&r2=682791&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h Tue Aug  5 10:03:16 2008
@@ -88,6 +88,7 @@
         size_t replayFlushLimit;
         size_t replayHardLimit;
         uint queueLimit;
+        bool tcpNoDelay;
     };
  
   private:

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp?rev=682791&r1=682790&r2=682791&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp Tue Aug  5 10:03:16
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/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.h?rev=682791&r1=682790&r2=682791&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.h Tue Aug  5 10:03:16
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/trunk/qpid/cpp/src/qpid/client/Connector.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp?rev=682791&r1=682790&r2=682791&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp Tue Aug  5 10:03:16 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/trunk/qpid/cpp/src/qpid/sys/Socket.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h?rev=682791&r1=682790&r2=682791&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h Tue Aug  5 10:03:16 2008
@@ -98,13 +98,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/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp?rev=682791&r1=682790&r2=682791&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp Tue Aug  5 10:03:16 2008
@@ -35,12 +35,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*,
@@ -64,21 +65,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/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp?rev=682791&r1=682790&r2=682791&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp Tue Aug  5 10:03:16 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>
@@ -251,9 +252,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



Mime
View raw message