diff options
author | Harald Welte <laforge@gnumonks.org> | 2014-08-22 00:28:51 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2014-08-24 16:52:54 +0200 |
commit | 39c9e7b471f29ec1df8b4fc407bb3fe2ac96cb9e (patch) | |
tree | de138b59f02a0d4d1a4a89dd59f125154eac3692 /src/ctrl/control_if.c | |
parent | 5e21131c8dd37a536ec7df968d602c2c85580c39 (diff) |
libctrl: Add support for 'deferred control commands'
Sometimes a control interface command cannot be processed
and responded immediately, but we need to process it asynchronously.
In order to support this, we introduce the 'ctrl_cmd_def', which
represents such a deferred command. It is created by the service
implementing the command using ctrl_cmd_def_make(), and a response is
later sent using ctrl_cmd_def_send().
ctrl_cmd_def_is_zombie() must be called to handle the case where
the control connection has disconnected/died between receiving the
command and sending the response.
Diffstat (limited to 'src/ctrl/control_if.c')
-rw-r--r-- | src/ctrl/control_if.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c index 59cf2552..c20c1e0f 100644 --- a/src/ctrl/control_if.c +++ b/src/ctrl/control_if.c @@ -128,6 +128,8 @@ struct ctrl_cmd *ctrl_cmd_trap(struct ctrl_cmd *cmd) static void control_close_conn(struct ctrl_connection *ccon) { + struct ctrl_cmd_def *cd, *cd2; + osmo_wqueue_clear(&ccon->write_queue); close(ccon->write_queue.bfd.fd); osmo_fd_unregister(&ccon->write_queue.bfd); @@ -135,6 +137,19 @@ static void control_close_conn(struct ctrl_connection *ccon) if (ccon->closed_cb) ccon->closed_cb(ccon); msgb_free(ccon->pending_msg); + + /* clean up deferred commands */ + llist_for_each_entry_safe(cd, cd2, &ccon->def_cmds, list) { + /* delete from list of def_cmds for this ccon */ + llist_del(&cd->list); + /* not strictly needed as this is a slave to the ccon which we + * are about to free anyway */ + talloc_free(cd->cmd); + /* set the CMD to null, this is the indication to the user that + * the connection for this command has gone */ + cd->cmd = NULL; + } + talloc_free(ccon); } @@ -338,6 +353,8 @@ static struct ctrl_connection *ctrl_connection_alloc(void *ctx) /* Error handling here? */ INIT_LLIST_HEAD(&ccon->cmds); + INIT_LLIST_HEAD(&ccon->def_cmds); + return ccon; } |