trafilo 0.1.0
Streaming event-handler framework in C
Loading...
Searching...
No Matches
socket.h File Reference
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include "bounded_queue.h"

Go to the source code of this file.

Data Structures

struct  listener_t
 UDP listener handle. More...

Functions

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_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.