Improve logging for socket forwarding 12/185912/3
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Thu, 2 Aug 2018 08:19:49 +0000 (10:19 +0200)
committerIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Tue, 21 Aug 2018 10:37:29 +0000 (12:37 +0200)
Change-Id: I993d089b924ef71b91c604ff730d2621fbc31c32
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
simulatordaemon/debugproxy/inc/forwarding.h
simulatordaemon/debugproxy/src/ProxySession.cpp

index 433c2a8..80bdc4b 100644 (file)
@@ -18,6 +18,7 @@ template <typename T, typename S>
 void forward(socket_ptr<T> from,
                    socket_ptr<S> to,
                    std::shared_ptr<AsyncEvent> connection_end,
+                   const std::string tag,
                    yield_ctx yield) {
        try {
                char data[chunk_size];
@@ -28,7 +29,8 @@ void forward(socket_ptr<T> from,
                                *to, boost::asio::buffer(data, len), yield);
                }
        } catch (std::exception &e) {
-               LOGD(MODULE_DEBUGPROXY, "Stopped forwarding sockets: %s", e.what());
+               LOGD(MODULE_DEBUGPROXY, "%s: Stopped forwarding sockets: %s",
+                    tag.c_str(), e.what());
                connection_end->set();
        }
 }
index ab4ee95..1067f70 100644 (file)
@@ -1,4 +1,5 @@
 #include <memory>
+#include <cstdio>
 #include <boost/bind.hpp>
 #include <boost/asio/deadline_timer.hpp>
 
@@ -64,16 +65,20 @@ std::shared_ptr<AsyncEvent> ProxySession::start_forwarding()
 {
        LOGD(MODULE_DEBUGPROXY, "(%p) Two-way forwarding started", this);
        auto connection_lost_event = std::make_shared<AsyncEvent>(this->io());
+       char tag[100];
+
+       std::sprintf(tag, "(%p) local -> port", this);
        boost::asio::spawn(
                this->io(),
                boost::bind(&forward<local::stream_protocol, ip::tcp>,
                            this->local_socket, this->port_socket,
-                           connection_lost_event, _1));
+                           connection_lost_event, tag, _1));
+       std::sprintf(tag, "(%p) port -> local", this);
        boost::asio::spawn(
                this->io(),
                boost::bind(&forward<ip::tcp, local::stream_protocol>,
                            this->port_socket, this->local_socket,
-                           connection_lost_event, _1));
+                           connection_lost_event, tag, _1));
        return connection_lost_event;
 }