[fix] Fixed conflicts between TCP server sockets (at thread launch each have its own socket, then it becomes the same, reference err) -> so memcpy the socket at launch)
This commit is contained in:
parent
095706b24f
commit
b245e6f623
|
@ -39,14 +39,15 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
int read, i, index, pindex; // compteurs
|
int read, i, index, pindex; // compteurs
|
||||||
char buffer[MAX_BUF_LEN]; // buffer
|
char buffer[MAX_BUF_LEN]; // buffer
|
||||||
struct plane data; // données de l'avion
|
struct plane data; // données de l'avion
|
||||||
struct sockaddr_in clientInfo; // Info client
|
int SOCKET; // Copie de la socket (évite les conflits de références)
|
||||||
socklen_t len;
|
|
||||||
|
|
||||||
|
|
||||||
/* 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));
|
||||||
if( DEBUGMOD&HDR ) printf("===== managePlane(%p, %p, %d, %p) =====\n", (void*) arg->managers, (void*) arg->activeManagers, arg->socket, (void*) arg->sgca);
|
if( DEBUGMOD&HDR ) printf("===== managePlane(%p, %p, %d, %p) =====\n", (void*) arg->managers, (void*) arg->activeManagers, arg->socket, (void*) arg->sgca);
|
||||||
|
|
||||||
|
|
||||||
/* 3. On récupère le rang du thread parmi les "managers" */
|
/* 3. On récupère le rang du thread parmi les "managers" */
|
||||||
index = -1;
|
index = -1;
|
||||||
for( i = 0 ; i < MAX_TCP_THR ; i++ )
|
for( i = 0 ; i < MAX_TCP_THR ; i++ )
|
||||||
|
@ -64,8 +65,7 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
/* (2) Récupération de la requête
|
/* (2) Récupération de la requête
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* 1. On lit sur la socket */
|
/* 1. On lit sur la socket */
|
||||||
len = sizeof(struct sockaddr_in);
|
read = recv(SOCKET, buffer, MAX_BUF_LEN, 0);
|
||||||
read = recvfrom(arg->socket, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
|
|
||||||
|
|
||||||
/* 2.1. Si erreur reception (-1:erreur, 0:fermeture client propre) */
|
/* 2.1. Si erreur reception (-1:erreur, 0:fermeture client propre) */
|
||||||
if( read <= 0 ){
|
if( read <= 0 ){
|
||||||
|
@ -149,10 +149,7 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
|
|
||||||
/* (5) Envoi de la réponse
|
/* (5) Envoi de la réponse
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
len = sizeof(struct sockaddr_in);
|
read = send(SOCKET, buffer, PLANE_LEN/sizeof(char) + 1, 0);
|
||||||
read = sendto(arg->socket, buffer, PLANE_LEN/sizeof(char) + 1, 0, (struct sockaddr*) &clientInfo, len);
|
|
||||||
|
|
||||||
printf("send: %d\n", read);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +164,7 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
/* [6] Fermeture de la connection (SOCKET)
|
/* [6] Fermeture de la connection (SOCKET)
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
printf("{tcp_com}(%d) Fermeture de la socket de communication!\n", index);
|
printf("{tcp_com}(%d) Fermeture de la socket de communication!\n", index);
|
||||||
close(arg->socket);
|
close(SOCKET);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,13 @@ struct control ctrl;
|
||||||
int mcast_socket = -1;
|
int mcast_socket = -1;
|
||||||
int commu_socket = -1;
|
int commu_socket = -1;
|
||||||
char buffer[MAX_BUF_LEN] = {0};
|
char buffer[MAX_BUF_LEN] = {0};
|
||||||
|
struct sockaddr_in sgca;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int open_communication(){
|
int open_communication(){
|
||||||
/* 0. Initialisation des variables */
|
/* 0. Initialisation des variables */
|
||||||
struct sockaddr_in udp, tcp; // données des sockets
|
struct sockaddr_in udp; // données des sockets
|
||||||
char buffer[MAX_BUF_LEN] = {0}; // buffer
|
char buffer[MAX_BUF_LEN] = {0}; // buffer
|
||||||
int status;
|
int status;
|
||||||
struct bind_header request;
|
struct bind_header request;
|
||||||
|
@ -70,6 +70,7 @@ int open_communication(){
|
||||||
// on indian-switch
|
// on indian-switch
|
||||||
request.port = ntohs(request.port);
|
request.port = ntohs(request.port);
|
||||||
|
|
||||||
|
// printf("* hex("); for( int i = 0 ; i < BINDHDR_LEN/sizeof(char) ; i++ ) printf("\\x%02X", buffer[i]); printf(")\n");
|
||||||
printf("* received bind_header{flags = %d; addr = %s; port = %d;}\n\n", request.flags, request.addr, request.port);
|
printf("* received bind_header{flags = %d; addr = %s; port = %d;}\n\n", request.flags, request.addr, request.port);
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ int open_communication(){
|
||||||
/* (1) Création socket TCP + connection
|
/* (1) Création socket TCP + connection
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* 1. Création socket TCP + connection serveur */
|
/* 1. Création socket TCP + connection serveur */
|
||||||
if( TCP_CONNECT(&commu_socket, request.addr, request.port, &tcp) < 0 )
|
if( TCP_CONNECT(&commu_socket, request.addr, request.port, &sgca) < 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -131,10 +132,11 @@ void send_data(){
|
||||||
|
|
||||||
read = send(commu_socket, buffer, PLANE_DATA_LEN/sizeof(char) + 1, 0);
|
read = send(commu_socket, buffer, PLANE_DATA_LEN/sizeof(char) + 1, 0);
|
||||||
|
|
||||||
if( read < 0 ){
|
if( read <= 0 ){
|
||||||
printf("Erreur d'envoi\n");
|
printf("Erreur d'envoi\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// printf("* hex("); for( int i = 0 ; i < PLANE_DATA_LEN/sizeof(char) ; i++ ) printf("\\x%02X", buffer[i]); printf(")\n");
|
||||||
|
|
||||||
/* 4. Récupération réponse */
|
/* 4. Récupération réponse */
|
||||||
read = recv(commu_socket, buffer, MAX_BUF_LEN, 0);
|
read = recv(commu_socket, buffer, MAX_BUF_LEN, 0);
|
||||||
|
|
Loading…
Reference in New Issue