/* * Created by yuuta on 7/13/22. */ #ifndef LIBAC_NET_H #define LIBAC_NET_H #include "incl.h" #include "common.h" #include "events.h" #include "requests.h" /* Connection */ typedef struct ac_connection_parameters { char *host; uint16_t port; unsigned int version; char *id; char *token; } ac_connection_parameters_t; /** * Connect to the server. * @param parameters Connection parameters. Untouched. * @param out Output connection reference if succeeds. Not-NULL. * @return AC_E_OK or an error code. When failed, *out will be untouched. * MT-Safe */ LIBAC_EXPORT int ac_connect(ac_connection_parameters_t parameters, void **out); /** * Disconnect the connection. * @param connection A non-NULL and connected connection passed as-is from ac_connect. * @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); /** * 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 response Output response of either an event or a response. May be NULL even if it succeeds. * @param timeout Read timeout in seconds. Set to 0 to wait infinitely. * @return AC_E_OK or an error code. When failed, *response is NULL. */ LIBAC_EXPORT int ac_receive(void *connection, ac_obj_t **response, long timeout); #endif /* LIBAC_NET_H */