aboutsummaryrefslogtreecommitdiff
path: root/client/libacron/include/net.h
blob: 8fb33f878d9c53e2d49fe7418df18c5c755335dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Created by yuuta on 7/13/22.
 */

#ifndef LIBAC_NET_H
#define LIBAC_NET_H

#include "common.h"
#include "events.h"
#include "requests.h"

/* Connection */

typedef struct ac_connection_parameters {
    /**
     * ws://host:port/ws?id=id&token=token
     * Currently wss is not supported.
     * Port must be supplied, or libac will connect to port zero.
     */
    char *url;
} 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
 */
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
 */
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.
 * @return AC_E_OK or an error code. When failed, *response is NULL.
 */
int ac_receive(void *connection, ac_obj_t **response);

#endif /* LIBAC_NET_H */