Skip to content

Commit cf525e1

Browse files
committed
doc: developer guide: adjust code
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 26a0286 commit cf525e1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

DEVELOPER_GUIDE.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ For crypto, Fluent Bit uses [mbedtls](https://github.com/ARMmbed/mbedtls).
2828
#### Memory Management
2929

3030
When you write Fluent Bit code, you will use Fluent Bit's versions of the standard C functions for working with memory:
31-
- [`flb_alloc()`](include/fluent-bit/flb_mem.h) - equivalent to `malloc`, allocates memory.
31+
- [`flb_malloc()`](include/fluent-bit/flb_mem.h) - equivalent to `malloc`, allocates memory.
3232
- [`flb_calloc()`](include/fluent-bit/flb_mem.h) - equivalent to `calloc`, allocates memory and initializes it to zero.
3333
- [`flb_realloc()`](include/fluent-bit/flb_mem.h) - equivalent to `realloc`.
3434
- [`flb_free()`](include/fluent-bit/flb_mem.h) - equivalent to `free`, releases allocated memory.
3535

3636
Note that many types have a specialized create and destroy function. For example,
37-
[`flb_sds_create()` and `flb_sds_destroy()`](include/fluent-bit/flb_sds.h).
37+
[`flb_sds_create()` and `flb_sds_destroy()`](include/fluent-bit/flb_sds.h) (more about this in the next section).
3838

3939
#### Strings
4040

@@ -70,20 +70,22 @@ static flb_sds_t make_request(struct flb_config *config)
7070
struct flb_upstream_conn *u_conn;
7171
flb_sds_t resp;
7272

73+
/* Create an 'upstream' context */
7374
upstream = flb_upstream_create(config, HOST, PORT, FLB_IO_TCP, NULL);
7475
if (!upstream) {
7576
flb_error("[example] connection initialization error");
7677
return -1;
7778
}
7879

80+
/* Retrieve a TCP connection from the 'upstream' context */
7981
u_conn = flb_upstream_conn_get(upstream);
8082
if (!u_conn) {
8183
flb_error("[example] connection initialization error");
8284
flb_upstream_destroy(upstream);
8385
return -1;
8486
}
8587

86-
/* Compose HTTP Client request */
88+
/* Create HTTP Client request/context */
8789
client = flb_http_client(u_conn,
8890
FLB_HTTP_GET, metadata_path,
8991
NULL, 0,
@@ -97,6 +99,10 @@ static flb_sds_t make_request(struct flb_config *config)
9799
return -1;
98100
}
99101

102+
/* Perform the HTTP request */
103+
ret = flb_http_do(client, &b_sent)
104+
105+
/* Validate return status and HTTP status if set */
100106
if (ret != 0 || client->resp.status != 200) {
101107
if (client->resp.payload_size > 0) {
102108
flb_debug("[example] Request failed and returned: \n%s",
@@ -108,8 +114,9 @@ static flb_sds_t make_request(struct flb_config *config)
108114
return -1;
109115
}
110116

117+
/* Copy payload response to an output SDS buffer */
111118
data = flb_sds_create_len(client->resp.payload,
112-
client->resp.payload_size);
119+
client->resp.payload_size);
113120

114121
flb_http_client_destroy(client);
115122
flb_upstream_conn_release(u_conn);
@@ -143,20 +150,22 @@ static int example()
143150
struct mk_list *head;
144151
struct mk_list items;
145152
int i;
153+
int len;
146154
char characters[] = "abcdefghijk";
147155
struct item *an_item;
148156
157+
len = strlen(characters);
158+
149159
/* construct a list */
150160
mk_list_init(&items);
151161
152-
for (i = 0; i < strlen(characters); i++) {
162+
for (i = 0; i < len; i++) {
153163
an_item = flb_malloc(sizeof(struct item));
154164
if (!an_item) {
155165
flb_errno();
156166
return -1;
157167
}
158168
an_item->some_data = characters[i];
159-
160169
mk_list_add(&an_item->_head, &items);
161170
}
162171
@@ -184,7 +193,7 @@ Fluent Bit uses [msgpack](https://msgpack.org/index.html) to internally store da
184193

185194
Fluent Bit embeds the [msgpack-c](https://github.com/msgpack/msgpack-c) library. The example below shows manipulating message pack to add a new key-value pair to a record. In Fluent Bit, the [filter_record_modifier](plugins/filter_record_modifier) plugin adds or deletes keys from records. See its code for more.
186195

187-
```
196+
```c
188197
#define A_NEW_KEY "key"
189198
#define A_NEW_KEY_LEN 3
190199
#define A_NEW_VALUE "value"

0 commit comments

Comments
 (0)