Implement Server (#1)
All checks were successful
Test and Deploy / test (push) Successful in 15s
Test and Deploy / docs (push) Successful in 28s

- Generic Server struct
- TCP and UDP

Reviewed-on: #1
This commit is contained in:
2024-07-09 21:03:23 +00:00
parent 074798ed62
commit 48f773b3ab
16 changed files with 440 additions and 49 deletions

View File

@ -17,4 +17,8 @@ void del_split(char **);
void del_lines(char **);
#define DEFAULT_CAPTURE_SYSTEM_BUFSIZE 1024
const char *capture_system(const char *cmd, int buf_sz);
#endif // LIBFLINT_INPUT_H

28
include/lfnetwork.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef LIBFLINT_NET_H
#define LIBFLINT_NET_H
#include <netdb.h>
typedef enum ServerType {
SERVERTYPE_TCP,
SERVERTYPE_UDP
} ServerType;
typedef struct Server {
ServerType server_type;
int fd;
int port;
void (*handler)(struct Server *s);
} Server;
#define DEFAULT_BACKLOG 5
Server *new_server(ServerType type, const char *port, void(handler)(Server *s));
void delete_server(Server *s);
int serve(Server *s, int backlog_size);
void *get_in_addr(struct sockaddr *sa);
// Example handlers
void handler_tcp_echo(Server *s);
#endif //LIBFLINT_NET_H