|
@@ -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
|