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> --- include/qapi/qmp/dispatch.h | 8 ++++++++ qapi/qmp-dispatch.c | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 32876764f3..bc64d4ed15 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 diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 31227ce6e9..6ceece5ef0 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) { assert(!client->return_cb); -- 2.11.0.295.gd7dffce1c