summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/v3_c/src/CMakeLists.txt8
-rw-r--r--app/v3_c/src/dispatcher.c (renamed from app/v3_c/src/process.c)12
-rw-r--r--app/v3_c/src/include/dispatcher.h13
-rw-r--r--app/v3_c/src/include/process.h13
-rw-r--r--app/v3_c/src/main.c9
-rw-r--r--app/v3_c/src/tcpserver.c (renamed from app/v3_c/src/myhttpd.c)20
-rw-r--r--app/v3_c/src/tcpserver.h.in10
7 files changed, 52 insertions, 33 deletions
diff --git a/app/v3_c/src/CMakeLists.txt b/app/v3_c/src/CMakeLists.txt
index 4a85291..7953490 100644
--- a/app/v3_c/src/CMakeLists.txt
+++ b/app/v3_c/src/CMakeLists.txt
@@ -3,10 +3,10 @@ set(SRC_COMMON utils.c)
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
- "myhttpd.h.in"
- "${PROJECT_BINARY_DIR}/myhttpd.h"
+ "tcpserver.h.in"
+ "${PROJECT_BINARY_DIR}/tcpserver.h"
)
-add_executable(myhttpd myhttpd.c process.c ${SRC_COMMON} )
-#target_link_libraries(netlem SDL SDL_net SDL_image)
+add_executable(usi2011jjl main.c tcpserver.c dispatcher.c ${SRC_COMMON} )
+#target_link_libraries(usi2011jjl SDL SDL_net SDL_image)
diff --git a/app/v3_c/src/process.c b/app/v3_c/src/dispatcher.c
index 630c718..84b1fda 100644
--- a/app/v3_c/src/process.c
+++ b/app/v3_c/src/dispatcher.c
@@ -1,10 +1,10 @@
#include <stdlib.h>
#include <unistd.h>
-#include "process.h"
+#include "dispatcher.h"
#include "utils.h"
-int initProcess() {
+int initDispatcher() {
// Créer au départ toutes les zones mémoire à gérer + pool de threads + files de sockets en attente...
// Utiliser des déclarations globales dans ce fichier et gérer la concurrence entre les threads
@@ -13,21 +13,21 @@ int initProcess() {
// Appelé des qu'un nouveau socket client est créé via accept().
// Un retour non nul de cette fonction provoque l'arrêt du serveur http
-int requestProcess(int sockfd, struct sockaddr_in *addr, socklen_t *addrlen ) {
+int requestDispatcher(int sockfd, struct sockaddr_in *addr, socklen_t *addrlen ) {
#ifdef HEAVYDEBUG
- logs("requestProcess start");
+ logs("requestDispatcher start");
#endif
if ( 0 ) { printf("%i %p %p\n", sockfd, (void *)addr, (void *)addrlen); }
close(sockfd);
#ifdef HEAVYDEBUG
- logs("requestProcess end");
+ logs("requestDispatcher end");
#endif
return 0;
}
-void freeProcess() {
+void freeDispatcher() {
// Libérer tous les espaces histoire de voir des infos propres dans valgrind
return;
}
diff --git a/app/v3_c/src/include/dispatcher.h b/app/v3_c/src/include/dispatcher.h
new file mode 100644
index 0000000..a3e779a
--- /dev/null
+++ b/app/v3_c/src/include/dispatcher.h
@@ -0,0 +1,13 @@
+#ifndef DISPATCHER_H
+#define DISPATCHER_H
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int initDispatcher();
+int requestDispatcher(int sockfd, struct sockaddr_in *addr, socklen_t *addrlen );
+void freeDispatcher();
+
+#endif
diff --git a/app/v3_c/src/include/process.h b/app/v3_c/src/include/process.h
deleted file mode 100644
index c88b235..0000000
--- a/app/v3_c/src/include/process.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef PROCESS_H
-#define PROCESS_H
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-int initProcess();
-int requestProcess(int sockfd, struct sockaddr_in *addr, socklen_t *addrlen );
-void freeProcess();
-
-#endif
diff --git a/app/v3_c/src/main.c b/app/v3_c/src/main.c
new file mode 100644
index 0000000..c88485e
--- /dev/null
+++ b/app/v3_c/src/main.c
@@ -0,0 +1,9 @@
+#include "tcpserver.h"
+
+#define USI2011JJL_VERSION_MAJOR @USI2011JJL_VERSION_MAJOR@
+#define USI2011JJL_VERSION_MINOR @USI2011JJL_VERSION_MINOR@
+
+
+int main() {
+ return tcpserver();
+}
diff --git a/app/v3_c/src/myhttpd.c b/app/v3_c/src/tcpserver.c
index 9d77949..53b86a9 100644
--- a/app/v3_c/src/myhttpd.c
+++ b/app/v3_c/src/tcpserver.c
@@ -9,16 +9,16 @@
#include <unistd.h>
#include <signal.h>
-#include "myhttpd.h"
-#include "process.h"
#include "utils.h"
+#include "tcpserver.h"
+#include "dispatcher.h"
int end=0;
-void signals(int signum) {
+void _signals(int signum) {
static int force=0;
- if (0) printf("signal %i\n");
+ if (0) printf("signal %i\n", signum);
if(!force) {
end=1;
@@ -31,7 +31,7 @@ void signals(int signum) {
}
-int main() {
+int tcpserver() {
int res;
int sockServ, sockCli;
struct sockaddr_in servAddr, cliAddr;
@@ -54,12 +54,12 @@ int main() {
if (res < 0) { perror("listen"); return(4); }
// On active la gestion des signaux
- signal(2,signals);
+ signal(2,_signals);
- res=initProcess();
+ res=initDispatcher();
if (res != 0 ) {
#ifdef DEBUG
- logs("initProcess() error");
+ logs("initDispatcher() error");
#endif
return(5);
}
@@ -100,11 +100,11 @@ int main() {
#ifdef HEAVYDEBUG
logs("Client accepté");
#endif
- end=requestProcess(sockCli, &cliAddr, &cliAddrLen);
+ end=requestDispatcher(sockCli, &cliAddr, &cliAddrLen);
}
}
- freeProcess();
+ freeDispatcher();
if ( end != 1 ) {
#ifdef DEBUG
diff --git a/app/v3_c/src/tcpserver.h.in b/app/v3_c/src/tcpserver.h.in
new file mode 100644
index 0000000..14b6736
--- /dev/null
+++ b/app/v3_c/src/tcpserver.h.in
@@ -0,0 +1,10 @@
+#ifndef TCPSERVER_H
+#define TCPSERVER_H
+
+#define LISTEN_PORT 8080
+#define LISTEN_BACKLOG 5
+
+int tcpserver();
+
+#endif
+