From 219e4bb54375995fa377a1bcf9601a77cf6f1fee Mon Sep 17 00:00:00 2001 From: Trumeet Date: Mon, 25 Jul 2022 14:47:04 -0700 Subject: feat(libacron): support force disconnecting without writing anything API:CHANGE Signed-off-by: Trumeet --- client/libacron/apps/helloworld/main.c | 2 +- client/libacron/include/net.h | 4 +++- client/libacron/net.c | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/client/libacron/apps/helloworld/main.c b/client/libacron/apps/helloworld/main.c index 6201fac..c112fcb 100644 --- a/client/libacron/apps/helloworld/main.c +++ b/client/libacron/apps/helloworld/main.c @@ -356,7 +356,7 @@ int main(int argc, char **argv) { } } if ((r = lock())) { goto end; } - ac_disconnect(connection); + ac_disconnect(connection, false); if ((r = unlock())) { goto end; } net_close(&sock); ac_free(); diff --git a/client/libacron/include/net.h b/client/libacron/include/net.h index 03be12f..6f5619a 100644 --- a/client/libacron/include/net.h +++ b/client/libacron/include/net.h @@ -65,10 +65,12 @@ LIBAC_EXPORT int ac_connect(ac_connection_parameters_t parameters, void **out); * Disconnect the connection. * The user must manually disconnect the socket passed in during ac_connect. * @param connection A non-NULL and connected connection passed as-is from ac_connect. + * @param force By default (false), libac will gracefully close the socket by writing something to it. If force is true, + * libac will directly free any internal structures without writing anything. * @return AC_E_OK or an error code. When failed, connection is undefined. When succeeds, connection is freed and invalid. * MT-Unsafe */ -LIBAC_EXPORT int ac_disconnect(void *connection); +LIBAC_EXPORT int ac_disconnect(void *connection, bool force); /** * Blocks the current thread until a new response or event arrives. diff --git a/client/libacron/net.c b/client/libacron/net.c index 1af752c..b393475 100644 --- a/client/libacron/net.c +++ b/client/libacron/net.c @@ -175,11 +175,16 @@ int ac_connect(ac_connection_parameters_t parameters, void **out) { return AC_E_OK; } -int ac_disconnect(void *connection) { +int ac_disconnect(void *connection, + bool force) { AC_CHECK_INIT; struct ac_connection *conn = connection; LOGD("Disconnecting..."); - wic_close(&conn->inst); + if (force) { + wic_close_with_reason(&conn->inst, WIC_CLOSE_ABNORMAL_1, NULL, 0U); + } else { + wic_close_with_reason(&conn->inst, WIC_CLOSE_NORMAL, NULL, 0U); + } conn_free(conn); return AC_E_OK; } -- cgit v1.2.3