If the client is gone, no need to return. The async handler can use this information to avoid unnecessary work and exit earlier.
Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> --- qapi/qmp-dispatch.c | 10 ++++++++++ include/qapi/qmp/dispatch.h | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index c8821b7..0c4022f 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -155,6 +155,16 @@ void qmp_return_error(QmpReturn *qret, Error *err) do_qmp_return(qret); } +bool qmp_return_is_cancelled(QmpReturn *qret) +{ + if (!qret->client) { + qmp_return_free(qret); + return true; + } + + return false; +} + void qmp_client_init(QmpClient *client, QmpDispatchReturn *return_cb) { client->return_cb = return_cb; diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 3287676..bc64d4e 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -78,4 +78,12 @@ void qmp_for_each_command(qmp_cmd_callback_fn fn, void *opaque); void qmp_return(QmpReturn *qret, QObject *cmd_rsp); void qmp_return_error(QmpReturn *qret, Error *err); +/* + * qmp_return_is_cancelled: + * + * Return true if the QmpReturn is cancelled, and free the QmpReturn + * in this case. + */ +bool qmp_return_is_cancelled(QmpReturn *qret); + #endif -- 2.10.0