trafilo 0.1.0
Streaming event-handler framework in C
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1#ifndef SOCKET_H
2#define SOCKET_H
3
4#include <errno.h>
5#include <stddef.h>
6#include <stdint.h>
7#include <string.h>
8#include <unistd.h>
9#include <sys/socket.h>
10#include <netinet/in.h>
11#include <arpa/inet.h>
12#include <sys/time.h>
13
14#include "bounded_queue.h"
15
19typedef struct listener_t {
20 int sockfd; /* UDP Port */
21 bounded_queue_t *bounded_q; /* Work queue associated with queue */
22 size_t max_line; /* The max lines work queue can handel*/
23 pthread_t thread; /* Listening and populating thread */
24 int started; /* Operation flag */
25 volatile int done; /* Atomic flag, for listener's thread, avoid compiler reordering for read/write on thread operations.*/
27
35listener_t *listener_create(int port, bounded_queue_t *bounded_q, size_t max_line);
36
42int listener_start(listener_t *listener);
43
49void listener_stop(listener_t *listener);
50
55void listener_destroy(listener_t *listener);
56#endif
listener_t * listener_create(int port, bounded_queue_t *bounded_q, size_t max_line)
Allocate a listener bound to the given UDP port.
Definition socket.c:50
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 ...
Definition socket.c:107
void listener_destroy(listener_t *listener)
Free the listener and close its socket.
Definition socket.c:115
int listener_start(listener_t *listener)
Spawn the receive thread.
Definition socket.c:93
A Circular ring queue, fixed size, to create a pool of events to be parsed.
Definition bounded_queue.h:12
UDP listener handle.
Definition socket.h:19
bounded_queue_t * bounded_q
Definition socket.h:21
pthread_t thread
Definition socket.h:23
volatile int done
Definition socket.h:25
size_t max_line
Definition socket.h:22
int started
Definition socket.h:24
int sockfd
Definition socket.h:20