Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions include/fluent-bit/flb_downstream_worker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2026 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_DOWNSTREAM_WORKER_H
#define FLB_DOWNSTREAM_WORKER_H

#include <cfl/cfl_atomic.h>

#include <fluent-bit/flb_config.h>
#include <fluent-bit/flb_pipe.h>
#include <fluent-bit/flb_pthread.h>

#include <monkey/mk_core.h>

struct flb_downstream_worker;
struct flb_downstream_worker_runtime;

typedef int (*flb_downstream_worker_init_cb)(struct flb_downstream_worker *worker,
void *parent,
void **worker_context);

typedef void (*flb_downstream_worker_exit_cb)(struct flb_downstream_worker *worker,
void *worker_context);

typedef void (*flb_downstream_worker_maintenance_cb)(
struct flb_downstream_worker *worker,
void *worker_context);

typedef void (*flb_downstream_worker_foreach_cb)(struct flb_downstream_worker *worker,
void *worker_context,
void *data);

struct flb_downstream_worker {
struct flb_downstream_worker_runtime *runtime;
struct mk_event_loop *event_loop;
struct mk_event control_event;
flb_pipefd_t control_channel[2];
void *context;
void *parent;
int worker_id;
int worker_count;

pthread_t thread;
pthread_mutex_t mutex;
pthread_cond_t condition;
uint64_t should_exit;
flb_downstream_worker_foreach_cb control_callback;
void *control_data;
int initialized;
int thread_created;
int control_channel_created;
int control_done;
int startup_result;
};

struct flb_downstream_worker_options {
int workers;
struct flb_config *config;
void *parent;
flb_downstream_worker_init_cb cb_init;
flb_downstream_worker_exit_cb cb_exit;
flb_downstream_worker_maintenance_cb cb_maintenance;
};

int flb_downstream_worker_runtime_start(struct flb_downstream_worker_runtime **out_runtime,
struct flb_downstream_worker_options *options);

void flb_downstream_worker_runtime_stop(struct flb_downstream_worker_runtime *runtime);

void flb_downstream_worker_runtime_foreach(struct flb_downstream_worker_runtime *runtime,
flb_downstream_worker_foreach_cb callback,
void *data);

#endif
4 changes: 2 additions & 2 deletions include/fluent-bit/http_server/flb_http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef int (*flb_http_server_request_processor_callback)(
struct flb_http_response *response);

struct flb_http_server;
struct flb_http_server_runtime;
struct flb_downstream_worker_runtime;

typedef int (*flb_http_server_worker_callback)(struct flb_http_server *server,
void *data);
Expand Down Expand Up @@ -145,7 +145,7 @@ struct flb_http_server {
int tls_alpn_configured;
flb_http_server_worker_callback cb_worker_init;
flb_http_server_worker_callback cb_worker_exit;
struct flb_http_server_runtime *runtime;
struct flb_downstream_worker_runtime *runtime;
};

struct flb_http_server_session {
Expand Down
55 changes: 22 additions & 33 deletions lib/cfl/.github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-latest, windows-2019]
os: [windows-latest, windows-2022]
steps:
- uses: actions/checkout@v4
- name: Build on ${{ matrix.os }} with vs-2019
- uses: actions/checkout@v6
- name: Build on ${{ matrix.os }} with MSVC
run: |
.\scripts\win_build.bat
- name: Run unit tests.
Expand All @@ -31,9 +31,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-latest, windows-2019]
os: [windows-latest, windows-2022]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Get dependencies w/ chocolatey
uses: crazy-max/ghaction-chocolatey@v3
with:
Expand Down Expand Up @@ -106,7 +106,11 @@ jobs:
steps:
- name: Set up base image dependencies
run: |
apt-get update
printf '%s\n' \
'deb http://archive.debian.org/debian buster main' \
'deb http://archive.debian.org/debian-security buster/updates main' \
> /etc/apt/sources.list
apt-get -o Acquire::Check-Valid-Until=false update
apt-get install -y build-essential wget make gcc g++

- name: Install CMake 3.20.0
Expand All @@ -122,7 +126,7 @@ jobs:
# Confirm CMake installation
/usr/local/bin/cmake --version

- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Run compilation
run: |
Expand All @@ -138,7 +142,7 @@ jobs:
os: [ubuntu-latest]
compiler: [ gcc, clang ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Build on ${{ matrix.os }} with ${{ matrix.compiler }}
uses: uraimo/run-on-arch-action@v3.0.1
with:
Expand Down Expand Up @@ -167,7 +171,7 @@ jobs:
os: [ubuntu-latest, macos-latest]
compiler: [ gcc, clang ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Build on ${{ matrix.os }} with ${{ matrix.compiler }}
run: |
echo "CC = $CC, CXX = $CXX"
Expand All @@ -193,36 +197,21 @@ jobs:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
with:
submodules: true
dependencies_debian: 'wget'

- name: Install CMake 3.20.0
run: |
CMAKE_VERSION=3.20.0
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh
chmod +x cmake-${CMAKE_VERSION}-linux-x86_64.sh

# Create a writable temporary directory
mkdir -p /tmp/cmake

# Install CMake to /tmp/cmake
./cmake-${CMAKE_VERSION}-linux-x86_64.sh --skip-license --prefix=/tmp/cmake

# Add CMake to the PATH
echo 'export PATH=/tmp/cmake/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

# Verify installation
/tmp/cmake/bin/cmake --version

- uses: actions/checkout@v4
- uses: docker://lpenz/ghaction-cmake:0.19
with:
pre_command: |
CMAKE_VERSION=3.20.0
curl -fsSLO https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh
chmod +x cmake-${CMAKE_VERSION}-linux-x86_64.sh
./cmake-${CMAKE_VERSION}-linux-x86_64.sh --skip-license --prefix=/usr/local
cmake --version
preset: ${{ matrix.preset }}

cmakeflags: '-DCFL_TESTS=On -DCFL_DEV=on .'
build_command: /tmp/cmake/bin/cmake && make all
build_command: make all

# this job provides the single required status for PRs to be merged into main.
# instead of updating the protected branch status in github, developers can update the needs section below
Expand Down
4 changes: 2 additions & 2 deletions lib/cfl/.github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: ludeeus/action-shellcheck@master
with:
ignore_paths: lib
Expand All @@ -21,7 +21,7 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- run: |
echo "::add-matcher::.github/actionlint-matcher.json"
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
Expand Down
10 changes: 5 additions & 5 deletions lib/cfl/.github/workflows/packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
format: [ rpm, deb ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: uraimo/run-on-arch-action@v3.0.1
name: Build the ${{matrix.format}} packages
with:
Expand All @@ -36,7 +36,7 @@ jobs:
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}

- name: Store the master package artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: ${{ matrix.format }}-arm64
path: |
Expand All @@ -51,14 +51,14 @@ jobs:

runs-on: [ ubuntu-latest ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Build the ${{matrix.format}} packages
run: |
cmake .
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}

- name: Store the master package artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: ${{ matrix.format }}-amd64
path: |
Expand All @@ -74,7 +74,7 @@ jobs:
contents: write
steps:
- name: Download all artefacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v7
with:
path: artifacts/

Expand Down
76 changes: 76 additions & 0 deletions lib/cfl/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Repository Guidelines

## Preferred Commands
- Configure with tests: `cmake -S . -B build -DCFL_TESTS=On`
- Build: `cmake --build build -j8`
- Run all tests: `ctest --test-dir build --output-on-failure`
- Run a focused test: `ctest --test-dir build -R <name> --output-on-failure`
- Check staged or local patches for whitespace before closing a change:
`git diff --check`

## Project Structure & Module Organization
CFL is a small C library built with CMake.

- `include/cfl/`: public CFL headers.
- `src/`: library implementation files.
- `tests/`: acutest-based unit tests.
- `lib/xxhash/`: bundled xxHash dependency.
- `cmake/`: project CMake helpers.

Keep changes scoped to the affected module. Put public declarations in
`include/cfl/`, implementation in `src/`, and matching unit coverage in
`tests/` when behavior changes.

## Build, Test, and Development Commands
- `cmake -S . -B build -DCFL_TESTS=On`: configure the project with tests.
- `cmake --build build -j8`: compile the static library and tests.
- `ctest --test-dir build --output-on-failure`: run the enabled test suite.
- `ctest --test-dir build -R cfl-test-<name> --output-on-failure`: run a
focused unit test.

Prefer targeted test runs while iterating, then run the full enabled suite
before closing changes that touch shared code or public APIs.

## Coding Style & Naming Conventions
- Follow the existing Apache-style C conventions used in this repository.
- Use 4-space indentation and keep lines readable; avoid unnecessary wrapping.
- Always use braces for `if/else/while/do` blocks.
- Put function opening braces on the next line:
`int fn(void)\n{ ... }`
- Declare variables at the start of functions, not mid-block.
- Prefer descriptive `snake_case` names with the `cfl_` prefix for public APIs.
- Use `CFL_TRUE` and `CFL_FALSE` for CFL boolean-style return values.
- Use `/* ... */` comments, and add comments only where they clarify non-obvious
behavior.
- Keep public headers self-contained by including the standard headers they need.

## Testing Guidelines
- Add or update acutest unit coverage for behavior changes.
- Keep tests close to the affected module and name test binaries through
`tests/CMakeLists.txt`.
- Validate both success and failure paths for parsers, containers, allocation
handling, and boundary conditions.
- Run broader coverage when changing shared headers, CMake wiring, memory
ownership, or common data structures.
- If a relevant test cannot be run, report the exact blocker in the final
response.

## Commit & Pull Request Guidelines
- Follow observed local history style:
`component: short imperative description`
Examples: `sds: do not export internal sds_alloc function`,
`build: bump to v0.6.2`, `atomic: add atomic operations API`.
- Keep each commit scoped to one component or interface.
- Keep subject/body lines concise; use a body when the reason or scope is not
obvious from the subject.
- Do not mix unrelated code and documentation updates in one commit unless the
user explicitly asks for a combined commit.
- Do not rewrite history, amend commits, create remote branches, or open pull
requests unless explicitly requested.

## Agent Action Limits
- Do not modify repositories or files outside this project unless the user
explicitly asks.
- Do not revert user changes outside the requested scope.
- Preserve unrelated untracked or modified files in the worktree.
- Prefer minimal patches that avoid unrelated formatting or refactoring churn.
4 changes: 2 additions & 2 deletions lib/cfl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# C Floppy Version
set(CFL_VERSION_MAJOR 0)
set(CFL_VERSION_MINOR 6)
set(CFL_VERSION_PATCH 1)
set(CFL_VERSION_MINOR 7)
set(CFL_VERSION_PATCH 0)
set(CFL_VERSION_STR "${CFL_VERSION_MAJOR}.${CFL_VERSION_MINOR}.${CFL_VERSION_PATCH}")

# Configuration options
Expand Down
Loading
Loading