summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_lib.h
blob: 3e182cbb81cb2eea7328283431fed0866da7255e (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
/*
 * Copyright (C) 2019 Intel Corporation.  All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

#ifndef CONNECTION_LIB_H_
#define CONNECTION_LIB_H_

#include "bi-inc/attr_container.h"
#include "wasm_export.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * This file defines connection library which should be implemented by
 * different platforms
 */

/*
 * @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
 *
 * @return 0~0xFFFFFFFE means id of the connection, otherwise(-1) means fail
 */
typedef uint32 (*connection_open_f)(wasm_module_inst_t module_inst,
                                    const char *name, attr_container_t *args);

/*
 * @brief Close a connection.
 *
 * @param handle of the connection
 */
typedef void (*connection_close_f)(uint32 handle);

/*
 * @brief Send data to the connection in non-blocking manner.
 *
 * @param handle of the connection
 * @param data data buffer to be sent
 * @param len length of the data in byte
 *
 * @return actual length sent, -1 if fail
 */
typedef int (*connection_send_f)(uint32 handle, const char *data, int len);

/*
 * @brief Configure connection.
 *
 * @param handle of the connection
 * @param cfg configurations
 *
 * @return true if success, false otherwise
 */
typedef bool (*connection_config_f)(uint32 handle, attr_container_t *cfg);

/* Raw connection interface for platform to implement */
typedef struct _connection_interface {
    connection_open_f _open;
    connection_close_f _close;
    connection_send_f _send;
    connection_config_f _config;
} connection_interface_t;

/* Platform must define this interface */
extern connection_interface_t connection_impl;

#ifdef __cplusplus
}
#endif

#endif /* CONNECTION_LIB_H_ */