The default timeout is increased to 25 seconds.
The following functions are added internally:
- rpc_port_set_timeout()
- rpc_port_get_timeout()
Change-Id: I6ae46d956c30e33606a74cd312a1b37ac67c2b02
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* @param[out] has_request The flag, if true, the pending request exists
* @return @c 0 on success,
* otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
* @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
*/
int rpc_port_stub_has_pending_request(rpc_port_stub_h h, bool *has_request);
+/**
+ * @brief Sets the timeout for the rpc port.
+ * @since_tizen 9.0
+ * @param[in] timeout The timeout in milliseconds
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see rpc_port_get_timeout()
+ */
+int rpc_port_set_timeout(int timeout);
+
+/**
+ * @brief Gets the timeout of the rpc port.
+ * @since_tizen 9.0
+ * @return The timeout in milliseconds
+ * @see rpc_port_set_timeout()
+ */
+int rpc_port_get_timeout(void);
+
#ifdef __cplusplus
}
#endif
+ADD_DEFINITIONS("-DRPC_PORT_TIMEOUT=25000")
+
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} RPC_PORT_SRCS)
ADD_LIBRARY(${TARGET_RPC_PORT} SHARED ${RPC_PORT_SRCS})
#include <sys/un.h>
#include <unistd.h>
+#include "include/rpc-port-internal.h"
#include "rpc-port/exception-internal.hh"
#include "rpc-port/log-private.hh"
_E("socket() is failed. errno(%d)", errno);
THROW(fd_);
} // LCOV_EXCL_STOP
+
+ SetReceiveTimeout(-1);
}
-ClientSocket::ClientSocket(int fd) : fd_(fd) { SetCloseOnExec(); }
+ClientSocket::ClientSocket(int fd) : fd_(fd) {
+ SetCloseOnExec();
+ SetReceiveTimeout(-1);
+}
ClientSocket::~ClientSocket() {
if (!IsClosed()) Close();
if (timeout == INT_MAX) return; // LCOV_EXCL_LINE
if (timeout == -1)
- timeout = 5000;
+ timeout = rpc_port_get_timeout();
if (timeout < 0) { // LCOV_EXCL_START
_E("Invalid parameter");
* limitations under the License.
*/
+#include "rpc-port/port-internal.hh"
+
#include <aul_rpc_port.h>
#include <dlog.h>
#include <fcntl.h>
#include <chrono>
#include <utility>
+#include "include/rpc-port-internal.h"
#include "include/rpc-port.h"
-#include "log-private.hh"
-#include "message-sending-thread-internal.hh"
-#include "port-internal.hh"
+#include "rpc-port/log-private.hh"
+#include "rpc-port/message-sending-thread-internal.hh"
namespace rpc_port {
namespace internal {
uuid_generate(u);
uuid_unparse(u, uuid);
instance_ = std::string(uuid) + ":" + id_;
- SetReceiveTimeout(10000);
+ if (read_fd > -1) SetReceiveTimeout(-1);
}
Port::Port(int read_fd, int write_fd, std::string id, std::string instance)
id_(std::move(id)),
instance_(std::move(instance)),
seq_(0) {
- SetReceiveTimeout(10000);
+ if (read_fd > -1) SetReceiveTimeout(10000);
}
Port::~Port() {
int Port::SetReceiveTimeout(int timeout) {
if (timeout == INT_MAX) return -EINVAL;
- if (timeout == -1) timeout = 10000;
+ if (timeout == -1) timeout = rpc_port_get_timeout();
if (timeout < 0) {
_E("Invalid parameter");
return PORT_STATUS_ERROR_NONE;
}
-void Port::SetReadFd(int read_fd) { read_fd_ = read_fd; }
+void Port::SetReadFd(int read_fd) {
+ read_fd_ = read_fd;
+ if (read_fd_ > -1) SetReceiveTimeout(-1);
+}
int Port::GetReadFd() const { return read_fd_; }
bool Proxy::WaitUntilPortCreation() {
file_monitor_.reset(new FileMonitor(port_path_));
- int retry_count = 100;
+ int retry_count = rpc_port_get_timeout() / 1000;
do {
if (file_monitor_->Exist()) return true;
// LCOV_EXCL_STOP
}
- GSource* source = g_timeout_source_new(10 * 1000);
+ GSource* source = g_timeout_source_new(rpc_port_get_timeout());
if (source == nullptr) {
// LCOV_EXCL_START
_E("g_timeout_source_new() is failed");
* limitations under the License.
*/
+#include "include/rpc-port-internal.h"
+
#include <aul_proc.h>
#include <sys/types.h>
#include <tzplatform_config.h>
#include <atomic>
-#include "include/rpc-port-internal.h"
#include "include/rpc-port.h"
-#include "peer-cred-internal.hh"
-#include "port-internal.hh"
+#include "rpc-port/log-private.hh"
+#include "rpc-port/peer-cred-internal.hh"
+#include "rpc-port/port-internal.hh"
#undef RPC_API
#define RPC_API extern "C" __attribute__((visibility("default")))
constexpr uid_t kRegularUidMin = 5000;
std::atomic<uid_t> __target_uid { getuid() };
+std::atomic<int> rpc_port_timeout { RPC_PORT_TIMEOUT };
} // namespace
return RPC_PORT_ERROR_NONE;
}
-RPC_API int rpc_port_get_peer_info(rpc_port_h h, pid_t* pid, uid_t* uid) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+RPC_API int rpc_port_get_peer_info(rpc_port_h h, pid_t* pid, uid_t* uid) {
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto port = static_cast<Port*>(h);
std::shared_ptr<PeerCred> cred(PeerCred::Get(port->GetReadFd()));
- if (cred.get() == nullptr)
- return RPC_PORT_ERROR_IO_ERROR;
+ if (cred.get() == nullptr) return RPC_PORT_ERROR_IO_ERROR;
+
+ if (pid) *pid = cred->GetPid();
+ if (uid) *uid = cred->GetUid();
- if (pid)
- *pid = cred->GetPid();
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_set_timeout(int timeout) {
+ if (timeout == INT_MAX) return RPC_PORT_ERROR_INVALID_PARAMETER;
- if (uid)
- *uid = cred->GetUid();
+ if (timeout == -1) timeout = RPC_PORT_TIMEOUT;
+ if (timeout < 0) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ _E("timeout=%d", timeout);
+ rpc_port_timeout.exchange(timeout);
return RPC_PORT_ERROR_NONE;
}
+RPC_API int rpc_port_get_timeout(void) {
+ set_last_result(RPC_PORT_ERROR_NONE);
+ return rpc_port_timeout;
+}
}, this);
ASSERT_EQ(ret, 0);
+ rpc_port_set_timeout(5000);
ret = rpc_port_proxy_connect(proxy_handle_, "TestApp", "wrong_port");
ASSERT_EQ(ret, 0);
- guint tag = g_timeout_add_seconds(15,
+ guint tag = g_timeout_add_seconds(10,
[](gpointer data) -> gboolean {
auto* p = static_cast<RpcPortBase*>(data);
p->Finish();
RunMainLoop();
ASSERT_TRUE(touch_proxy_rejected_event_cb_);
g_source_remove(tag);
+ rpc_port_set_timeout(-1);
}
TEST_F(RpcPortConnection, rpc_port_proxy_event_receive_p) {
ASSERT_TRUE(touch_stub_disconnected_event_cb_);
ASSERT_TRUE(touch_proxy_disconnected_event_cb_);
}
+
+TEST_F(RpcPortConnection, rpc_port_set_timeout_P) {
+ int ret = rpc_port_set_timeout(1000);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_EQ(rpc_port_get_timeout(), 1000);
+ rpc_port_set_timeout(-1);
+}
+
+TEST_F(RpcPortConnection, rpc_port_get_timeout_P) {
+ int timeout = rpc_port_get_timeout();
+ ASSERT_EQ(get_last_result(), RPC_PORT_ERROR_NONE);
+ ASSERT_NE(timeout, 0);
+}