KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
connection.h File Reference
#include <keel/allocator.h>
#include <keel/chunked.h>
#include <keel/file_io.h>
#include <keel/request.h>
#include <keel/response.h>
#include <keel/parser.h>
#include <keel/router.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for connection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KlConn
 
struct  KlConnPool
 

Macros

#define KL_READ_BUF_SIZE   8192
 Default read buffer size (bytes).
 

Typedefs

typedef struct KlTls KlTls
 
typedef struct KlWsServerConn KlWsServerConn
 
typedef struct KlH2ServerConn KlH2ServerConn
 
typedef struct KlH2ServerConfig KlH2ServerConfig
 
typedef struct KlConn KlConn
 

Enumerations

enum  KlConnState {
  KL_CONN_TLS_HANDSHAKE , KL_CONN_READING , KL_CONN_READING_BODY , KL_CONN_PROCESSING ,
  KL_CONN_SENDING , KL_CONN_WEBSOCKET , KL_CONN_HTTP2 , KL_CONN_SUSPENDED ,
  KL_CONN_CLOSED
}
 

Functions

int kl_conn_pool_init (KlConnPool *pool, int capacity, KlAllocator *alloc)
 Initialize a pre-allocated connection pool.
 
KlConnkl_conn_acquire (KlConnPool *pool, int fd)
 Acquire a connection slot from the pool. Returns NULL if full.
 
void kl_conn_release (KlConnPool *pool, KlConn *c)
 Release a connection back to the pool (closes fd).
 
void kl_conn_pool_free (KlConnPool *pool)
 Free all pool resources.
 
KlConnState kl_conn_on_handshake (KlConn *c)
 Process TLS handshake on a connection.
 
KlConnState kl_conn_on_readable (KlConn *c, KlRouter *router)
 Process readable data on a connection (parse headers/body, invoke handler).
 
KlConnState kl_conn_on_writable (KlConn *c)
 Process writable event (send response data).
 
KlConnState kl_conn_on_file_complete (KlConn *c, ssize_t result, int zero_copy)
 Handle async file I/O completion (called from server tick loop).
 
uint64_t kl_monotonic_ms (void)
 Monotonic clock in milliseconds (for timeout tracking).
 

Macro Definition Documentation

◆ KL_READ_BUF_SIZE

#define KL_READ_BUF_SIZE   8192

Default read buffer size (bytes).

Typedef Documentation

◆ KlTls

typedef struct KlTls KlTls

◆ KlWsServerConn

◆ KlH2ServerConn

◆ KlH2ServerConfig

◆ KlConn

typedef struct KlConn KlConn

Enumeration Type Documentation

◆ KlConnState

Enumerator
KL_CONN_TLS_HANDSHAKE 

TLS handshake in progress

KL_CONN_READING 

Reading request headers

KL_CONN_READING_BODY 

Reading request body

KL_CONN_PROCESSING 

Processing request

KL_CONN_SENDING 

Sending response

KL_CONN_WEBSOCKET 

WebSocket connection (upgraded)

KL_CONN_HTTP2 

HTTP/2 connection (upgraded)

KL_CONN_SUSPENDED 

Suspended for async operation

KL_CONN_CLOSED 

Connection closed

Function Documentation

◆ kl_conn_pool_init()

int kl_conn_pool_init ( KlConnPool pool,
int  capacity,
KlAllocator alloc 
)

Initialize a pre-allocated connection pool.

Parameters
poolPool to initialize.
capacityMaximum concurrent connections.
allocAllocator for pool memory.
Returns
0 on success, -1 on failure.

◆ kl_conn_acquire()

KlConn * kl_conn_acquire ( KlConnPool pool,
int  fd 
)

Acquire a connection slot from the pool. Returns NULL if full.

◆ kl_conn_release()

void kl_conn_release ( KlConnPool pool,
KlConn c 
)

Release a connection back to the pool (closes fd).

◆ kl_conn_pool_free()

void kl_conn_pool_free ( KlConnPool pool)

Free all pool resources.

◆ kl_conn_on_handshake()

KlConnState kl_conn_on_handshake ( KlConn c)

Process TLS handshake on a connection.

Returns
New connection state.

◆ kl_conn_on_readable()

KlConnState kl_conn_on_readable ( KlConn c,
KlRouter router 
)

Process readable data on a connection (parse headers/body, invoke handler).

Returns
New connection state.

◆ kl_conn_on_writable()

KlConnState kl_conn_on_writable ( KlConn c)

Process writable event (send response data).

Returns
New connection state.

◆ kl_conn_on_file_complete()

KlConnState kl_conn_on_file_complete ( KlConn c,
ssize_t  result,
int  zero_copy 
)

Handle async file I/O completion (called from server tick loop).

Parameters
cConnection that submitted the read.
resultBytes read/transferred (positive) or error (negative/zero).
zero_copy1 if data was spliced directly to socket (no WRITING phase).
Returns
New connection state.

◆ kl_monotonic_ms()

uint64_t kl_monotonic_ms ( void  )

Monotonic clock in milliseconds (for timeout tracking).