summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wa-inc/connection.h
blob: 823eaec74beaca3f836e6b370bfcb26207892ab6 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2019 Intel Corporation.  All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

#ifndef _CONNECTION_H_
#define _CONNECTION_H_

#include "bi-inc/attr_container.h"

#ifdef __cplusplus
extern "C" {
#endif

struct _connection;
typedef struct _connection connection_t;

/* Connection event type */
typedef enum {
    /* Data is received */
    CONN_EVENT_TYPE_DATA = 1,
    /* Connection is disconnected */
    CONN_EVENT_TYPE_DISCONNECT
} conn_event_type_t;

/*
 * @typedef on_connection_event_f
 *
 * @param conn the connection that the event belongs to
 * @param type event type
 * @param data the data received for CONN_EVENT_TYPE_DATA event
 * @param len length of the data in byte
 * @param user_data user data
 */
typedef void (*on_connection_event_f)(connection_t *conn,
                                      conn_event_type_t type, const char *data,
                                      uint32 len, void *user_data);

/*
 *****************
 * Connection API's
 *****************
 */

/*
 * @brief Open a connection.
 *
 * @param name name of the connection, "TCP", "UDP" or "UART"
 * @param args connection arguments, such as: ip:127.0.0.1, port:8888
 * @param on_event callback function called when event occurs
 * @param user_data user data
 *
 * @return the connection or NULL means fail
 */
connection_t *
api_open_connection(const char *name, attr_container_t *args,
                    on_connection_event_f on_event, void *user_data);

/*
 * @brief Close a connection.
 *
 * @param conn connection
 */
void
api_close_connection(connection_t *conn);

/*
 * Send data to the connection in non-blocking manner which returns immediately
 *
 * @param conn the connection
 * @param data data buffer to be sent
 * @param len length of the data in byte
 *
 * @return actual length sent, or -1 if fail(maybe underlying buffer is full)
 */
int
api_send_on_connection(connection_t *conn, const char *data, uint32 len);

/*
 * @brief Configure connection.
 *
 * @param conn the connection
 * @param cfg configurations
 *
 * @return true if success, false otherwise
 */
bool
api_config_connection(connection_t *conn, attr_container_t *cfg);

#ifdef __cplusplus
}
#endif

#endif