diff options
author | Trumeet <yuuta@yuuta.moe> | 2022-08-09 17:15:45 -0700 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2022-08-09 17:15:45 -0700 |
commit | 7edaa14c2c822e5b776edaa6534753b258d29488 (patch) | |
tree | 7c6dba03c89d3d9745a40d03e5b45c1f9cdf3938 /client/libacron/include | |
parent | 1d42944d172cbc725cd025aea1c364c3f13a38e5 (diff) | |
download | acron-7edaa14c2c822e5b776edaa6534753b258d29488.tar acron-7edaa14c2c822e5b776edaa6534753b258d29488.tar.gz acron-7edaa14c2c822e5b776edaa6534753b258d29488.tar.bz2 acron-7edaa14c2c822e5b776edaa6534753b258d29488.zip |
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.
Diffstat (limited to 'client/libacron/include')
-rw-r--r-- | client/libacron/include/common.h | 2 | ||||
-rw-r--r-- | client/libacron/include/net.h | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/client/libacron/include/common.h b/client/libacron/include/common.h index 79dd29b..a263f7e 100644 --- a/client/libacron/include/common.h +++ b/client/libacron/include/common.h @@ -22,6 +22,8 @@ #define AC_E_INVALID_REQUEST 6 /* Network error */ #define AC_E_NET 7 +/* Call ac_receive again */ +#define AC_E_AGAIN 8 /* Remote errors */ #define AC_ER_BAD_REQUEST 400 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. |