Skip to content

Commit 8c44185

Browse files
edsipercosmo0920
authored andcommitted
downstream: add flb_downstream_pause and flb_downstream_resume api
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent 0f8ac25 commit 8c44185

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

include/fluent-bit/flb_downstream.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct flb_downstream {
4545

4646
/* this is a config map reference coming from the plugin net_setup field */
4747
struct flb_net_setup *net_setup;
48+
49+
/* pause state */
50+
int paused;
4851
};
4952

5053
static inline int flb_downstream_is_shutting_down(struct flb_downstream *downstream)
@@ -76,6 +79,9 @@ int flb_downstream_set_property(struct flb_config *config,
7679

7780
struct flb_connection *flb_downstream_conn_get(struct flb_downstream *stream);
7881

82+
void flb_downstream_pause(struct flb_downstream *stream);
83+
void flb_downstream_resume(struct flb_downstream *stream);
84+
7985
int flb_downstream_conn_release(struct flb_connection *connection);
8086

8187
int flb_downstream_conn_pending_destroy_list(struct mk_list *list);

src/flb_downstream.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ struct flb_connection *flb_downstream_conn_get(struct flb_downstream *stream)
283283

284284
transport = stream->base.transport;
285285

286+
if (stream->paused) {
287+
if (transport != FLB_TRANSPORT_UDP &&
288+
transport != FLB_TRANSPORT_UNIX_DGRAM) {
289+
connection_fd = flb_net_accept(stream->server_fd);
290+
if (connection_fd >= 0) {
291+
flb_socket_close(connection_fd);
292+
}
293+
}
294+
295+
return NULL;
296+
}
297+
286298
if (transport == FLB_TRANSPORT_UDP ||
287299
transport == FLB_TRANSPORT_UNIX_DGRAM ) {
288300
if (stream->dgram_connection != NULL) {
@@ -357,6 +369,20 @@ struct flb_connection *flb_downstream_conn_get(struct flb_downstream *stream)
357369
return connection;
358370
}
359371

372+
void flb_downstream_pause(struct flb_downstream *stream)
373+
{
374+
if (stream) {
375+
stream->paused = FLB_TRUE;
376+
}
377+
}
378+
379+
void flb_downstream_resume(struct flb_downstream *stream)
380+
{
381+
if (stream) {
382+
stream->paused = FLB_FALSE;
383+
}
384+
}
385+
360386
void flb_downstream_destroy(struct flb_downstream *stream)
361387
{
362388
struct flb_connection *connection;

0 commit comments

Comments
 (0)