[svn] commit: r1949 - in /branches/trac183/src/lib/cc: session.cc session_unittests.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Thu May 27 16:12:37 UTC 2010


Author: jelte
Date: Thu May 27 16:12:37 2010
New Revision: 1949

Log:
applied jinmei's patches from http://bind10.isc.org/ticket/183 (with a minor cleanup)
changed IPPROTO_TCP to 0 in the non-asio socket call, which I don't think we need and more importantly, does not work here.

Modified:
    branches/trac183/src/lib/cc/session.cc
    branches/trac183/src/lib/cc/session_unittests.cc

Modified: branches/trac183/src/lib/cc/session.cc
==============================================================================
--- branches/trac183/src/lib/cc/session.cc (original)
+++ branches/trac183/src/lib/cc/session.cc Thu May 27 16:12:37 2010
@@ -59,7 +59,7 @@
 public:
     SessionImpl() : sequence_(-1) { queue_ = Element::createFromString("[]"); }
     virtual ~SessionImpl() {}
-    virtual void establish(const char* socket_file = NULL) = 0;
+    virtual void establish(const char& socket_file) = 0;
     virtual int getSocket() = 0;
     virtual void disconnect() = 0;
     virtual void writeData(const void* data, size_t datalen) = 0;
@@ -78,7 +78,7 @@
     ASIOSession(io_service& io_service) :
         io_service_(io_service), socket_(io_service_), data_length_(0)
     {}
-    virtual void establish(const char* socket_file = NULL);
+    virtual void establish(const char& socket_file);
     virtual void disconnect();
     virtual int getSocket() { return (socket_.native()); }
     virtual void writeData(const void* data, size_t datalen);
@@ -100,15 +100,9 @@
 
 
 void
-ASIOSession::establish(const char* socket_file) {
-    if (!socket_file) {
-        socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
-    }
-    if (!socket_file) {
-        socket_file = BIND10_MSGQ_SOCKET_FILE;
-    }
+ASIOSession::establish(const char& socket_file) {
     try {
-        socket_.connect(boost::asio::local::stream_protocol::endpoint(socket_file), error_);
+        socket_.connect(boost::asio::local::stream_protocol::endpoint(&socket_file), error_);
     } catch (boost::system::system_error& se) {
         isc_throw(SessionError, se.what());
     }
@@ -192,7 +186,7 @@
     SocketSession() : sock_(-1) {}
     virtual ~SocketSession() { disconnect(); }
     virtual int getSocket() { return (sock_); }
-    void establish(const char* socket_file = NULL);
+    void establish(const char& socket_file);
     virtual void disconnect()
     {
         if (sock_ >= 0) {
@@ -227,28 +221,20 @@
 }
 
 void
-SocketSession::establish(const char* socket_file) {
-    int s;
+SocketSession::establish(const char& socket_file) {
     struct sockaddr_un sun;
 
-    s = socket(AF_UNIX, SOCK_STREAM, IPPROTO_TCP);
+    if (strlen(&socket_file) >= sizeof(sun.sun_path)) {
+        isc_throw(SessionError, "Unable to connect to message queue; "
+                  "socket file path too long: " << socket_file);
+    }
+    sun.sun_family = AF_UNIX;
+    strncpy(sun.sun_path, &socket_file, sizeof(sun.sun_path) - 1);
+
+    int s = socket(AF_UNIX, SOCK_STREAM, 0);
     if (s < 0) {
         isc_throw(SessionError, "socket() failed");
     }
-
-    if (!socket_file) {
-        socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
-    }
-    if (!socket_file) {
-        socket_file = BIND10_MSGQ_SOCKET_FILE;
-    }
-
-    if (strlen(socket_file) >= sizeof(sun.sun_path)) {
-        isc_throw(SessionError, "Unable to connect to message queue; socket file path too long");
-    }
-
-    sun.sun_family = AF_UNIX;
-    strncpy(sun.sun_path, socket_file, sizeof(sun.sun_path) - 1);
 
     if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
         close(s);
@@ -312,7 +298,14 @@
 
 void
 Session::establish(const char* socket_file) {
-    impl_->establish(socket_file);
+    if (socket_file == NULL) {
+        socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
+    }
+    if (socket_file == NULL) {
+        socket_file = BIND10_MSGQ_SOCKET_FILE;
+    }
+
+    impl_->establish(*socket_file);
 
     // once established, encapsulate the implementation object so that we
     // can safely release the internal resource when exception happens

Modified: branches/trac183/src/lib/cc/session_unittests.cc
==============================================================================
--- branches/trac183/src/lib/cc/session_unittests.cc (original)
+++ branches/trac183/src/lib/cc/session_unittests.cc Thu May 27 16:12:37 2010
@@ -17,7 +17,9 @@
 #include "config.h"
 #include <gtest/gtest.h>
 #include <session.h>
+#ifdef HAVE_BOOST_SYSTEM
 #include <boost/asio.hpp>
+#endif
 #include <exceptions/exceptions.h>
 
 using namespace isc::cc;




More information about the bind10-changes mailing list