summaryrefslogtreecommitdiff
path: root/bittorrent/epoll_server/connection.h
blob: 40e2370aed3ecb5334603a8e12250ac55e6f0faa (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
#ifndef CONNECTION_H
#define CONNECTION_H

#include <sys/types.h>

/**
 * \brief Contains the information about the clients (linked list)
 */
struct connection_t
{
    int client_socket; /**< socket fd of the client */

    char *buffer; /**< buffer containing the data received by this client */

    ssize_t nb_read; /**< number of bytes read (also size of the buffer) */

    struct connection_t *next; /**< the next client */
};

/**
 * \brief Adds a new client connection_t to the linked list
 *
 * \param connection: the connection_t linked list with all the clients
 *
 * \param client_socket: the client socket fd to add
 *
 * \return The connection_t linked list with the element added
 */
struct connection_t *add_client(struct connection_t *head, int client_socket);

/**
 * \brief Removes the client connection_t from the linked list connection
 *
 * \param connection: the connection_t linked list with all the clients
 *
 * \param client_socket: the client socket fd to remove
 *
 * \return The connection_t linked list with element removed
 */
struct connection_t *remove_client(struct connection_t *head,
                                   int client_socket);

/**
 * \brief Find the connection_t element where the socket is equal to client sock
 *
 * \param connection: the connection_t linked list with all the clients
 *
 * \param client_socket: the client socket to find
 *
 * \return The connection_t element of the specific client
 */
struct connection_t *find_client(struct connection_t *head, int client_socket);

#endif /* !CONNECTION_H */