summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJelte Jansen <jelte@isc.org>2010-05-27 18:12:37 +0200
committerJelte Jansen <jelte@isc.org>2010-05-27 18:12:37 +0200
commit2def58b09b7ca7974f2f00e81d8f227ff482ed5d (patch)
tree489aa9d1960f50df84b83471773ce4e14e6d1ba1 /src
parentcatch exception by reference. (diff)
downloadkea-2def58b09b7ca7974f2f00e81d8f227ff482ed5d.tar.xz
kea-2def58b09b7ca7974f2f00e81d8f227ff482ed5d.zip
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. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac183@1949 e5f2f494-b856-4b98-b285-d166d9295462
Diffstat (limited to 'src')
-rw-r--r--src/lib/cc/session.cc51
-rw-r--r--src/lib/cc/session_unittests.cc2
2 files changed, 24 insertions, 29 deletions
diff --git a/src/lib/cc/session.cc b/src/lib/cc/session.cc
index ba4b799fbd..ee8256a649 100644
--- a/src/lib/cc/session.cc
+++ b/src/lib/cc/session.cc
@@ -59,7 +59,7 @@ class SessionImpl {
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 @@ public:
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 @@ private:
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 @@ public:
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,29 +221,21 @@ public:
}
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 (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: " << socket_file);
}
+ sun.sun_family = AF_UNIX;
+ strncpy(sun.sun_path, &socket_file, sizeof(sun.sun_path) - 1);
- if (strlen(socket_file) >= sizeof(sun.sun_path)) {
- isc_throw(SessionError, "Unable to connect to message queue; socket file path too long");
+ int s = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (s < 0) {
+ isc_throw(SessionError, "socket() failed");
}
- 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);
isc_throw(SessionError, "Unable to connect to message queue");
@@ -312,7 +298,14 @@ Session::startRead(boost::function<void()> read_callback) {
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
diff --git a/src/lib/cc/session_unittests.cc b/src/lib/cc/session_unittests.cc
index 048a9fb9bc..455fa11adf 100644
--- a/src/lib/cc/session_unittests.cc
+++ b/src/lib/cc/session_unittests.cc
@@ -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;