diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /bittorrent/epoll_server/epoll_server.h | |
Diffstat (limited to 'bittorrent/epoll_server/epoll_server.h')
| -rw-r--r-- | bittorrent/epoll_server/epoll_server.h | 58 |
1 files changed, 58 insertions, 0 deletions
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 <netdb.h> +#include <sys/socket.h> +#include <sys/types.h> + +#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 */ |
