Browse Source

add (optional) socket_file argument to isc::cc::Session::establish(), if NULL (defulat), it uses env var BIND10_MSGQ_SOCKET_FILE, if env var not set, it'll use configure-time default (from session_config.h)

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac183@1916 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
c2dedd7b10

+ 20 - 10
src/lib/cc/session.cc

@@ -57,7 +57,7 @@ class SessionImpl {
 public:
     SessionImpl() : sequence_(-1) { queue_ = Element::createFromString("[]"); }
     virtual ~SessionImpl() {}
-    virtual void establish() = 0; 
+    virtual void establish(const char* socket_file = NULL) = 0;
     virtual int getSocket() = 0;
     virtual void disconnect() = 0;
     virtual void writeData(const void* data, size_t datalen) = 0;
@@ -76,7 +76,7 @@ public:
     ASIOSession(io_service& io_service) :
         io_service_(io_service), socket_(io_service_), data_length_(0)
     {}
-    virtual void establish();
+    virtual void establish(const char* socket_file = NULL);
     virtual void disconnect();
     virtual int getSocket() { return (socket_.native()); }
     virtual void writeData(const void* data, size_t datalen);
@@ -95,9 +95,13 @@ private:
     boost::system::error_code error_;
 };
 
+
+
 void
-ASIOSession::establish() {
-    const char *socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
+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;
     }
@@ -105,6 +109,10 @@ ASIOSession::establish() {
     if (error_) {
         isc_throw(SessionError, "Unable to connect to message queue.");
     }
+    socket_.connect(boost::asio::local::stream_protocol::endpoint(socket_file), error_);
+    if (error_) {
+        isc_throw(SessionError, "Unable to connect to message queue.");
+    }
 }
 
 void
@@ -182,7 +190,7 @@ public:
     SocketSession() : sock_(-1) {}
     virtual ~SocketSession() { disconnect(); }
     virtual int getSocket() { return (sock_); }
-    void establish();
+    void establish(const char* socket_file = NULL);
     virtual void disconnect()
     {
         if (sock_ >= 0) {
@@ -217,7 +225,7 @@ public:
 }
 
 void
-SocketSession::establish() {
+SocketSession::establish(const char* socket_file) {
     int s;
     struct sockaddr_un sun;
 
@@ -225,8 +233,10 @@ SocketSession::establish() {
     if (s < 0) {
         isc_throw(SessionError, "socket() failed");
     }
-    
-    const char *socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
+
+    if (!socket_file) {
+        socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
+    }
     if (!socket_file) {
         socket_file = BIND10_MSGQ_SOCKET_FILE;
     }
@@ -296,8 +306,8 @@ Session::startRead(boost::function<void()> read_callback) {
 }
 
 void
-Session::establish() {
-    impl_->establish();
+Session::establish(const char* socket_file) {
+    impl_->establish(socket_file);
 
     // once established, encapsulate the implementation object so that we
     // can safely release the internal resource when exception happens

+ 1 - 1
src/lib/cc/session.h

@@ -60,7 +60,7 @@ namespace isc {
 
             void startRead(boost::function<void()> read_callback);
 
-            void establish();
+            void establish(const char* socket_file = NULL);
             void disconnect();
             void sendmsg(isc::data::ElementPtr& msg);
             void sendmsg(isc::data::ElementPtr& env,

+ 1 - 1
src/lib/config/tests/fake_session.cc

@@ -172,7 +172,7 @@ Session::startRead(boost::function<void()> read_callback UNUSED_PARAM) {
 }
 
 void
-Session::establish() {
+Session::establish(const char* socket_file) {
 }
 
 //

+ 1 - 1
src/lib/config/tests/fake_session.h

@@ -73,7 +73,7 @@ namespace isc {
 
             void startRead(boost::function<void()> read_callback);
 
-            void establish();
+            void establish(const char* socket_file = NULL);
             bool connect();
             void disconnect();
             void sendmsg(isc::data::ElementPtr& msg);