From 7edaa14c2c822e5b776edaa6534753b258d29488 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Tue, 9 Aug 2022 17:15:45 -0700 Subject: fix(libacron): infinite loop when wic_parse returns 0 This is a rather complicated way to fix backlogging issues. It asks the client to pass partial buffer, and the client also must retry with NULL buffer if ac_receive returns AC_E_AGAIN. --- client/libacron/include/net.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'client/libacron/include/net.h') diff --git a/client/libacron/include/net.h b/client/libacron/include/net.h index 6f5619a..7b28df2 100644 --- a/client/libacron/include/net.h +++ b/client/libacron/include/net.h @@ -76,15 +76,22 @@ LIBAC_EXPORT int ac_disconnect(void *connection, bool force); * Blocks the current thread until a new response or event arrives. * @param connection A non-NULL and connected connection passed as-is from ac_connect. * @param buffer Buffer of data read from the socket. + * @param pos Read the buffer starting at pos. * @param len Length to buffer. * @param response Output response of either an event or a response. May be NULL even if it succeeds. + * @param len_read Output the bytes read. Must be <= len. The caller must call it again with pos = *len_read until + * the sum of *len_read == len or when return value == AC_E_AGAIN, except when return value != AC_E_OK. + * Note: if return value == AC_E_AGAIN, call ac_receive with buffer = pos = len = 0 once, regardless of *len_read. + * In this case, len_read is ignored. * @return AC_E_OK or an error code. When failed, *response is NULL. * Notes: if the state is changed to CLOSED after receiving, this function will return AC_E_NET. */ LIBAC_EXPORT int ac_receive(void *connection, const void *buffer, + size_t pos, size_t len, - ac_obj_t **response); + ac_obj_t **response, + size_t *len_read); /** * Get the current state of the connection. -- cgit v1.2.3