Commit fff6f0370e40689fd0720531d0e4dc2183891fd8
1 parent
32c9271a
modifs
Showing
5 changed files
with
39 additions
and
9 deletions
Show diff stats
Threads/threadSocket.c
... | ... | @@ -10,24 +10,27 @@ void* reponseConnexion(void* sock) |
10 | 10 | { |
11 | 11 | |
12 | 12 | printf("Connected\n"); |
13 | - char buffer[]= "HTTP/1.1 200 OK\nServer: Serveur fait maison\nContent-Type: text/html; charset=UTF-8\nConnection: Keep-alive\n\n<h1>Hey !</h1>"; | |
14 | - | |
13 | + char buff_rec[BUFF_SIZE]; | |
14 | + char buffer[]="HTTP/1.1 200 OK\r\nServer: Serveur fait maison\r\nContent-Type: text/html; charset=UTF-8\r\nConnection: Keep-alive\r\n\r\nPOST /Page.html HTTP/1.1\r\n\r\n"; | |
15 | + | |
16 | + | |
15 | 17 | FILE* sockdial_stream = fdopen(*((int*)(sock)), "a+"); |
16 | 18 | |
17 | 19 | printf("Sock : %d // Stream : %p \n", *((int*)(sock)), sockdial_stream); |
18 | 20 | |
21 | + fgets(buff_rec, BUFF_SIZE, sockdial_stream); | |
19 | 22 | fprintf(sockdial_stream, "%s", buffer); |
20 | 23 | |
21 | - while(strcmp(buffer, "EXIT\n")!=0) | |
22 | - { | |
24 | + //while(strcmp(buffer, "EXIT\n")!=0) | |
25 | + //{ | |
23 | 26 | printf("WAIT\n"); |
24 | - fgets(buffer, BUFF_SIZE, sockdial_stream); | |
27 | + // fgets(buff_rec, BUFF_SIZE, sockdial_stream); | |
25 | 28 | |
26 | - printf("Le message reçu : %s", buffer); | |
29 | + printf("Le message reçu : %s", buff_rec); | |
27 | 30 | |
28 | 31 | fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); |
29 | 32 | |
30 | - } | |
33 | + //} | |
31 | 34 | |
32 | 35 | strcpy(buffer, "START"); |
33 | 36 | printf("Fin de la connexion\n"); | ... | ... |
bin/test
No preview for this file type
bin/test.c
1 | 1 | #include <stdlib.h> |
2 | 2 | #include <stdio.h> |
3 | +#include <unistd.h> | |
3 | 4 | #include <getopt.h> |
4 | 5 | #include <string.h> |
6 | +#include <signal.h> | |
5 | 7 | #include "libnet.h" |
6 | 8 | |
7 | 9 | |
10 | +int sock_fd; | |
11 | + | |
12 | +struct sigaction action; | |
13 | + | |
14 | +void handler(int sig) | |
15 | +{ | |
16 | + if(sig==SIGINT) | |
17 | + { | |
18 | + printf("\nINTERRUPTION SOCKET : %d\n\n", sock_fd); | |
19 | + close(sock_fd); | |
20 | + exit(1); | |
21 | + } | |
22 | +} | |
23 | + | |
24 | + | |
8 | 25 | void argPortParsing(int argc, char* argv[], char* port) |
9 | 26 | { |
10 | 27 | struct option port_arg={"port", 1, NULL, 'p'}; |
... | ... | @@ -30,8 +47,8 @@ int main(int argc, char* argv[]) |
30 | 47 | char port[10]="80"; |
31 | 48 | argPortParsing(argc, argv, port); |
32 | 49 | |
33 | - | |
34 | - int sock_fd; | |
50 | + action.sa_handler=&handler; | |
51 | + sigaction(SIGINT, &action, NULL); | |
35 | 52 | |
36 | 53 | if( (sock_fd=initialisationServeur(port)) ==-1 ) { fprintf(stderr, "Initialisation du serveur impossible\n"); return -1; } |
37 | 54 | ... | ... |
libs/libthrd.a
No preview for this file type