summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJo-Philipp Wich2026-03-27 10:29:50 +0000
committerJo-Philipp Wich2026-03-27 10:34:31 +0000
commit5b078674a5929a5c90043c66721d45e1d8eae73d (patch)
tree46d02efccf6c07dd7fdb1dac20889f8d7cfcd8c2
parenta4a5a298588960638a2e1713eb8fb858e1dbedeb (diff)
downloadrpcd-master.tar.gz
optimize by reusing timeout memberHEADmaster
Replace deferred_reply uloop_timeout with timeout reuse in both rpc_exec_context and rpc_file_exec_context. This eliminates redundant state tracking (deferred_reply_pending) and function pointers, reducing struct sizes and code complexity while maintaining deferred reply behavior through callback switching. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--exec.c17
-rw-r--r--file.c19
-rw-r--r--include/rpcd/exec.h2
3 files changed, 8 insertions, 30 deletions
diff --git a/exec.c b/exec.c
index 31dfc68..72533e0 100644
--- a/exec.c
+++ b/exec.c
@@ -122,9 +122,6 @@ rpc_exec_reply(struct rpc_exec_context *c, int rv)
{
uloop_timeout_cancel(&c->timeout);
uloop_process_delete(&c->process);
- uloop_timeout_cancel(&c->deferred_reply);
-
- c->deferred_reply_pending = false;
if (rv == UBUS_STATUS_OK)
{
@@ -159,24 +156,20 @@ rpc_exec_reply(struct rpc_exec_context *c, int rv)
}
static void
-rpc_exec_deferred_reply_cb(struct uloop_timeout *t)
+rpc_exec_reply_cb(struct uloop_timeout *t)
{
struct rpc_exec_context *c =
- container_of(t, struct rpc_exec_context, deferred_reply);
+ container_of(t, struct rpc_exec_context, timeout);
- c->deferred_reply_pending = false;
rpc_exec_reply(c, c->deferred_status);
}
static void
rpc_exec_schedule_reply(struct rpc_exec_context *c, int rv)
{
- if (c->deferred_reply_pending)
- return;
-
c->deferred_status = rv;
- c->deferred_reply_pending = true;
- uloop_timeout_set(&c->deferred_reply, 0);
+ c->timeout.cb = rpc_exec_reply_cb;
+ uloop_timeout_set(&c->timeout, 0);
}
static void
@@ -373,8 +366,6 @@ rpc_exec(const char **args, rpc_exec_write_cb_t in,
c->process.cb = rpc_exec_process_cb;
uloop_process_add(&c->process);
- c->deferred_reply.cb = rpc_exec_deferred_reply_cb;
-
c->timeout.cb = rpc_exec_timeout_cb;
uloop_timeout_set(&c->timeout, rpc_exec_timeout);
diff --git a/file.c b/file.c
index b3bf31f..eeb0713 100644
--- a/file.c
+++ b/file.c
@@ -70,10 +70,8 @@ struct rpc_file_exec_context {
struct uloop_process process;
struct ustream_fd opipe;
struct ustream_fd epipe;
- struct uloop_timeout deferred_reply;
int stat;
int deferred_status;
- bool deferred_reply_pending;
};
@@ -791,9 +789,6 @@ rpc_file_exec_reply(struct rpc_file_exec_context *c, int rv)
{
uloop_timeout_cancel(&c->timeout);
uloop_process_delete(&c->process);
- uloop_timeout_cancel(&c->deferred_reply);
-
- c->deferred_reply_pending = false;
if (rv == UBUS_STATUS_OK)
{
@@ -820,24 +815,20 @@ rpc_file_exec_reply(struct rpc_file_exec_context *c, int rv)
}
static void
-rpc_file_exec_deferred_reply_cb(struct uloop_timeout *t)
+rpc_file_exec_reply_cb(struct uloop_timeout *t)
{
struct rpc_file_exec_context *c =
- container_of(t, struct rpc_file_exec_context, deferred_reply);
+ container_of(t, struct rpc_file_exec_context, timeout);
- c->deferred_reply_pending = false;
rpc_file_exec_reply(c, c->deferred_status);
}
static void
rpc_file_exec_schedule_reply(struct rpc_file_exec_context *c, int rv)
{
- if (c->deferred_reply_pending)
- return;
-
c->deferred_status = rv;
- c->deferred_reply_pending = true;
- uloop_timeout_set(&c->deferred_reply, 0);
+ c->timeout.cb = rpc_file_exec_reply_cb;
+ uloop_timeout_set(&c->timeout, 0);
}
static void
@@ -1061,8 +1052,6 @@ rpc_file_exec_run(const char *cmd, const struct blob_attr *sid,
c->process.cb = rpc_file_exec_process_cb;
uloop_process_add(&c->process);
- c->deferred_reply.cb = rpc_file_exec_deferred_reply_cb;
-
c->timeout.cb = rpc_file_exec_timeout_cb;
uloop_timeout_set(&c->timeout, *ops->exec_timeout);
diff --git a/include/rpcd/exec.h b/include/rpcd/exec.h
index 6c28864..900d6c1 100644
--- a/include/rpcd/exec.h
+++ b/include/rpcd/exec.h
@@ -61,7 +61,6 @@ struct rpc_exec_context {
struct ubus_request_data request;
struct uloop_timeout timeout;
struct uloop_process process;
- struct uloop_timeout deferred_reply;
struct ustream_fd ipipe;
struct ustream_fd opipe;
struct ustream_fd epipe;
@@ -71,7 +70,6 @@ struct rpc_exec_context {
char *err;
int stat;
int deferred_status;
- bool deferred_reply_pending;
void *priv;
bool blob_array;
void *blob_cookie;