Forráskód Böngészése

:sparkles: Gestion message deconnexion client

Arthur Brandao 6 éve
szülő
commit
7e1f2401cd
6 módosított fájl, 65 hozzáadás és 3 törlés
  1. 5 1
      Serveur/bomberstudent_server.c
  2. 4 0
      Serveur/constante.h
  3. 21 0
      Serveur/handler.c
  4. 30 0
      Serveur/handler.h
  5. 2 1
      Serveur/main.c
  6. 3 1
      Serveur/makefile

+ 5 - 1
Serveur/bomberstudent_server.c

@@ -71,6 +71,10 @@ void* client_thread(void* data) {
             remove_client(cliId);
             break;
         }
+        //Regarde si le client existe toujours
+        if(get_client(cliId) == NULL){
+            break;
+        }
     }
     return NULL;
 }
@@ -149,7 +153,7 @@ void ini_server() {
 void add_handler(char* method, char* ressource, int(*handler)(int, JsonParser*)) {
     if (strncmp(method, "POST", 5) == 0) {
         arraylist_add(&post, ressource, handler);
-    } else if (strncmp(method, "POST", 5) == 0) {
+    } else if (strncmp(method, "GET", 4) == 0) {
         arraylist_add(&get, ressource, handler);
     }
 }

+ 4 - 0
Serveur/constante.h

@@ -24,6 +24,10 @@
 /* --- Null --- */
 #define null NULL
 
+/* --- Reussite --- */
+#define FAIL 0
+#define SUCCESS 1
+
 /* --- Application --- */
 #define GET 1
 #define POST 2

+ 21 - 0
Serveur/handler.c

@@ -0,0 +1,21 @@
+/* 
+ * File:   handler.c
+ * Author: Arthur Brandao
+ *
+ * Created on 23 novembre 2018
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "bomberstudent_server.h"
+#include "client.h"
+#include "handler.h"
+
+void ini_handler(){
+    add_handler("GET", "client/end", handler_client_end);
+}
+
+int handler_client_end(int cliId, JsonParser* json){
+    remove_client(cliId);
+    return SUCCESS;
+}

+ 30 - 0
Serveur/handler.h

@@ -0,0 +1,30 @@
+/* 
+ * File:   handler.h
+ * Author: Arthur Brandao
+ *
+ * Created on 23 novembre 2018
+ */
+
+#ifndef HANDLER_H
+#define HANDLER_H
+
+/* --- Include --- */
+#include "constante.h"
+#include "json.h"
+
+/* --- Fonctions --- */
+/**
+ * Initialise les handlers
+ */
+void ini_handler();
+
+/**
+ * Handler de gestion des deconnxion des clients
+ * @param int L'id du client
+ * @param JsonParser* Le json envoyer par le client
+ * @return int Etat
+ */
+int handler_client_end(int, JsonParser*);
+
+#endif /* HANDLER_H */
+

+ 2 - 1
Serveur/main.c

@@ -12,6 +12,7 @@
 #include "error.h"
 #include "bomberstudent_server.h"
 #include "main.h"
+#include "handler.h"
 
 /* --- Extern --- */
 extern Error error;
@@ -54,7 +55,7 @@ int main(){
     signal(SIGINT, handler);
     signal(SIGPIPE, SIG_IGN); //Ignore les signaux SIGPIPE (on est pas sur d'en recevoir à chaque coupure socket + Impossible de determnier quelle socket est fermé (on laisse la méthode du timeout pour la trouver)
     //Ajout des handlers
-    /*add_handler("POST", "aze/rty", handler);*/
+    ini_handler();
     //Lance le serveur UDP
     if(!launch_udp_server(PORT_UDP)){
         error.print("Impossible de démarrer le serveur");

+ 3 - 1
Serveur/makefile

@@ -3,7 +3,7 @@
 #
 
 EXEC = main test
-OBJETS = str.o json_parser.o json_encoder.o error.o arraylist.o server_tcp.o server_udp.o bomberstudent_server.o client.o file.o
+OBJETS = str.o json_parser.o json_encoder.o error.o arraylist.o server_tcp.o server_udp.o bomberstudent_server.o client.o file.o handler.o
 NOM_PROJET = Projet Reseau
 
 #
@@ -105,6 +105,8 @@ bomberstudent_server.o: bomberstudent_server.c arraylist.h constante.h \
  server.h json.h str.h bomberstudent_server.h client.h error.h
 client.o: client.c client.h constante.h server.h
 file.o: file.c error.h str.h file.h constante.h
+handler.o: handler.c bomberstudent_server.h constante.h server.h json.h \
+ str.h client.h handler.h
 main.o: main.c error.h bomberstudent_server.h constante.h server.h json.h \
  str.h client.h main.h
 test.o: test.c json.h str.h constante.h arraylist.h server.h error.h \