summaryrefslogtreecommitdiff
path: root/bittorrent/epoll_server/connection.h
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /bittorrent/epoll_server/connection.h
add: added projectsHEADmain
Diffstat (limited to 'bittorrent/epoll_server/connection.h')
-rw-r--r--bittorrent/epoll_server/connection.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/bittorrent/epoll_server/connection.h b/bittorrent/epoll_server/connection.h
new file mode 100644
index 0000000..40e2370
--- /dev/null
+++ b/bittorrent/epoll_server/connection.h
@@ -0,0 +1,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 */