From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- bittorrent/epoll_server/epoll_server.h | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 bittorrent/epoll_server/epoll_server.h (limited to 'bittorrent/epoll_server/epoll_server.h') diff --git a/bittorrent/epoll_server/epoll_server.h b/bittorrent/epoll_server/epoll_server.h new file mode 100644 index 0000000..ba5de4f --- /dev/null +++ b/bittorrent/epoll_server/epoll_server.h @@ -0,0 +1,58 @@ +#ifndef EPOLL_SERVER_H +#define EPOLL_SERVER_H + +#include +#include +#include + +#include "connection.h" + +/** + * \brief The length of the event array, must be greater than zero + */ +#define MAX_EVENTS 64 + +#define DEFAULT_BUFFER_SIZE 2048 + +/** + * \brief Iterate over the struct addrinfo elements to create and bind a socket + * + * \param addrinfo: struct addrinfo elements + * + * \return The created socket or exit with 1 if there is an error + * + * Try to create and connect a socket with every addrinfo element until it + * succeeds + * + */ +int create_and_bind(struct addrinfo *addrinfo); + +/** + * \brief Initialize the Addrinfo struct and call create_and bind() and + * listen(2) + * + * \param ip: IP address of the server + * \param port: Port of the server + * + * \return The created socket + * + * Initialize the struct addrinfo needed by create_and_bind() before calling + * it. When create_and_bind() returns a valid socket, set the socket to + * listening and return it. + */ +int prepare_socket(const char *ip, const char *port); + +/** + * \brief Accept a new client and add it to the connection_t struct + * + * \param epoll_instance: the epoll instance + * \param server_socket: listening socket + * \param connection: the connection linked list with all the current + * connections + * + * \return The connection struct with the new client added + */ +struct connection_t *accept_client(int epoll_instance, int server_socket, + struct connection_t *connection); + +#endif /* !EPOLL_SERVER_H */ -- cgit v1.2.3