#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 */