blob: ba5de4f7aa40aaaa67b6dda564383bea9513e6c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 */
|