From 7d78f39a792b18ef4436946c15f055f3721eece2 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Wed, 7 Sep 2022 11:17:50 +0900 Subject: [PATCH 01/16] Fix static analysis issues Changes: - Adds exception handling logic. - Fix to using const_cast instead of strdup. Change-Id: Ic6b54c8257f1099f37b1fea33ba5a6894dc751ad Signed-off-by: Changgyu Choi --- benchmark/server/main.cc | 9 ++++++--- benchmark/tool/main.cc | 13 +++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/benchmark/server/main.cc b/benchmark/server/main.cc index b44fb96..c4466cf 100644 --- a/benchmark/server/main.cc +++ b/benchmark/server/main.cc @@ -72,9 +72,12 @@ class MainLoop { return; } - stub_.Listen(std::shared_ptr< - bs::Benchmark::ServiceBase::Factory>( - new TestService::Factory())); + try { + stub_.Listen(std::shared_ptr( + new TestService::Factory())); + } catch (const std::exception& e) { + _E("stub listen is failed(%s)", e.what()); + } g_main_loop_run(loop_); } diff --git a/benchmark/tool/main.cc b/benchmark/tool/main.cc index 7883b32..a8b5ce8 100644 --- a/benchmark/tool/main.cc +++ b/benchmark/tool/main.cc @@ -29,8 +29,8 @@ namespace { -constexpr const char SERVER_PROC_NAME[] = "org.tizen.appfw.rpc_port.benchmark"; -constexpr const char SERVER_BIN[] = "/usr/bin/rpc-port-benchmark-server"; +#define SERVER_PROC_NAME "org.tizen.appfw.rpc_port.benchmark" +#define SERVER_BIN "/usr/bin/rpc-port-benchmark-server" namespace bp = rpc_port::BenchmarkProxy::proxy; @@ -147,7 +147,7 @@ class Tester { if (server_pid_ == 0) { setsid(); - char* argv[] = { strdup(SERVER_BIN), nullptr, nullptr }; + char* argv[] = { SERVER_BIN, nullptr, nullptr }; int ret = execv(argv[0], argv); if (ret < 0) { std::cerr << "execv() is failed. errno: " << errno << std::endl; @@ -174,6 +174,11 @@ class Tester { int main(int argc, char** argv) { Tester tester; - tester.Run(argc, argv); + try { + tester.Run(argc, argv); + } catch (const std::exception& e) { + std::cerr << "Exception occurred!!!" << e.what() << std::endl; + } + return 0; } -- 2.7.4 From 4b48140bea65e9fb9661d3f4c614b4df08f77a95 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Wed, 7 Sep 2022 16:42:42 +0900 Subject: [PATCH 02/16] Release version 1.13.3 Changes: - Fix static analysis issues Change-Id: I0e0669a5f02715647d3e93a25d1e3ae24f302629 Signed-off-by: Changgyu Choi --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 10993c0..997e36c 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.13.2 +Version: 1.13.3 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From b7550b2f2a4e7ed0bfb3d327a700442322e09783 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 15 Sep 2022 10:47:54 +0000 Subject: [PATCH 03/16] Remove build warning messages To remove -Wwrite-strings warning messages, char array is added to set the SERVER_BIN. Change-Id: I66cb1c3d325f794f6d89b66b378b2f0f15836297 Signed-off-by: Hwankyu Jhun --- benchmark/tool/main.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmark/tool/main.cc b/benchmark/tool/main.cc index a8b5ce8..580eb69 100644 --- a/benchmark/tool/main.cc +++ b/benchmark/tool/main.cc @@ -147,7 +147,8 @@ class Tester { if (server_pid_ == 0) { setsid(); - char* argv[] = { SERVER_BIN, nullptr, nullptr }; + char bin[] = { SERVER_BIN }; + char* argv[] = { bin, nullptr, nullptr }; int ret = execv(argv[0], argv); if (ret < 0) { std::cerr << "execv() is failed. errno: " << errno << std::endl; -- 2.7.4 From d416ebd46e130a862a040afb6d3e031ffe932d96 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 15 Sep 2022 10:42:36 +0000 Subject: [PATCH 04/16] Fix DebugPort implementation The DebugPort implementation is changed. The method are changed to 'static'. The implementation of the DebugPort is moved to the DebugPortImpl. To avoid unnecessary locking mutex, the flag that is connected_ is changed to std::atomic. Change-Id: I4aca67730639664c7a2646f9486be49124dad0ff Signed-off-by: Hwankyu Jhun --- src/debug-port-internal.cc | 198 ++++++++++++++++++++++++++++++++------------- src/debug-port-internal.hh | 102 +---------------------- src/proxy-internal.cc | 12 +-- src/rpc-port.cc | 6 +- src/stub-internal.cc | 6 +- 5 files changed, 159 insertions(+), 165 deletions(-) diff --git a/src/debug-port-internal.cc b/src/debug-port-internal.cc index 9787f96..a6c8e2e 100644 --- a/src/debug-port-internal.cc +++ b/src/debug-port-internal.cc @@ -16,23 +16,29 @@ #include "debug-port-internal.hh" +#include #include +#include +#include #include #include #include #include #include +#include +#include +#include +#include +#include #include #include "log-private.hh" - -#undef RPC_DTOR -#define RPC_DTOR __attribute__ ((destructor)) +#include "port-internal.hh" +#include "shared-queue-internal.hh" namespace rpc_port { namespace internal { - namespace { constexpr const char PATH_RPC_PORT_UTIL_SOCK[] = @@ -40,43 +46,94 @@ constexpr const char PATH_RPC_PORT_UTIL_SOCK[] = constexpr const char ENDPOINT_RPC_PORT_DEBUG[] = "org.tizen.rpcport.debug"; constexpr const char KEY_PORT_NAME[] = "__K_PORT_NAME__"; -RPC_DTOR void DebugPortDtor() { - DebugPort::GetInst()->Dispose(false); -} - -} // namespace +class Session { + public: + Session(std::string port_name, std::string destination, + int main_port, int delegate_port) + : port_name_(std::move(port_name)), + destination_(std::move(destination)), + main_port_(main_port), + delegate_port_(delegate_port) { + } -std::atomic DebugPort::inst_; -std::mutex DebugPort::mutex_; + const std::string& GetPortName() const { + return port_name_; + } -DebugPort::~DebugPort() { - Dispose(); -} + const std::string& GetDestination() const { + return destination_; + } -DebugPort* DebugPort::GetInst() { - DebugPort* inst = inst_.load(std::memory_order_acquire); - if (inst == nullptr) { - std::lock_guard lock(mutex_); - inst = inst_.load(std::memory_order_relaxed); - if (inst == nullptr) { - inst = new DebugPort(); - inst_.store(inst, std::memory_order_release); - } + int GetMainPort() const { + return main_port_; } - std::lock_guard rec_lock(inst->GetMutex()); - if (inst->disposed_) - inst->Init(); + int GetDelegatePort() const { + return delegate_port_; + } - return inst; + private: + std::string port_name_; + std::string destination_; + int main_port_; + int delegate_port_; +}; + +class DebugPortImpl { + public: + DebugPortImpl() = default; + ~DebugPortImpl(); + + void Dispose(); + bool IsConnected() const; + void AddSession(std::string port_name, std::string destination, + int main_port, int delegate_port); + void RemoveSession(int port); + int Send(int port, bool is_read, uint32_t seq, + const void* buf, unsigned int size); + void Init(); + + private: + int Connect(); + int Watch(int fd); + void Unwatch(); + void SetConnectionStatus(bool status); + void CreateThread(); + void JoinThread(); + + std::recursive_mutex& GetMutex() const; + std::shared_ptr FindSession(int port); + std::shared_ptr FindSession(const std::string& port_name); + + static gboolean OnDebugPortDisconnectedCb(GIOChannel* io, + GIOCondition cond, gpointer data); + static int AppComCb(const char* endpoint, aul_app_com_result_e result, + bundle* envelope, void* user_data); + + private: + bool disposed_ = true; + std::atomic connected_; + std::unique_ptr port_; + GIOChannel* io_ = nullptr; + guint watch_tag_ = 0; + std::list> sessions_; + std::thread thread_; + std::atomic is_running_; + SharedQueue> queue_; + mutable std::recursive_mutex mutex_; + aul_app_com_connection_h conn_ = nullptr; +}; + +DebugPortImpl::~DebugPortImpl() { + Dispose(); } -void DebugPort::Dispose(bool do_leave) { +void DebugPortImpl::Dispose() { std::lock_guard lock(GetMutex()); if (disposed_) return; - if (do_leave && conn_) { + if (conn_) { aul_app_com_leave(conn_); conn_ = nullptr; } @@ -86,23 +143,22 @@ void DebugPort::Dispose(bool do_leave) { disposed_ = true; } -bool DebugPort::IsConnected() { - std::lock_guard lock(GetMutex()); +bool DebugPortImpl::IsConnected() const { return connected_; } -void DebugPort::AddSession(std::string port_name, std::string destination, +void DebugPortImpl::AddSession(std::string port_name, std::string destination, int main_port, int delegate_port) { std::lock_guard lock(GetMutex()); sessions_.emplace_back( - new DebugPort::Session(std::move(port_name), std::move(destination), - main_port, delegate_port)); + new Session(std::move(port_name), std::move(destination), + main_port, delegate_port)); } -void DebugPort::RemoveSession(int port) { +void DebugPortImpl::RemoveSession(int port) { std::lock_guard lock(GetMutex()); auto iter = std::find_if(sessions_.begin(), sessions_.end(), - [port](std::shared_ptr& sess) -> bool { + [port](std::shared_ptr& sess) -> bool { return sess->GetMainPort() == port || sess->GetDelegatePort() == port; }); @@ -112,7 +168,7 @@ void DebugPort::RemoveSession(int port) { } } -std::shared_ptr DebugPort::FindSession(int port) { +std::shared_ptr DebugPortImpl::FindSession(int port) { std::lock_guard lock(GetMutex()); for (auto& s : sessions_) { if (s->GetMainPort() == port || s->GetDelegatePort() == port) @@ -122,7 +178,7 @@ std::shared_ptr DebugPort::FindSession(int port) { return nullptr; } -std::shared_ptr DebugPort::FindSession( +std::shared_ptr DebugPortImpl::FindSession( const std::string& port_name) { std::lock_guard lock(GetMutex()); for (auto& s : sessions_) { @@ -133,9 +189,8 @@ std::shared_ptr DebugPort::FindSession( return nullptr; } -int DebugPort::Send(int port, bool is_read, uint32_t seq, +int DebugPortImpl::Send(int port, bool is_read, uint32_t seq, const void* buf, unsigned int size) { - std::lock_guard lock(GetMutex()); if (!IsConnected()) return 0; @@ -161,7 +216,11 @@ int DebugPort::Send(int port, bool is_read, uint32_t seq, return 0; } -void DebugPort::Init() { +void DebugPortImpl::Init() { + if (!disposed_) + return; + + std::lock_guard lock(GetMutex()); aul_app_com_create_async(ENDPOINT_RPC_PORT_DEBUG, nullptr, AppComCb, this, &conn_); if (conn_ == nullptr) @@ -184,7 +243,7 @@ void DebugPort::Init() { disposed_ = false; } -int DebugPort::Connect() { +int DebugPortImpl::Connect() { if (access(PATH_RPC_PORT_UTIL_SOCK, F_OK) != 0) return -1; @@ -209,7 +268,7 @@ int DebugPort::Connect() { return fd; } -int DebugPort::Watch(int fd) { +int DebugPortImpl::Watch(int fd) { GIOChannel* io = g_io_channel_unix_new(fd); if (io == nullptr) { _E("g_io_channel_unix_new() is failed"); @@ -230,7 +289,7 @@ int DebugPort::Watch(int fd) { return 0; } -void DebugPort::Unwatch() { +void DebugPortImpl::Unwatch() { if (io_) { g_io_channel_unref(io_); io_ = nullptr; @@ -242,10 +301,10 @@ void DebugPort::Unwatch() { } } -gboolean DebugPort::OnDebugPortDisconnectedCb(GIOChannel* io, +gboolean DebugPortImpl::OnDebugPortDisconnectedCb(GIOChannel* io, GIOCondition cond, gpointer data) { _W("cond(%d)", static_cast(cond)); - auto* debug_port = static_cast(data); + auto* debug_port = static_cast(data); std::lock_guard lock(debug_port->GetMutex()); debug_port->SetConnectionStatus(false); debug_port->watch_tag_ = 0; @@ -255,12 +314,11 @@ gboolean DebugPort::OnDebugPortDisconnectedCb(GIOChannel* io, return G_SOURCE_REMOVE; } -void DebugPort::SetConnectionStatus(bool status) { - std::lock_guard lock(GetMutex()); - connected_ = status; +void DebugPortImpl::SetConnectionStatus(bool status) { + connected_.exchange(status); } -void DebugPort::CreateThread() { +void DebugPortImpl::CreateThread() { if (is_running_) return; @@ -297,7 +355,7 @@ void DebugPort::CreateThread() { is_running_ = true; } -void DebugPort::JoinThread() { +void DebugPortImpl::JoinThread() { if (is_running_) queue_.Push(std::shared_ptr(new tizen_base::Parcel())); @@ -307,16 +365,21 @@ void DebugPort::JoinThread() { } } -int DebugPort::AppComCb(const char* endpoint, aul_app_com_result_e result, + +std::recursive_mutex& DebugPortImpl::GetMutex() const { + return mutex_; +} + +int DebugPortImpl::AppComCb(const char* endpoint, aul_app_com_result_e result, bundle* envelope, void* user_data) { const char* val = bundle_get_val(envelope, KEY_PORT_NAME); if (val == nullptr) return -1; - auto* handle = static_cast(user_data); + auto* handle = static_cast(user_data); std::string port_name(val); if (port_name.empty() || handle->FindSession(port_name) != nullptr) { - auto* handle = static_cast(user_data); + auto* handle = static_cast(user_data); int fd = handle->Connect(); if (fd < 0) return -1; @@ -335,5 +398,32 @@ int DebugPort::AppComCb(const char* endpoint, aul_app_com_result_e result, return 0; } +DebugPortImpl impl; + +} // namespace + +bool DebugPort::IsConnected() { + impl.Init(); + return impl.IsConnected(); +} + +void DebugPort::AddSession(std::string port_name, std::string destination, + int main_port, int delegate_port) { + impl.Init(); + return impl.AddSession(std::move(port_name), std::move(destination), + main_port, delegate_port); +} + +void DebugPort::RemoveSession(int port) { + impl.Init(); + return impl.RemoveSession(port); +} + +int DebugPort::Send(int port, bool is_read, uint32_t seq, const void* buf, + unsigned int size) { + impl.Init(); + return impl.Send(port, is_read, seq, buf, size); +} + } // namespace internal } // namespace rpc_port diff --git a/src/debug-port-internal.hh b/src/debug-port-internal.hh index e624660..1fb2285 100644 --- a/src/debug-port-internal.hh +++ b/src/debug-port-internal.hh @@ -17,113 +17,19 @@ #ifndef DEBUG_PORT_INTERNAL_HH_ #define DEBUG_PORT_INTERNAL_HH_ -#include -#include -#include -#include - -#include -#include -#include -#include #include -#include -#include - -#include "port-internal.hh" -#include "shared-queue-internal.hh" namespace rpc_port { namespace internal { class DebugPort { - private: - DebugPort() = default; - ~DebugPort(); - public: - class Session { - public: - Session(std::string port_name, std::string destination, - int main_port, int delegate_port) - : port_name_(std::move(port_name)), - destination_(std::move(destination)), - main_port_(main_port), - delegate_port_(delegate_port) { - } - virtual ~Session() = default; - - const std::string& GetPortName() { - return port_name_; - } - - const std::string& GetDestination() { - return destination_; - } - - int GetMainPort() { - return main_port_; - } - - int GetDelegatePort() { - return delegate_port_; - } - - private: - std::string port_name_; - std::string destination_; - int main_port_; - int delegate_port_; - }; - - static DebugPort* GetInst(); - - void Dispose(bool do_leave = true); - bool IsConnected(); - - void AddSession(std::string port_name, std::string destination, + static bool IsConnected(); + static void AddSession(std::string port_name, std::string destination, int main_port, int delegate_port); - void RemoveSession(int port); - - int Send(int port, bool is_read, uint32_t seq, + static void RemoveSession(int port); + static int Send(int port, bool is_read, uint32_t seq, const void* buf, unsigned int size); - - private: - static std::atomic inst_; - static std::mutex mutex_; - - std::recursive_mutex& GetMutex() const { - return rec_mutex_; - } - - void Init(); - int Connect(); - int Watch(int fd); - void Unwatch(); - void SetConnectionStatus(bool status); - void CreateThread(); - void JoinThread(); - - std::shared_ptr FindSession(int port); - std::shared_ptr FindSession(const std::string& port_name); - - static gboolean OnDebugPortDisconnectedCb(GIOChannel* io, - GIOCondition cond, gpointer data); - static int AppComCb(const char* endpoint, aul_app_com_result_e result, - bundle* envelope, void* user_data); - - private: - bool disposed_ = true; - bool connected_ = false; - std::unique_ptr port_; - GIOChannel* io_ = nullptr; - guint watch_tag_ = 0; - std::list> sessions_; - std::thread thread_; - std::atomic is_running_; - SharedQueue> queue_; - mutable std::recursive_mutex rec_mutex_; - aul_app_com_connection_h conn_ = nullptr; }; } // namespace internal diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index bd03cac..771a303 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -106,7 +106,7 @@ Proxy::~Proxy() { std::lock_guard lock(GetMutex()); _D("Proxy::~Proxy()"); if (main_port_.get() != nullptr) - DebugPort::GetInst()->RemoveSession(main_port_->GetFd()); + DebugPort::RemoveSession(main_port_->GetFd()); listener_ = nullptr; UnsetIdler(); @@ -267,7 +267,7 @@ int Proxy::ConnectSync(std::string appid, std::string port_name, main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false)); delegate_port_.reset(new ProxyPort(this, fds_[1], target_appid_)); - DebugPort::GetInst()->AddSession(port_name, target_appid_, fds_[0], fds_[1]); + DebugPort::AddSession(port_name, target_appid_, fds_[0], fds_[1]); listener_->OnConnected(target_appid_, main_port_.get()); return RPC_PORT_ERROR_NONE; } @@ -275,7 +275,7 @@ int Proxy::ConnectSync(std::string appid, std::string port_name, void Proxy::DisconnectPort() { std::lock_guard lock(GetMutex()); if (main_port_.get() != nullptr) { - DebugPort::GetInst()->RemoveSession(main_port_->GetFd()); + DebugPort::RemoveSession(main_port_->GetFd()); main_port_.reset(); } } @@ -556,7 +556,7 @@ gboolean Proxy::ProxyPort::OnSocketDisconnected(GIOChannel* channel, proxy->delegate_port_.reset(); proxy->listener_ = nullptr; listener->OnDisconnected(proxy->target_appid_); - DebugPort::GetInst()->RemoveSession(fd); + DebugPort::RemoveSession(fd); return G_SOURCE_REMOVE;; } @@ -578,7 +578,7 @@ gboolean Proxy::ProxyPort::OnDataReceived(GIOChannel* channel, proxy->listener_ = nullptr; proxy->delegate_port_->SetSource(0); if (proxy->main_port_.get() != nullptr) { - DebugPort::GetInst()->RemoveSession(proxy->main_port_->GetFd()); + DebugPort::RemoveSession(proxy->main_port_->GetFd()); proxy->main_port_.reset(); } proxy->delegate_port_.reset(); @@ -763,7 +763,7 @@ gboolean Proxy::Client::OnResponseReceived(GIOChannel* channel, proxy->fds_[1] = client_fd; proxy->delegate_port_.reset( new ProxyPort(proxy, proxy->fds_[1], proxy->target_appid_)); - DebugPort::GetInst()->AddSession(proxy->port_name_, proxy->target_appid_, + DebugPort::AddSession(proxy->port_name_, proxy->target_appid_, proxy->fds_[0], proxy->fds_[1]); listener->OnConnected(proxy->target_appid_, proxy->main_port_.get()); _W("target_appid(%s), port_name(%s), main_fd(%d), delegate_fd(%d)", diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 2ed8c89..1ccd5e5 100644 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -241,8 +241,7 @@ RPC_API int rpc_port_read(rpc_port_h h, void* buf, unsigned int size) { return ret; } - auto* debug_port = DebugPort::GetInst(); - debug_port->Send(port->GetFd(), true, seq, buf, size); + DebugPort::Send(port->GetFd(), true, seq, buf, size); return RPC_PORT_ERROR_NONE; } @@ -260,8 +259,7 @@ RPC_API int rpc_port_write(rpc_port_h h, const void* buf, unsigned int size) { if (ret < 0) return ret; - auto* debug_port = DebugPort::GetInst(); - debug_port->Send(port->GetFd(), false, seq, buf, size); + DebugPort::Send(port->GetFd(), false, seq, buf, size); return RPC_PORT_ERROR_NONE; } diff --git a/src/stub-internal.cc b/src/stub-internal.cc index 1ffc2e8..5a9d014 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -97,7 +97,7 @@ Stub::~Stub() { _D("Stub::~Stub"); for (auto& p : ports_) { if (!p->IsDelegate()) - DebugPort::GetInst()->RemoveSession(p->GetFd()); + DebugPort::RemoveSession(p->GetFd()); } listener_ = nullptr; @@ -167,7 +167,7 @@ void Stub::RemoveAcceptedPorts(std::string instance) { while (iter != ports_.end()) { if ((*iter)->GetInstance().compare(instance) == 0) { LOGI("Close: fd(%d)", (*iter)->GetFd()); - DebugPort::GetInst()->RemoveSession((*iter)->GetFd()); + DebugPort::RemoveSession((*iter)->GetFd()); iter = ports_.erase(iter); } else { iter++; @@ -264,7 +264,7 @@ void Stub::AddAcceptedPort(const std::string& sender_appid, _W("sender_appid(%s), instance(%s), main_fd(%d), delegate_fd(%d)", sender_appid.c_str(), instance.c_str(), main_fd, fd); - DebugPort::GetInst()->AddSession(port_name_, sender_appid, main_fd, fd); + DebugPort::AddSession(port_name_, sender_appid, main_fd, fd); listener_->OnConnected(sender_appid, instance); } -- 2.7.4 From 5362a9aaa708b0acffe2bf6acb0eb18ccabcb0f4 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 16 Sep 2022 01:52:10 +0000 Subject: [PATCH 05/16] Release version 1.13.4 Changes: - Remove build warning messages - Fix DebugPort implementation Change-Id: I4c5e8edcee9604326d7344dea0a52384a7f232aa Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 997e36c..47a9b0e 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.13.3 +Version: 1.13.4 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From a49371e1f9f157392f3c74b147f332d43a5b0ed3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 21 Sep 2022 08:20:13 +0000 Subject: [PATCH 06/16] Check debug port connection If the debug port is not connected, the rpc-port doesn't send and receive the sequence number. Change-Id: I7697410a0500a790fad2328d9aa4ff54a93da652 Signed-off-by: Hwankyu Jhun --- src/rpc-port.cc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 1ccd5e5..6d38540 100644 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -229,19 +229,23 @@ RPC_API int rpc_port_read(rpc_port_h h, void* buf, unsigned int size) { auto port = static_cast(h); uint32_t seq = 0; - int ret = port->Read(reinterpret_cast(&seq), sizeof(seq)); - if (ret < 0) { - _E("IO Error"); - return ret; + if (DebugPort::IsConnected()) { + int ret = port->Read(reinterpret_cast(&seq), sizeof(seq)); + if (ret < 0) { + _E("IO Error"); + return ret; + } } - ret = port->Read(buf, size); + int ret = port->Read(buf, size); if (ret < 0) { _E("IO Error"); return ret; } - DebugPort::Send(port->GetFd(), true, seq, buf, size); + if (DebugPort::IsConnected()) + DebugPort::Send(port->GetFd(), true, seq, buf, size); + return RPC_PORT_ERROR_NONE; } @@ -251,15 +255,19 @@ RPC_API int rpc_port_write(rpc_port_h h, const void* buf, unsigned int size) { auto port = static_cast(h); uint32_t seq = port->GetSeq(); - int ret = port->Write(reinterpret_cast(&seq), sizeof(seq)); - if (ret < 0) - return ret; + if (DebugPort::IsConnected()) { + int ret = port->Write(reinterpret_cast(&seq), sizeof(seq)); + if (ret < 0) + return ret; + } - ret = port->Write(buf, size); + int ret = port->Write(buf, size); if (ret < 0) return ret; - DebugPort::Send(port->GetFd(), false, seq, buf, size); + if (DebugPort::IsConnected()) + DebugPort::Send(port->GetFd(), false, seq, buf, size); + return RPC_PORT_ERROR_NONE; } -- 2.7.4 From d053d8eb7a43de791d04701744572dd507306005 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 22 Sep 2022 01:29:11 +0000 Subject: [PATCH 07/16] Fix static analysis issue - Initializes member variables Change-Id: Iea984746028c53001d2a2100cc57d03fc3315f30 Signed-off-by: Hwankyu Jhun --- src/debug-port-internal.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/debug-port-internal.cc b/src/debug-port-internal.cc index a6c8e2e..e5c1802 100644 --- a/src/debug-port-internal.cc +++ b/src/debug-port-internal.cc @@ -112,13 +112,13 @@ class DebugPortImpl { private: bool disposed_ = true; - std::atomic connected_; + std::atomic connected_ { false }; std::unique_ptr port_; GIOChannel* io_ = nullptr; guint watch_tag_ = 0; std::list> sessions_; std::thread thread_; - std::atomic is_running_; + std::atomic is_running_ { false }; SharedQueue> queue_; mutable std::recursive_mutex mutex_; aul_app_com_connection_h conn_ = nullptr; -- 2.7.4 From 447f76e51d74efa44702b48e2cd2884dd4b8b9b0 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 22 Sep 2022 05:42:25 +0000 Subject: [PATCH 08/16] Release version 1.13.5 Changes: - Check debug port connection - Fix static analysis issue Change-Id: Iad333eae69105012fa456e08f0f042b792e7883e Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 47a9b0e..5144054 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.13.4 +Version: 1.13.5 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From ce812b6c2ad864314c7911d0f421acca45b92e5c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 23 Sep 2022 11:06:39 +0000 Subject: [PATCH 09/16] Use modified tizen_base::Parcel To improve the performance of the parcel creation, the implementation of the Parcel is changed. It uses malloc() instead of std::vector. Requires: - https://review.tizen.org/gerrit/#/c/platform/core/base/bundle/+/281779/ Change-Id: Iaf01e6e94e34e10a36b8ca17081c6aba3b3b51e1 Signed-off-by: Hwankyu Jhun --- src/debug-port-internal.cc | 4 ++-- src/parcel-internal.cc | 23 +++++++---------------- src/parcel-internal.hh | 4 +++- src/proxy-internal.cc | 17 +++++++++++------ src/rpc-port-parcel.cc | 14 ++++++-------- src/stub-internal.cc | 5 ++--- 6 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/debug-port-internal.cc b/src/debug-port-internal.cc index e5c1802..06e44dc 100644 --- a/src/debug-port-internal.cc +++ b/src/debug-port-internal.cc @@ -327,7 +327,7 @@ void DebugPortImpl::CreateThread() { do { std::shared_ptr parcel; queue_.WaitAndPop(parcel); - int len = parcel->GetRaw().size(); + int len = parcel->GetDataSize(); if (len == 0) { _W("Done"); break; @@ -343,7 +343,7 @@ void DebugPortImpl::CreateThread() { continue; } - ret = port_->Write(&*parcel->GetRaw().cbegin(), len); + ret = port_->Write(parcel->GetData(), len); if (ret < 0) { _E("Failed to write data"); SetConnectionStatus(false); diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index ba6ba66..75f5805 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -22,23 +22,15 @@ namespace rpc_port { namespace internal { -Parcel::Parcel() { - parcel_create(&handle_); -} +Parcel::Parcel() {} -Parcel::~Parcel() { - if (handle_) - parcel_destroy(handle_); -} +Parcel::~Parcel() {} void Parcel::WriteToParcel(tizen_base::Parcel* parcel) const { parcel->WriteParcelable(header_); - void* raw = nullptr; - uint32_t size = 0; - parcel_get_raw(handle_, &raw, &size); - parcel->WriteUInt32(size); - parcel->Write(raw, size); + parcel->WriteUInt32(handle_.GetDataSize()); + parcel->Write(handle_.GetData(), handle_.GetDataSize()); } void Parcel::ReadFromParcel(tizen_base::Parcel* parcel) { @@ -47,15 +39,14 @@ void Parcel::ReadFromParcel(tizen_base::Parcel* parcel) { uint32_t size = 0; parcel->ReadUInt32(&size); if (size > 0) { - auto buf = new (std::nothrow) uint8_t[size]; + auto* buf = static_cast(malloc(size)); if (buf == nullptr) { _E("Out of memory"); return; } - std::unique_ptr ptr(buf); parcel->Read(buf, size); - parcel_reset(handle_, buf, size); + handle_ = std::move(tizen_base::Parcel(buf, size, false)); } } @@ -64,7 +55,7 @@ const ParcelHeader* Parcel::GetParcelHeader() { } parcel_h Parcel::GetHandle() const { - return handle_; + return static_cast(const_cast(&handle_)); } } // namespace internal diff --git a/src/parcel-internal.hh b/src/parcel-internal.hh index 77507fb..6922003 100644 --- a/src/parcel-internal.hh +++ b/src/parcel-internal.hh @@ -19,6 +19,8 @@ #include +#include + #include #include "parcel-header-internal.hh" @@ -39,7 +41,7 @@ class Parcel : public tizen_base::Parcelable { private: ParcelHeader header_; - parcel_h handle_ = nullptr; + tizen_base::Parcel handle_; }; } // namespace internal diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 771a303..8ddb569 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -53,15 +53,14 @@ std::string GenInstance() { int SendRequest(ClientSocket* client, const Request& request) { tizen_base::Parcel parcel; parcel.WriteParcelable(const_cast(request)); - const std::vector& raw = parcel.GetRaw(); - size_t size = raw.size(); + size_t size = parcel.GetDataSize(); int ret = client->Send(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { _E("Send() is failed. error(%d)", ret); return -1; } - ret = client->Send(raw.data(), raw.size()); + ret = client->Send(parcel.GetData(), size); if (ret != 0) { _E("Send() is failed. error(%d)", ret); return -1; @@ -78,14 +77,20 @@ int ReceiveResponse(ClientSocket* client, Response** response) { return -1; } - std::vector buf(size); - ret = client->Receive(buf.data(), size); + uint8_t* buf = static_cast(malloc(size)); + if (buf == nullptr) { + _E("Out of memory"); + return -1; + } + + ret = client->Receive(buf, size); if (ret != 0) { _E("Receive() is failed. error(%d)", ret); + free(buf); return -1; } - tizen_base::Parcel parcel(buf.data(), buf.size()); + tizen_base::Parcel parcel(buf, size, false); *response = new (std::nothrow) Response(); if (*response == nullptr) { _E("Out of memory"); diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 35361db..86af7b3 100644 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -62,7 +62,7 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, if (len <= 0 || len > MAX_PARCEL_SIZE) return RPC_PORT_ERROR_IO_ERROR; - buf = new (std::nothrow) unsigned char[len]; + buf = static_cast(malloc(len)); if (buf == nullptr) { _E("Out of memory"); return RPC_PORT_ERROR_IO_ERROR; @@ -70,7 +70,7 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, ret = rpc_port_read(port, buf, len); if (ret != 0) { - delete[] buf; + free(buf); return ret; } } @@ -78,13 +78,12 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, auto* parcel = new (std::nothrow) internal::Parcel(); if (parcel == nullptr) { _E("Out of memory"); - delete[] buf; + free(buf); return RPC_PORT_ERROR_IO_ERROR; } - tizen_base::Parcel raw_parcel(buf, len); + tizen_base::Parcel raw_parcel(buf, len, false); raw_parcel.ReadParcelable(parcel); - delete[] buf; *h = static_cast(parcel); return RPC_PORT_ERROR_NONE; } @@ -96,9 +95,8 @@ RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { auto* parcel = static_cast(h); tizen_base::Parcel raw_parcel; raw_parcel.WriteParcelable(*parcel); - const std::vector& raw_data = raw_parcel.GetRaw(); - void* raw = reinterpret_cast(const_cast(&raw_data[0])); - uint32_t len = raw_data.size(); + void* raw = reinterpret_cast(raw_parcel.GetData()); + uint32_t len = raw_parcel.GetDataSize(); if (len <= 0) return RPC_PORT_ERROR_INVALID_PARAMETER; diff --git a/src/stub-internal.cc b/src/stub-internal.cc index 5a9d014..5508bc4 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -69,15 +69,14 @@ int ReceiveRequest(ClientSocket* client, Request** request) { int SendResponse(ClientSocket* client, const Response& response) { tizen_base::Parcel parcel; parcel.WriteParcelable(const_cast(response)); - const std::vector& raw = parcel.GetRaw(); - size_t size = raw.size(); + size_t size = parcel.GetDataSize(); int ret = client->Send(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { _E("Send() is failed. error(%d)", ret); return -1; } - ret = client->Send(raw.data(), raw.size()); + ret = client->Send(parcel.GetData(), size); if (ret != 0) { _E("Send() is failed. error(%d)", ret); return -1; -- 2.7.4 From 6629e6615e87dbbbb58946ce63d7ad330ca43a7d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 27 Sep 2022 05:30:49 +0000 Subject: [PATCH 10/16] Fix static analysis issue The following issue is fixed: - ODR_VIOLATION Change-Id: Icece742e174148c3af52fed4e7346a04b51e1790 Signed-off-by: Hwankyu Jhun --- src/exception-internal.cc | 2 -- src/exception-internal.hh | 2 +- src/request-internal.cc | 4 ---- src/request-internal.hh | 4 ++-- src/response-internal.cc | 2 -- src/response-internal.hh | 2 +- utils/message.cc | 2 -- utils/message.hh | 2 +- 8 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/exception-internal.cc b/src/exception-internal.cc index 8e21f20..2af6bfb 100644 --- a/src/exception-internal.cc +++ b/src/exception-internal.cc @@ -26,8 +26,6 @@ Exception::Exception(int error_code, const std::string& file, int line) message_(std::move(GetErrorMessage(error_code_, file, line))) { } -Exception::~Exception() = default; - const char* Exception::what() const noexcept { return message_.c_str(); } diff --git a/src/exception-internal.hh b/src/exception-internal.hh index 4f52240..655fbae 100644 --- a/src/exception-internal.hh +++ b/src/exception-internal.hh @@ -28,7 +28,7 @@ namespace internal { class Exception : public std::exception { public: explicit Exception(int error_code, const std::string& file, int line); - virtual ~Exception(); + virtual ~Exception() = default; virtual const char* what() const noexcept; int GetErrorCode(); diff --git a/src/request-internal.cc b/src/request-internal.cc index af78026..c293c29 100644 --- a/src/request-internal.cc +++ b/src/request-internal.cc @@ -26,10 +26,6 @@ Request::Request(std::string instance, std::string port_type) port_type_(std::move(port_type)) { } -Request::Request() = default; - -Request::~Request() = default; - void Request::SetPortType(std::string port_type) { port_type_ = std::move(port_type); } diff --git a/src/request-internal.hh b/src/request-internal.hh index bd72505..3aa9b05 100644 --- a/src/request-internal.hh +++ b/src/request-internal.hh @@ -28,8 +28,8 @@ namespace internal { class Request : public tizen_base::Parcelable { public: Request(std::string instance, std::string port_type); - Request(); - ~Request(); + Request() = default; + ~Request() = default; void SetPortType(std::string port_type); const std::string& GetInstance(); diff --git a/src/response-internal.cc b/src/response-internal.cc index 3583dde..9d32604 100644 --- a/src/response-internal.cc +++ b/src/response-internal.cc @@ -25,8 +25,6 @@ Response::Response(int result) : result_(result) { Response::Response() : result_(0) { } -Response::~Response() = default; - int Response::GetResult() { return result_; } diff --git a/src/response-internal.hh b/src/response-internal.hh index 25227d3..2c12ab2 100644 --- a/src/response-internal.hh +++ b/src/response-internal.hh @@ -27,7 +27,7 @@ class Response : public tizen_base::Parcelable { public: explicit Response(int result); Response(); - ~Response(); + ~Response() = default; int GetResult(); diff --git a/utils/message.cc b/utils/message.cc index 47be341..c4145bc 100644 --- a/utils/message.cc +++ b/utils/message.cc @@ -41,8 +41,6 @@ Message::Message(time_t time, int pid, std::string port_name, data_(std::move(data)) { } -Message::~Message() = default; - void Message::Print() { struct tm sent_time; localtime_r(&time_, &sent_time); diff --git a/utils/message.hh b/utils/message.hh index 9157b2b..098a4f5 100644 --- a/utils/message.hh +++ b/utils/message.hh @@ -30,7 +30,7 @@ class Message { Message(time_t time, int pid, std::string port_name, std::string destination, bool is_delegate, int port, bool is_read, uint32_t seq, std::vector data); - virtual ~Message(); + virtual ~Message() = default; void Print(); -- 2.7.4 From 1b6d9ceef23c57fedc4099bd4ef1fb83d65565ad Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 27 Sep 2022 06:56:16 +0000 Subject: [PATCH 11/16] Release version 1.13.6 Changes: - Use modified tizen_base::Parcel - Fix static analysis issue Change-Id: Ifad26b8f42b17f3b793f751659203e6e27ccccc1 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 5144054..650f8b2 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.13.5 +Version: 1.13.6 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From fd1c15c4a95a4092008d27583f0c7c3d9ae62f5b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 28 Sep 2022 10:27:29 +0000 Subject: [PATCH 12/16] Fix bugs about getting and setting raw data Unfortunately, there is a bug about the raw data of the parcel. When the rpc_port_parcel_get_raw() is called, the function allocates a tizen_base::Parcel to set the raw data internally. Change-Id: I4297f7fab5ba144bafd17366b518627bfbd1e5d1 Signed-off-by: Hwankyu Jhun --- src/parcel-internal.cc | 8 ++++++++ src/parcel-internal.hh | 7 ++++++- src/rpc-port-parcel.cc | 26 +++++++++++++++++--------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index 75f5805..5cb299d 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -58,5 +58,13 @@ parcel_h Parcel::GetHandle() const { return static_cast(const_cast(&handle_)); } +void Parcel::SetRawParcel(tizen_base::Parcel* raw_parcel) { + raw_parcel_.reset(raw_parcel); +} + +tizen_base::Parcel* Parcel::GetRawParcel() const { + return raw_parcel_.get(); +} + } // namespace internal } // namespace rpc_port diff --git a/src/parcel-internal.hh b/src/parcel-internal.hh index 6922003..6c907b8 100644 --- a/src/parcel-internal.hh +++ b/src/parcel-internal.hh @@ -20,9 +20,10 @@ #include #include - #include +#include + #include "parcel-header-internal.hh" namespace rpc_port { @@ -39,9 +40,13 @@ class Parcel : public tizen_base::Parcelable { const ParcelHeader* GetParcelHeader(); parcel_h GetHandle() const; + void SetRawParcel(tizen_base::Parcel* raw_parcel); + tizen_base::Parcel* GetRawParcel() const; + private: ParcelHeader header_; tizen_base::Parcel handle_; + std::unique_ptr raw_parcel_ { nullptr }; }; } // namespace internal diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 86af7b3..12782ee 100644 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -415,9 +415,10 @@ RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void** array, return RPC_PORT_ERROR_INVALID_PARAMETER; auto* parcel = static_cast(h); - void* raw = nullptr; - uint32_t raw_size = 0; - parcel_get_raw(parcel->GetHandle(), &raw, &raw_size); + tizen_base::Parcel raw_parcel; + raw_parcel.WriteParcelable(*parcel); + void* raw = raw_parcel.GetData(); + uint32_t raw_size = raw_parcel.GetDataSize();; if (raw_size == 0) { _E("raw_size is zero"); return RPC_PORT_ERROR_IO_ERROR; @@ -440,7 +441,8 @@ RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void* array, auto* parcel = static_cast(h); uint32_t valid_size = size & UINT32_MAX; - parcel_reset(parcel->GetHandle(), array, valid_size); + tizen_base::Parcel raw_parcel(array, valid_size); + raw_parcel.ReadParcelable(parcel); return RPC_PORT_ERROR_NONE; } @@ -517,12 +519,18 @@ RPC_API int rpc_port_parcel_get_raw(rpc_port_parcel_h h, void** raw, return RPC_PORT_ERROR_INVALID_PARAMETER; auto* parcel = static_cast(h); - void* raw_data = nullptr; - uint32_t raw_size = 0; - parcel_get_raw(parcel->GetHandle(), &raw_data, &raw_size); + auto* raw_parcel = new (std::nothrow) tizen_base::Parcel(); + if (raw_parcel != nullptr) { + raw_parcel->WriteParcelable(*parcel); + parcel->SetRawParcel(raw_parcel); + *raw = raw_parcel->GetData(); + *size = static_cast(raw_parcel->GetDataSize()); + } else { + _E("Out of memory"); + *raw = nullptr; + *size = 0; + } - *raw = raw_data; - *size = static_cast(raw_size); return RPC_PORT_ERROR_NONE; } -- 2.7.4 From 04fa14c796d9d939647ceb149a5f70b8f6d2cb79 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 28 Sep 2022 23:20:50 +0000 Subject: [PATCH 13/16] Release version 1.13.7 Changes: - Fix bugs about getting and setting raw data Change-Id: I55f35f2f2506158285f6b3f07ac8a924e73e6206 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 650f8b2..19ef7b9 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.13.6 +Version: 1.13.7 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 98c79873c97089db94449b57c2603dc43f0bef14 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 4 Oct 2022 11:47:34 +0900 Subject: [PATCH 14/16] Fix wrong exception handling Change-Id: Ifd4f0104ad69dbcaddbdc31a75e84b676471716e Signed-off-by: Changgyu Choi --- benchmark/server/main.cc | 21 +++++++++--------- benchmark/tool/main.cc | 58 ++++++++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/benchmark/server/main.cc b/benchmark/server/main.cc index c4466cf..9be81a1 100644 --- a/benchmark/server/main.cc +++ b/benchmark/server/main.cc @@ -29,14 +29,14 @@ namespace bs = rpc_port::BenchmarkStub::stub; class TestService : public bs::Benchmark::ServiceBase { public: class Factory : public bs::Benchmark::ServiceBase::Factory { - public: - virtual ~Factory() = default; - - std::unique_ptr - CreateService(std::string sender, std::string instance) { - return std::unique_ptr( - new TestService(sender, instance)); - } + public: + virtual ~Factory() = default; + + std::unique_ptr + CreateService(std::string sender, std::string instance) { + return std::unique_ptr( + new TestService(sender, instance)); + } }; TestService(std::string sender, std::string instance) : @@ -75,9 +75,10 @@ class MainLoop { try { stub_.Listen(std::shared_ptr( new TestService::Factory())); - } catch (const std::exception& e) { - _E("stub listen is failed(%s)", e.what()); + } catch (const bs::Exception&) { + _E("stub listen is failed"); } + g_main_loop_run(loop_); } diff --git a/benchmark/tool/main.cc b/benchmark/tool/main.cc index 580eb69..8abe412 100644 --- a/benchmark/tool/main.cc +++ b/benchmark/tool/main.cc @@ -65,8 +65,8 @@ class Tester { void Run(int argc, char** argv) { options_ = rpc_port::benchmark::Options::Parse(argc, argv); if (!options_) { - _E("options is nullptr"); - exit(1); + std::cerr << "options is unllptr" << std::endl; + return; } ExecuteServer(); @@ -75,28 +75,36 @@ class Tester { try { proxy_->Connect(true); } catch (const bp::Exception& e) { - _E("Connect() failed"); - exit(1); + std::cerr << "Connect() failed" << std::endl; + return; + } catch (const std::exception& e) { + std::cerr << "Connect() failed. " << e.what() << std::endl; + return; } printf("%15s\t%15s\t%15s\t\t%15s\t\t%15s\n", "Iterations", "Data size", "Time", "Throughput", "Latency"); - if (options_->IsAll()) { - DoTest(4000, 10); - DoTest(4000, 20); - DoTest(4000, 100); - DoTest(4000, 200); - DoTest(2000, 1000); - DoTest(2000, 2000); - DoTest(1000, 10000); - DoTest(1000, 20000); - DoTest(1000, 30000); - DoTest(1000, 40000); - DoTest(1000, 50000); - DoTest(1000, 60000); - DoTest(500, 100000); - } else { - DoTest(options_->GetIters(), options_->GetSize()); + + try { + if (options_->IsAll()) { + DoTest(4000, 10); + DoTest(4000, 20); + DoTest(4000, 100); + DoTest(4000, 200); + DoTest(2000, 1000); + DoTest(2000, 2000); + DoTest(1000, 10000); + DoTest(1000, 20000); + DoTest(1000, 30000); + DoTest(1000, 40000); + DoTest(1000, 50000); + DoTest(1000, 60000); + DoTest(500, 100000); + } else { + DoTest(options_->GetIters(), options_->GetSize()); + } + } catch (const bp::Exception& e) { + std::cerr << "test failed" << std::endl; } } @@ -134,7 +142,8 @@ class Tester { } void EndTime(int iters, int size) { - std::chrono::duration sec = std::chrono::system_clock::now() - start_; + std::chrono::duration sec = + std::chrono::system_clock::now() - start_; double t = size * iters * 8 / sec.count() / 1024 / 1024; double l = sec.count() * 1000 / iters; @@ -175,11 +184,6 @@ class Tester { int main(int argc, char** argv) { Tester tester; - try { - tester.Run(argc, argv); - } catch (const std::exception& e) { - std::cerr << "Exception occurred!!!" << e.what() << std::endl; - } - + tester.Run(argc, argv); return 0; } -- 2.7.4 From b3ad5d660c267deb2276dc43d8a95bb5ed0cfcc6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 12 Oct 2022 06:41:39 +0000 Subject: [PATCH 15/16] Release the client handle When the client application calls the rpc_port_proxy_connect() function after the diconnected event is received, the main_client_ and the delegate_client_ handles have to be released. Change-Id: I2aeef18323bc9f438b048cfef42fb9dd1c82f62e Signed-off-by: Hwankyu Jhun --- src/proxy-internal.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 8ddb569..7816276 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -206,6 +206,8 @@ int Proxy::Connect(std::string appid, std::string port_name, target_appid_ = std::move(appid); port_name_ = std::move(port_name); SetRealAppId(target_appid_); + main_port_.reset(); + delegate_port_.reset(); UnsetConnTimer(); int ret = Aul::PrepareStub(real_appid_, port_name_, -- 2.7.4 From 2ef2bea64aa235d172daaefc5e5776d6b4f51288 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 17 Oct 2022 13:14:44 +0900 Subject: [PATCH 16/16] Fix static analysis issues Change-Id: I443f2472f98001c1b279cc27d835dc341024e846 Signed-off-by: Changgyu Choi --- src/client-socket-internal.cc | 8 ++++---- src/peer-cred-internal.cc | 2 +- src/rpc-port-parcel.cc | 4 ++-- src/server-socket-internal.cc | 2 +- utils/debug-port.cc | 4 ++-- utils/message.cc | 3 ++- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/client-socket-internal.cc b/src/client-socket-internal.cc index 4fbb344..c932342 100644 --- a/src/client-socket-internal.cc +++ b/src/client-socket-internal.cc @@ -62,7 +62,7 @@ int ClientSocket::Connect(const std::string& endpoint) { snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s", endpoint.c_str()); struct sockaddr* sockaddr_ptr = reinterpret_cast(&sockaddr); - socklen_t len = sizeof(sockaddr); + socklen_t len = static_cast(sizeof(sockaddr)); int ret = connect(GetFd(), sockaddr_ptr, len); fcntl(GetFd(), F_SETFL, flag); if (ret < 0) { @@ -142,7 +142,7 @@ int ClientSocket::GetSendBufferSize() { int ClientSocket::GetReceiveTimeout() { struct timeval timeout = { 0, }; - socklen_t len = sizeof(struct timeval); + socklen_t len = static_cast(sizeof(struct timeval)); int ret = getsockopt(GetFd(), SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&timeout), &len); if (ret < 0) { @@ -156,7 +156,7 @@ int ClientSocket::GetReceiveTimeout() { } void ClientSocket::SetReceiveBufferSize(int size) { - socklen_t len = sizeof(size); + socklen_t len = static_cast(sizeof(size)); int ret = setsockopt(GetFd(), SOL_SOCKET, SO_RCVBUF, &size, len); if (ret < 0) { ret = -errno; @@ -191,7 +191,7 @@ void ClientSocket::SetReceiveTimeout(int timeout) { .tv_sec = static_cast(timeout / 1000), .tv_usec = static_cast((timeout % 1000) * 1000) }; - socklen_t len = sizeof(struct timeval); + socklen_t len = static_cast(sizeof(struct timeval)); int ret = setsockopt(GetFd(), SOL_SOCKET, SO_RCVTIMEO, &tv, len); if (ret < 0) { ret = -errno; diff --git a/src/peer-cred-internal.cc b/src/peer-cred-internal.cc index eebc131..e978e0f 100644 --- a/src/peer-cred-internal.cc +++ b/src/peer-cred-internal.cc @@ -31,7 +31,7 @@ PeerCred::PeerCred(pid_t pid, uid_t uid, gid_t gid) PeerCred* PeerCred::Get(int fd) { struct ucred cred; - socklen_t len = sizeof(struct ucred); + socklen_t len = static_cast(sizeof(struct ucred)); int ret = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, static_cast(&cred), &len); if (ret != 0) { diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 12782ee..098a53a 100644 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -96,7 +96,7 @@ RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { tizen_base::Parcel raw_parcel; raw_parcel.WriteParcelable(*parcel); void* raw = reinterpret_cast(raw_parcel.GetData()); - uint32_t len = raw_parcel.GetDataSize(); + uint32_t len = static_cast(raw_parcel.GetDataSize()); if (len <= 0) return RPC_PORT_ERROR_INVALID_PARAMETER; @@ -418,7 +418,7 @@ RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void** array, tizen_base::Parcel raw_parcel; raw_parcel.WriteParcelable(*parcel); void* raw = raw_parcel.GetData(); - uint32_t raw_size = raw_parcel.GetDataSize();; + size_t raw_size = raw_parcel.GetDataSize(); if (raw_size == 0) { _E("raw_size is zero"); return RPC_PORT_ERROR_IO_ERROR; diff --git a/src/server-socket-internal.cc b/src/server-socket-internal.cc index 228e75b..4f60c20 100644 --- a/src/server-socket-internal.cc +++ b/src/server-socket-internal.cc @@ -42,7 +42,7 @@ bool ServerSocket::IsClosed() { ClientSocket* ServerSocket::Accept() { struct sockaddr_un addr = { 0, }; - socklen_t len = sizeof(struct sockaddr_un); + socklen_t len = static_cast(sizeof(struct sockaddr_un)); auto* addr_ptr = reinterpret_cast(&addr); int client_fd = accept(GetFd(), addr_ptr, &len); if (client_fd == -1) { diff --git a/utils/debug-port.cc b/utils/debug-port.cc index b1c5fc7..08a80ea 100644 --- a/utils/debug-port.cc +++ b/utils/debug-port.cc @@ -219,7 +219,7 @@ void DebugPort::Unwatch() { int DebugPort::Accept(struct ucred* cred) { struct sockaddr_un addr = { 0, }; - socklen_t socklen = sizeof(addr); + socklen_t socklen = static_cast(sizeof(addr)); int client_fd = accept(fd_, reinterpret_cast(&addr), &socklen); if (client_fd < 0) { @@ -227,7 +227,7 @@ int DebugPort::Accept(struct ucred* cred) { return -1; } - socklen = sizeof(struct ucred); + socklen = static_cast(sizeof(struct ucred)); int ret = getsockopt(client_fd, SOL_SOCKET, SO_PEERCRED, cred, &socklen); if (ret < 0) { diff --git a/utils/message.cc b/utils/message.cc index c4145bc..e62bd3e 100644 --- a/utils/message.cc +++ b/utils/message.cc @@ -69,7 +69,8 @@ void Message::Hexdump() { break; std::cout << std::setw(8) << address; - nread = ((data_.size() - address) > 16) ? 16 : (data_.size() - address); + nread = static_cast( + ((data_.size() - address) > 16) ? 16 : (data_.size() - address)); for (unsigned int i = 0; i < 16; ++i) { if (i % 8 == 0) -- 2.7.4