Some apps want to set aul request timeout.
If there is a timeout value in the bundle, it changes the socket timeout to that value.
Change-Id: Ic8fd03dbce72ebed3ebc669f4ac11e2776eeaa6d
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
* @brief Definition for AUL: The value of indicating a enabled light user for app.
* @since_tizen 7.0
*/
-#define AUL_K_ENABLED_LIGHT_USER "__AUL_ENABLED_LIGHT_USER__"
+#define AUL_K_ENABLED_LIGHT_USER "__AUL_ENABLED_LIGHT_USER__"
/**
* @brief Definition for AUL: The complication mode.
* @brief Definition for AUL: The package event name.
* @since_tizen 7.0
*/
-#define AUL_K_PKG_EVENT_NAME "__AUL_K_PKG_EVENT_NAME__"
+#define AUL_K_PKG_EVENT_NAME "__AUL_K_PKG_EVENT_NAME__"
/**
* @brief Definition for AUL: The package event
* @since_tizen 7.0
*/
-#define AUL_K_PKG_EVENT_RESULT "__AUL_K_PKG_EVENT_RESULT__"
+#define AUL_K_PKG_EVENT_RESULT "__AUL_K_PKG_EVENT_RESULT__"
+
+
+/**
+ * @brief Definition for AUL: The socket timeout milli seconds.
+ * @since_tizen 7.5
+ */
+#define AUL_K_SOCKET_TIMEOUT "__AUL_SOCKET_TIMEOUT__"
return context;
}
-static void __process_app_pkt(app_pkt_t *pkt, int clifd)
+static void __process_app_pkt(app_pkt_t *pkt, int clifd, aul_worker_h worker)
{
struct aul_request_s *req;
bundle *b = NULL;
+ char *timeout_str;
+ unsigned int timeout = 5000;
+ int ret;
if (pkt->opt & AUL_SOCK_BUNDLE) {
b = bundle_decode(pkt->data, pkt->len);
_E("Failed to decode the packet");
return;
}
+
+ ret = bundle_get_str(b, AUL_K_SOCKET_TIMEOUT, &timeout_str);
+ if (ret == BUNDLE_ERROR_NONE && isdigit(timeout_str[0])) {
+ timeout = atoi(timeout_str);
+ _I("timeout: %ums", timeout);
+ }
}
req = __create_request(pkt->cmd, clifd, b);
return;
}
+ aul_worker_add_anr_timer(worker, pkt->cmd, timeout);
__g_idle_add_full(__get_glib_context(pkt->cmd, b), G_PRIORITY_DEFAULT,
__dispatch_request, req);
}
return true;
}
- aul_worker_add_anr_timer(worker, pkt->cmd);
- __process_app_pkt(pkt, fd);
+ __process_app_pkt(pkt, fd, worker);
free(pkt);
return true;
}
}
- aul_worker_add_anr_timer(worker, pkt->cmd);
- __process_app_pkt(pkt, clifd);
+ __process_app_pkt(pkt, clifd, worker);
if (pkt->cmd == WIDGET_GET_CONTENT)
clifd = -1;
#include <bundle_cpp.h>
#include "aul_api.h"
+#include "aul_key.h"
#include "aul_util.h"
#include "aul/socket/client_socket.hh"
int MAX_FDS = sysconf(_SC_OPEN_MAX);
constexpr const char DEST_PROCESS[] = "amd";
+constexpr unsigned int SOCKET_TIMEOUT_MIN = 5000U;
+constexpr unsigned int SOCKET_TIMEOUT_MAX = 30000U;
+
// POD type
struct PacketHeader {
int cmd;
return ret;
}
+int SendAndReceiveWithTimeout(int pid, uid_t uid, int cmd, unsigned char* data,
+ int datalen, int opt, int timeout) {
+ int ret;
+ try {
+ ClientSocket client;
+ client.Connect(GetSocketPath(pid, uid));
+ aul_sock_set_sock_option(client.GetFd(), 1);
+ _W("timeout: %dms", timeout);
+ client.SetReceiveTimeout(timeout);
+
+ const auto& inherit = CPUInheritance(pid, cmd);
+ ret = SendAndReceive(&client, cmd, data, datalen, opt);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
+ return e.GetErrorCode();
+ }
+
+ return ret;
+}
+
int ReceiveAppPacket(ClientSocket* client, app_pkt_t** out_pkt) {
PacketHeader header;
static_assert(std::is_standard_layout<PacketHeader>(),
closedir(dp);
}
+unsigned int GetSocketTimeout(unsigned int timeout) {
+ return std::min(std::max(timeout, SOCKET_TIMEOUT_MIN), SOCKET_TIMEOUT_MAX);
+}
+
SocketTimeout socket_timeout;
SocketLink socket_link;
return -EINVAL;
tizen_base::Bundle b(kb, false, false);
- auto raw = b.ToRaw();
- return SendAndReceive(pid, uid, cmd,
- reinterpret_cast<unsigned char*>(raw.first.get()), raw.second,
- opt | AUL_SOCK_BUNDLE);
+ std::string timeout_str = b.GetString(AUL_K_SOCKET_TIMEOUT);
+ if (timeout_str.empty() || !isdigit(timeout_str[0])) {
+ auto [ptr, size] = b.ToRaw();
+ return SendAndReceive(pid, uid, cmd,
+ reinterpret_cast<unsigned char*>(ptr.get()),
+ size, opt | AUL_SOCK_BUNDLE);
+ }
+
+ unsigned int timeout = static_cast<unsigned int>(std::stoi(timeout_str));
+ if (timeout < SOCKET_TIMEOUT_MIN || timeout > SOCKET_TIMEOUT_MAX) {
+ timeout = GetSocketTimeout(timeout);
+ b.Delete(AUL_K_SOCKET_TIMEOUT);
+ b.Add(AUL_K_SOCKET_TIMEOUT, std::to_string(timeout));
+ }
+
+ auto [ptr, size] = b.ToRaw();
+ return SendAndReceiveWithTimeout(
+ pid, uid, cmd, reinterpret_cast<unsigned char*>(ptr.get()), size,
+ opt | AUL_SOCK_BUNDLE, timeout);
}
extern "C" API app_pkt_t* aul_sock_recv_pkt(int fd, int* clifd,
#define AUL_SVC_K_WIN_ID "__APP_SVC_K_WIN_ID__"
/** AUL SVC internal private key */
#define AUL_SVC_K_LAUNCH_MODE "__APP_SVC_LAUNCH_MODE__"
-
-
return G_SOURCE_REMOVE;
}
-int aul_worker_add_anr_timer(aul_worker_h handle, int cmd)
+int aul_worker_add_anr_timer(aul_worker_h handle, int cmd, unsigned int timeout)
{
struct aul_worker_s *worker = handle;
struct anr_timer_s *anr_timer;
current_time = g_get_monotonic_time();
if (anr_timer->start_time == 0) {
- interval = DEFAULT_INTERVAL;
+ interval = timeout;
anr_timer->start_time = current_time;
} else {
elapsed_time = (unsigned int)((current_time -
anr_timer->start_time) / 1000);
- interval = DEFAULT_INTERVAL + (DEFAULT_INTERVAL - elapsed_time);
+ interval = timeout + (DEFAULT_INTERVAL - elapsed_time);
anr_timer->start_time = current_time;
}
void aul_worker_remove_io_job(aul_worker_h handle, int fd);
-int aul_worker_add_anr_timer(aul_worker_h handle, int cmd);
+int aul_worker_add_anr_timer(aul_worker_h handle,
+ int cmd, unsigned int timeout);
int aul_worker_remove_anr_timer(aul_worker_h handle);