29 #include <boost/bind.hpp>
31 #include <rsc/misc/langutils.h>
38 using namespace boost;
40 using namespace boost::asio;
43 using namespace rsc::logging;
49 BusConnection::BusConnection(
BusPtr bus,
53 logger(Logger::getLogger(
"rsb.transport.socket.BusConnection")),
54 socket(socket), bus(bus), disconnecting(false) {
59 RSCINFO(
logger,
"Setting TCP_NODELAY option");
60 boost::asio::ip::tcp::no_delay option(
true);
61 socket->set_option(option);
81 RSCINFO(
logger,
"Disconnecting");
85 this->
socket->shutdown(ip::tcp::socket::shutdown_send);
86 this->
socket->shutdown(ip::tcp::socket::shutdown_receive);
87 RSCINFO(
logger,
"Closing");
97 const string& wireSchema) {
104 *static_pointer_cast<string>(event->getData()));
125 bus->removeConnection(shared_from_this());
126 }
catch (
const boost::bad_weak_ptr&) {
134 }
catch (
const std::exception& e) {
135 RSCDEBUG(
logger,
"Failed to disconnect (in " << context <<
"): "
145 boost::asio::placeholders::error,
146 boost::asio::placeholders::bytes_transferred));
150 size_t bytesTransferred) {
151 if (error || (bytesTransferred != 4)) {
153 RSCDEBUG(
logger,
"Receive failure (error " << error <<
")"
154 <<
" or incomplete message header (received " << bytesTransferred <<
" bytes)"
155 <<
"; closing connection");
167 RSCDEBUG(
logger,
"Received message header with size " << size);
174 boost::asio::placeholders::error,
175 boost::asio::placeholders::bytes_transferred,
180 size_t bytesTransferred,
182 if (error || (bytesTransferred != expected)) {
184 RSCWARN(
logger,
"Receive failure (error " << error <<
")"
185 <<
" or incomplete message body (received " << bytesTransferred <<
" bytes)"
186 <<
"; closing connection");
201 BusPtr bus = this->bus.lock();
203 bus->handleIncoming(event, shared_from_this());
205 RSCWARN(
logger,
"Dangling bus pointer when trying to dispatch incoming event; closing connection");
216 stream <<
"local = " << this->
socket->local_endpoint()
217 <<
", remote = " << this->
socket->remote_endpoint();
219 stream <<
"<error printing socket info>";