trafilo 0.1.0
Streaming event-handler framework in C
Loading...
Searching...
No Matches
socket.c File Reference
#include "headers/socket.h"

Functions

static void * listener_loop (void *arg)
 Looping function for socket thread.
listener_tlistener_create (int port, bounded_queue_t *bounded_q, size_t max_line)
 Allocate a listener bound to the given UDP port.
int listener_start (listener_t *listener)
 Spawn the receive thread.
void listener_stop (listener_t *listener)
 Signal the receive thread to exit and join it. Does NOT shut down the queue — caller decides when to call bq_shutdown.
void listener_destroy (listener_t *listener)
 Free the listener and close its socket.

Function Documentation

◆ listener_create()

listener_t * listener_create ( int port,
bounded_queue_t * bounded_q,
size_t max_line )

Allocate a listener bound to the given UDP port.

Parameters
portUDP port to bind on.
bounded_qQueue raw lines are pushed onto. Listener does NOT take ownership — caller manages lifetime.
max_lineThe max buffer length per line.
Returns
Listener handle on success, NULL on socket/bind/alloc failure.

◆ listener_destroy()

void listener_destroy ( listener_t * listener)

Free the listener and close its socket.

Parameters
listenerListener to destroy.

◆ listener_loop()

void * listener_loop ( void * arg)
static

Looping function for socket thread.

Parameters
argThe listener_t of the connection

◆ listener_start()

int listener_start ( listener_t * listener)

Spawn the receive thread.

Parameters
listenerListener to start.
Returns
0 on success, -1 if pthread_create failed, -2 already started.

◆ listener_stop()

void listener_stop ( listener_t * listener)

Signal the receive thread to exit and join it. Does NOT shut down the queue — caller decides when to call bq_shutdown.

Parameters
listenerListener to stop.