|
@@ -14,6 +14,7 @@
|
|
|
|
|
|
#include <config.h>
|
|
#include <config.h>
|
|
#include <cc/session_config.h>
|
|
#include <cc/session_config.h>
|
|
|
|
+#include <cc/logger.h>
|
|
|
|
|
|
#include <stdint.h>
|
|
#include <stdint.h>
|
|
|
|
|
|
@@ -118,12 +119,16 @@ private:
|
|
void
|
|
void
|
|
SessionImpl::establish(const char& socket_file) {
|
|
SessionImpl::establish(const char& socket_file) {
|
|
try {
|
|
try {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_BASIC, CC_ESTABLISH).arg(socket_file);
|
|
socket_.connect(asio::local::stream_protocol::endpoint(&socket_file),
|
|
socket_.connect(asio::local::stream_protocol::endpoint(&socket_file),
|
|
error_);
|
|
error_);
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_BASIC, CC_ESTABLISHED);
|
|
} catch(const asio::system_error& se) {
|
|
} catch(const asio::system_error& se) {
|
|
|
|
+ LOG_FATAL(logger, CC_CONN_ERROR).arg(se.what());
|
|
isc_throw(SessionError, se.what());
|
|
isc_throw(SessionError, se.what());
|
|
}
|
|
}
|
|
if (error_) {
|
|
if (error_) {
|
|
|
|
+ LOG_FATAL(logger, CC_NO_MSGQ).arg(error_.message());
|
|
isc_throw(SessionError, "Unable to connect to message queue: " <<
|
|
isc_throw(SessionError, "Unable to connect to message queue: " <<
|
|
error_.message());
|
|
error_.message());
|
|
}
|
|
}
|
|
@@ -131,6 +136,7 @@ SessionImpl::establish(const char& socket_file) {
|
|
|
|
|
|
void
|
|
void
|
|
SessionImpl::disconnect() {
|
|
SessionImpl::disconnect() {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_BASIC, CC_DISCONNECT);
|
|
socket_.close();
|
|
socket_.close();
|
|
data_length_ = 0;
|
|
data_length_ = 0;
|
|
}
|
|
}
|
|
@@ -140,6 +146,7 @@ SessionImpl::writeData(const void* data, size_t datalen) {
|
|
try {
|
|
try {
|
|
asio::write(socket_, asio::buffer(data, datalen));
|
|
asio::write(socket_, asio::buffer(data, datalen));
|
|
} catch (const asio::system_error& asio_ex) {
|
|
} catch (const asio::system_error& asio_ex) {
|
|
|
|
+ LOG_FATAL(logger, CC_WRITE_ERROR).arg(asio_ex.what());
|
|
isc_throw(SessionError, "ASIO write failed: " << asio_ex.what());
|
|
isc_throw(SessionError, "ASIO write failed: " << asio_ex.what());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -151,6 +158,7 @@ SessionImpl::readDataLength() {
|
|
if (ret_len == 0) {
|
|
if (ret_len == 0) {
|
|
readData(&data_length_, sizeof(data_length_));
|
|
readData(&data_length_, sizeof(data_length_));
|
|
if (data_length_ == 0) {
|
|
if (data_length_ == 0) {
|
|
|
|
+ LOG_ERROR(logger, CC_LENGTH_NOT_READY);
|
|
isc_throw(SessionError, "ASIO read: data length is not ready");
|
|
isc_throw(SessionError, "ASIO read: data length is not ready");
|
|
}
|
|
}
|
|
ret_len = ntohl(data_length_);
|
|
ret_len = ntohl(data_length_);
|
|
@@ -199,9 +207,11 @@ SessionImpl::readData(void* data, size_t datalen) {
|
|
// asio::error_code evaluates to false if there was no error
|
|
// asio::error_code evaluates to false if there was no error
|
|
if (*read_result) {
|
|
if (*read_result) {
|
|
if (*read_result == asio::error::operation_aborted) {
|
|
if (*read_result == asio::error::operation_aborted) {
|
|
|
|
+ LOG_ERROR(logger, CC_TIMEOUT);
|
|
isc_throw(SessionTimeout,
|
|
isc_throw(SessionTimeout,
|
|
"Timeout while reading data from cc session");
|
|
"Timeout while reading data from cc session");
|
|
} else {
|
|
} else {
|
|
|
|
+ LOG_ERROR(logger, CC_READ_ERROR).arg(read_result->message());
|
|
isc_throw(SessionError,
|
|
isc_throw(SessionError,
|
|
"Error while reading data from cc session: " <<
|
|
"Error while reading data from cc session: " <<
|
|
read_result->message());
|
|
read_result->message());
|
|
@@ -210,6 +220,7 @@ SessionImpl::readData(void* data, size_t datalen) {
|
|
} catch (const asio::system_error& asio_ex) {
|
|
} catch (const asio::system_error& asio_ex) {
|
|
// to hide ASIO specific exceptions, we catch them explicitly
|
|
// to hide ASIO specific exceptions, we catch them explicitly
|
|
// and convert it to SessionError.
|
|
// and convert it to SessionError.
|
|
|
|
+ LOG_FATAL(logger, CC_READ_EXCEPTION).arg(asio_ex.what());
|
|
isc_throw(SessionError, "ASIO read failed: " << asio_ex.what());
|
|
isc_throw(SessionError, "ASIO read failed: " << asio_ex.what());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -233,10 +244,12 @@ SessionImpl::internalRead(const asio::error_code& error,
|
|
assert(bytes_transferred == sizeof(data_length_));
|
|
assert(bytes_transferred == sizeof(data_length_));
|
|
data_length_ = ntohl(data_length_);
|
|
data_length_ = ntohl(data_length_);
|
|
if (data_length_ == 0) {
|
|
if (data_length_ == 0) {
|
|
|
|
+ LOG_ERROR(logger, CC_ZERO_LENGTH);
|
|
isc_throw(SessionError, "Invalid message length (0)");
|
|
isc_throw(SessionError, "Invalid message length (0)");
|
|
}
|
|
}
|
|
user_handler_();
|
|
user_handler_();
|
|
} else {
|
|
} else {
|
|
|
|
+ LOG_ERROR(logger, CC_ASYNC_READ_FAILED);
|
|
isc_throw(SessionError, "asynchronous read failed");
|
|
isc_throw(SessionError, "asynchronous read failed");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -255,6 +268,7 @@ Session::disconnect() {
|
|
|
|
|
|
void
|
|
void
|
|
Session::startRead(boost::function<void()> read_callback) {
|
|
Session::startRead(boost::function<void()> read_callback) {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_START_READ);
|
|
impl_->startRead(read_callback);
|
|
impl_->startRead(read_callback);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -374,6 +388,7 @@ Session::recvmsg(ConstElementPtr& env, ConstElementPtr& msg,
|
|
|
|
|
|
unsigned short header_length = ntohs(header_length_net);
|
|
unsigned short header_length = ntohs(header_length_net);
|
|
if (header_length > length || length < 2) {
|
|
if (header_length > length || length < 2) {
|
|
|
|
+ LOG_ERROR(logger, CC_INVALID_LENGTHS).arg(length).arg(header_length);
|
|
isc_throw(SessionError, "Length parameters invalid: total=" << length
|
|
isc_throw(SessionError, "Length parameters invalid: total=" << length
|
|
<< ", header=" << header_length);
|
|
<< ", header=" << header_length);
|
|
}
|
|
}
|
|
@@ -417,6 +432,7 @@ Session::recvmsg(ConstElementPtr& env, ConstElementPtr& msg,
|
|
|
|
|
|
void
|
|
void
|
|
Session::subscribe(std::string group, std::string instance) {
|
|
Session::subscribe(std::string group, std::string instance) {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_SUBSCRIBE).arg(group);
|
|
ElementPtr env = Element::createMap();
|
|
ElementPtr env = Element::createMap();
|
|
|
|
|
|
env->set("type", Element::create("subscribe"));
|
|
env->set("type", Element::create("subscribe"));
|
|
@@ -428,6 +444,7 @@ Session::subscribe(std::string group, std::string instance) {
|
|
|
|
|
|
void
|
|
void
|
|
Session::unsubscribe(std::string group, std::string instance) {
|
|
Session::unsubscribe(std::string group, std::string instance) {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_UNSUBSCRIBE).arg(group);
|
|
ElementPtr env = Element::createMap();
|
|
ElementPtr env = Element::createMap();
|
|
|
|
|
|
env->set("type", Element::create("unsubscribe"));
|
|
env->set("type", Element::create("unsubscribe"));
|
|
@@ -441,6 +458,8 @@ int
|
|
Session::group_sendmsg(ConstElementPtr msg, std::string group,
|
|
Session::group_sendmsg(ConstElementPtr msg, std::string group,
|
|
std::string instance, std::string to)
|
|
std::string instance, std::string to)
|
|
{
|
|
{
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_GROUP_SEND).arg(msg->str()).
|
|
|
|
+ arg(group);
|
|
ElementPtr env = Element::createMap();
|
|
ElementPtr env = Element::createMap();
|
|
long int nseq = ++impl_->sequence_;
|
|
long int nseq = ++impl_->sequence_;
|
|
|
|
|
|
@@ -460,11 +479,21 @@ bool
|
|
Session::group_recvmsg(ConstElementPtr& envelope, ConstElementPtr& msg,
|
|
Session::group_recvmsg(ConstElementPtr& envelope, ConstElementPtr& msg,
|
|
bool nonblock, int seq)
|
|
bool nonblock, int seq)
|
|
{
|
|
{
|
|
- return (recvmsg(envelope, msg, nonblock, seq));
|
|
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_GROUP_RECEIVE);
|
|
|
|
+ bool result(recvmsg(envelope, msg, nonblock, seq));
|
|
|
|
+ if (result) {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_GROUP_RECEIVED).
|
|
|
|
+ arg(envelope->str()).arg(msg->str());
|
|
|
|
+ } else {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_NO_MESSAGE);
|
|
|
|
+ }
|
|
|
|
+ return (result);
|
|
}
|
|
}
|
|
|
|
|
|
int
|
|
int
|
|
Session::reply(ConstElementPtr envelope, ConstElementPtr newmsg) {
|
|
Session::reply(ConstElementPtr envelope, ConstElementPtr newmsg) {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_REPLY).arg(envelope->str()).
|
|
|
|
+ arg(newmsg->str());
|
|
ElementPtr env = Element::createMap();
|
|
ElementPtr env = Element::createMap();
|
|
long int nseq = ++impl_->sequence_;
|
|
long int nseq = ++impl_->sequence_;
|
|
|
|
|
|
@@ -488,6 +517,7 @@ Session::hasQueuedMsgs() const {
|
|
|
|
|
|
void
|
|
void
|
|
Session::setTimeout(size_t milliseconds) {
|
|
Session::setTimeout(size_t milliseconds) {
|
|
|
|
+ LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_SET_TIMEOUT).arg(milliseconds);
|
|
impl_->setTimeout(milliseconds);
|
|
impl_->setTimeout(milliseconds);
|
|
}
|
|
}
|
|
|
|
|