Merge remote-tracking branch 'origin/master'

This commit is contained in:
SeekDaSky 2017-05-19 09:35:53 +02:00
commit d11649e9b9
3 changed files with 28 additions and 18 deletions

View File

@ -23,5 +23,5 @@ all: boot
# cleans the compiled files # cleans the compiled files
clean: clean:
@find ./lib/network/**/*.o >/dev/null 2>&1 && rm ./lib/network/**/*.o || return 0; @rm ./lib/network/**/*.o;
@find ./boot >/dev/null 2>&1 && rm ./boot || return 0; @rm ./boot;

View File

@ -35,7 +35,7 @@ all: boot
# cleans the compiled files # cleans the compiled files
clean: clean:
@find lib/network/*.o >/dev/null 2>&1 && rm lib/network/*.o || return 0; @rm lib/network/*.o;
@find lib/network/**/*.o >/dev/null 2>&1 && rm lib/network/**/*.o || return 0; @rm lib/network/**/*.o;
@find lib/local/*.o >/dev/null 2>&1 && rm lib/local/*.o || return 0; @rm lib/local/*.o;
@find boot >/dev/null 2>&1 && rm boot || return 0; @rm boot;

View File

@ -215,9 +215,11 @@ void* manageViewTerm(void* THREADABLE_ARGS){
int sent; // compteurs d'envoi int sent; // compteurs d'envoi
int i, index = -1; // Compteurs globaux int i, index = -1; // Compteurs globaux
char* buffer = malloc(1); // Buffer d'envoi char* buffer = malloc(1); // Buffer d'envoi
int SOCKET;
/* 2. On récupère les arguments */ /* 2. On récupère les arguments */
struct handler_arg* arg = THREADABLE_ARGS; struct handler_arg* arg = THREADABLE_ARGS;
memcpy(&SOCKET, &arg->socket, sizeof(int));
/* 3. On récupère le rang dans les "managers" */ /* 3. On récupère le rang dans les "managers" */
for( i = 0 ; i < MAX_UDP_THR ; i++ ) for( i = 0 ; i < MAX_UDP_THR ; i++ )
@ -228,7 +230,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
/* 4. Attente d'un client */ /* 4. Attente d'un client */
len = sizeof(struct sockaddr_in); len = sizeof(struct sockaddr_in);
if( recvfrom(arg->socket, buffer, MAX_BUF_LEN*sizeof(char), 0, (struct sockaddr*) &clientInfo, &len) < 0 ){ if( recvfrom(SOCKET, buffer, MAX_BUF_LEN*sizeof(char), 0, (struct sockaddr*) &clientInfo, &len) < 0 ){
printf("{udp_vterm}{com}(%d) No terminal detected, exiting\n", index); printf("{udp_vterm}{com}(%d) No terminal detected, exiting\n", index);
loop = 0; loop = 0;
} }
@ -248,7 +250,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
=========================================================*/ =========================================================*/
/* 2. Envoi */ /* 2. Envoi */
len = sizeof(struct sockaddr_in); len = sizeof(struct sockaddr_in);
sent = sendto(arg->socket, buffer, buflen + 1, 0, (struct sockaddr*) &clientInfo, len); sent = sendto(SOCKET, buffer, buflen + 1, 0, (struct sockaddr*) &clientInfo, len);
/* 3. Gestion erreur */ /* 3. Gestion erreur */
if( sent <= 0 ){ if( sent <= 0 ){
@ -261,7 +263,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
=========================================================*/ =========================================================*/
/* 1. Réception feedback (0x10) */ /* 1. Réception feedback (0x10) */
len = sizeof(struct sockaddr_in); len = sizeof(struct sockaddr_in);
sent = recvfrom(arg->socket, buffer, 1, 0, (struct sockaddr*) &clientInfo, &len); sent = recvfrom(SOCKET, buffer, 1, 0, (struct sockaddr*) &clientInfo, &len);
/* 2. Gestion erreur (erreur ou mauvais feedback != 0x10) */ /* 2. Gestion erreur (erreur ou mauvais feedback != 0x10) */
if( sent <= 0 || buffer[0] != TERMREQ_OFF ){ if( sent <= 0 || buffer[0] != TERMREQ_OFF ){
@ -284,7 +286,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
arg->activeUDPManagers[index] = 0; arg->activeUDPManagers[index] = 0;
/* 2. On ferme la socket + libère la mémoire */ /* 2. On ferme la socket + libère la mémoire */
close(arg->socket); close(SOCKET);
free(buffer); free(buffer);
@ -331,10 +333,13 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
char* dataBuffer = malloc(1); char* dataBuffer = malloc(1);
struct term_req request; // Requête struct term_req request; // Requête
char flags; char flags;
int SOCKET;
struct in_addr* ip = malloc(sizeof(struct in_addr));
/* 2. On récupère les arguments */ /* 2. On récupère les arguments */
struct handler_arg* arg = THREADABLE_ARGS; struct handler_arg* arg = THREADABLE_ARGS;
memcpy(&SOCKET, &arg->socket, sizeof(int));
/* 3. On récupère le rang dans les "managers" */ /* 3. On récupère le rang dans les "managers" */
for( i = 0 ; i < MAX_UDP_THR ; i++ ) for( i = 0 ; i < MAX_UDP_THR ; i++ )
@ -344,11 +349,16 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
/* 4. Attente d'un client */ /* 4. Attente d'un client */
len = sizeof(struct sockaddr_in); len = sizeof(struct sockaddr_in);
if( recvfrom(arg->socket, buffer, MAX_BUF_LEN*sizeof(char), 0, (struct sockaddr*) &clientInfo, &len) < 0 ){ if( recvfrom(SOCKET, buffer, MAX_BUF_LEN*sizeof(char), 0, (struct sockaddr*) &clientInfo, &len) < 0 ){
printf("{udp_cterm}{com}(%d) No terminal detected, exiting\n", index); printf("{udp_cterm}{com}(%d) No terminal detected, exiting\n", index);
loop = 0; loop = 0;
}else }else{
printf("{udp_cterm}{com}(%d) Terminal connected\n", index); ip->s_addr = clientInfo.sin_addr.s_addr;
printf("{udp_cterm}{com}(%d) Terminal connected from %s:%d\n", index, inet_ntoa(*ip), ntohs(clientInfo.sin_port));
}
free(ip);
while( loop ){ while( loop ){
@ -360,14 +370,14 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
/* 1. On lit sur la socket */ /* 1. On lit sur la socket */
len = sizeof(struct sockaddr_in); len = sizeof(struct sockaddr_in);
bzero(buffer, sizeof(char)*MAX_BUF_LEN); bzero(buffer, sizeof(char)*MAX_BUF_LEN);
count = recvfrom(arg->socket, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len); count = recvfrom(SOCKET, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
/* 2. Si erreur reception */ /* 2. Si erreur reception */
if( count <= 0 ) // because of timeout or error if( count <= 0 ) // because of timeout or error
break; break;
if( count < TERMREQ_LEN ){ if( count < TERMREQ_LEN ){
send(arg->socket, "\0\0", sizeof(char)*2, 0); send(SOCKET, "\0\0", sizeof(char)*2, 0);
if( DEBUGMOD&BUF ) printf("{udp_cterm}{com}(%d) Error receiving request\n", index); if( DEBUGMOD&BUF ) printf("{udp_cterm}{com}(%d) Error receiving request\n", index);
continue; continue;
} }
@ -390,7 +400,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
update = ( request.flags&TERMREQ_ALT || request.flags&TERMREQ_CAP || request.flags&TERMREQ_SPD ); update = ( request.flags&TERMREQ_ALT || request.flags&TERMREQ_CAP || request.flags&TERMREQ_SPD );
fbk = request.flags&TERMREQ_FBK; fbk = request.flags&TERMREQ_FBK;
if( !( update || fbk ) ){ if( !( update || fbk ) ){
send(arg->socket, "\x00\0", sizeof(char)*2, 0); send(SOCKET, "\x00\0", sizeof(char)*2, 0);
if( request.flags != 0 ) if( request.flags != 0 )
printf("{udp_cterm}{com}(%d) Invalid flags\n", index); printf("{udp_cterm}{com}(%d) Invalid flags\n", index);
continue; continue;
@ -500,7 +510,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
=========================================================*/ =========================================================*/
printf("{udp_cterm}{com}(%d) Sending response { flags: %d; n: %d }\n", index, dataBuffer[0], dataBuffer[1]); printf("{udp_cterm}{com}(%d) Sending response { flags: %d; n: %d }\n", index, dataBuffer[0], dataBuffer[1]);
len = sizeof(struct sockaddr_in); len = sizeof(struct sockaddr_in);
if( sendto(arg->socket, dataBuffer, dataLen, 0, (struct sockaddr*) &clientInfo, len) < 0 ) if( sendto(SOCKET, dataBuffer, dataLen, 0, (struct sockaddr*) &clientInfo, len) < 0 )
printf("{udp_cterm}{com}(%d) Cannot answer to terminal\n", index); printf("{udp_cterm}{com}(%d) Cannot answer to terminal\n", index);
@ -514,7 +524,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
arg->activeUDPManagers[index] = 0; arg->activeUDPManagers[index] = 0;
/* 2. On ferme la socket */ /* 2. On ferme la socket */
close(arg->socket); close(SOCKET);
free(dataBuffer); free(dataBuffer);
/* 3. On arrête le THREAD */ /* 3. On arrête le THREAD */