From: Hwankyu Jhun Date: Tue, 26 Oct 2021 09:00:41 +0000 (+0900) Subject: Fix Write() method of Port X-Git-Tag: submit/tizen/20211028.054746~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99cc275334f64d281a3e10e5ace5e22e1f15a6a3;p=platform%2Fcore%2Fappfw%2Frpc-port.git Fix Write() method of Port If the data is larger than the maximum socket buffer size, the port divides the data by the maximum socket buffer size and transmits it. And, the queue size of delayed messages is changed to '1024 * 1024 * 10'. Change-Id: I357efb0c55af9bf61abb06dcc49e63f031ba1091 Signed-off-by: Hwankyu Jhun --- diff --git a/src/port-internal.cc b/src/port-internal.cc index aaccee8..7dd3ce6 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -35,7 +35,7 @@ namespace rpc_port { namespace internal { namespace { -constexpr const int QUEUE_SIZE_MAX = 1024 * 1024; +constexpr const int QUEUE_SIZE_MAX = 1024 * 1024 * 10; constexpr const int MAX_RETRY_CNT = 10; constexpr const int MAX_TIMEOUT = 1000; constexpr const int MIN_TIMEOUT = 50; @@ -71,10 +71,13 @@ Port::Port(int fd, std::string id) uuid_generate(u); uuid_unparse(u, uuid); instance_ = std::string(uuid) + ":" + id_; + send_buffer_size_ = GetSendBufferSize(); } Port::Port(int fd, std::string id, std::string instance) - : fd_(fd), id_(std::move(id)), instance_(std::move(instance)), seq_(0) {} + : fd_(fd), id_(std::move(id)), instance_(std::move(instance)), seq_(0) { + send_buffer_size_ = GetSendBufferSize(); +} Port::~Port() { ClearQueue(); @@ -179,6 +182,19 @@ int Port::Read(void* buf, unsigned int size) { return RPC_PORT_ERROR_NONE; } +int Port::GetSendBufferSize() { + int value; + socklen_t len = sizeof(int); + int ret = getsockopt(fd_, SOL_SOCKET, SO_SNDBUF, + reinterpret_cast(&value), &len); + if (ret < 0) { + _E("getsockopt() is failed. errno(%d)", errno); + return 163840; + } + + return value; +} + bool Port::CanRead(int timeout) { struct pollfd fds[1]; fds[0].fd = fd_; @@ -259,7 +275,8 @@ int Port::Write(const void* buf, unsigned int size, int* sent_bytes) { } while (left && (retry_cnt < MAX_RETRY_CNT)) { - nb = send(fd_, buffer, left, MSG_NOSIGNAL); + size_t len = left > send_buffer_size_ ? send_buffer_size_ : left; + nb = send(fd_, buffer, len, MSG_NOSIGNAL); if (nb == -1) { if (errno == EINTR) { LOGI("write_socket: EINTR continue ..."); diff --git a/src/port-internal.hh b/src/port-internal.hh index 853b27f..028e786 100644 --- a/src/port-internal.hh +++ b/src/port-internal.hh @@ -67,6 +67,7 @@ class Port : public std::enable_shared_from_this { } private: + int GetSendBufferSize(); bool CanRead(int timeout); bool CanWrite(); void IgnoreIOEvent(); @@ -102,6 +103,7 @@ class Port : public std::enable_shared_from_this { int fd_; std::string id_; std::string instance_; + size_t send_buffer_size_; std::atomic seq_; mutable std::recursive_mutex mutex_; std::queue> queue_;