merge branch leo
This commit is contained in:
commit
5140f704d7
1 changed files with 79 additions and 1 deletions
80
src/mictcp.c
80
src/mictcp.c
|
@ -39,6 +39,7 @@
|
|||
|
||||
int mic_tcp_socket(start_mode sm)
|
||||
{
|
||||
//ajouter return -1 en cas d'erreur
|
||||
int result=-1;
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
result = initialize_components(sm); /* Appel obligatoire */
|
||||
|
@ -72,10 +73,22 @@ int mic_tcp_accept(int socket, mic_tcp_sock_addr* addr)
|
|||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
//printf("Je vais dormir\n");
|
||||
pthread_cond_wait(&cond,&mutex);
|
||||
<<<<<<< HEAD
|
||||
//printf("Je suis réveillé\n");
|
||||
sock.state = CONNECTED;
|
||||
=======
|
||||
printf("Je suis réveillé\n");*/
|
||||
>>>>>>> leo
|
||||
|
||||
//retourne 0 si sock.state = established, -1 sinon
|
||||
if (sock.fd == socket){
|
||||
sock.state == CONNECTED;
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -147,7 +160,14 @@ int mic_tcp_connect(int socket, mic_tcp_sock_addr addr)
|
|||
if(IP_send(ack,sock.addr)==-1){
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
=======
|
||||
}*/
|
||||
|
||||
//se servir de addr et sock.addr + refaire condition pour avoir 0 ou -1 et c'est tout ??
|
||||
|
||||
>>>>>>> leo
|
||||
printf("Connected\n");
|
||||
init(fenetre,SIZE);
|
||||
sock.state=CONNECTED;
|
||||
|
@ -161,7 +181,30 @@ int mic_tcp_connect(int socket, mic_tcp_sock_addr addr)
|
|||
int mic_tcp_send (int mic_sock, char* mesg, int mesg_size)
|
||||
{
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
<<<<<<< HEAD
|
||||
int sent= -1;
|
||||
=======
|
||||
|
||||
//construction pdu
|
||||
pdu.header.syn = 0;
|
||||
pdu.header.ack = 0;
|
||||
pdu.header.fin = 0;
|
||||
pdu.header.seq_num= PE;
|
||||
|
||||
//payload
|
||||
pdu.payload.data = mesg;
|
||||
pdu.payload.size=mesg_size;
|
||||
|
||||
mic_tcp_pdu mem = pdu;
|
||||
//printf("%d\n",pdu.header.seq_num);
|
||||
|
||||
//envoi du pdu
|
||||
if((sent=IP_send(pdu,sock.addr))==-1){
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
}
|
||||
PE = (PE +1) %2;
|
||||
>>>>>>> leo
|
||||
|
||||
if(sock.state==CONNECTED){
|
||||
int max = 20;
|
||||
|
@ -252,6 +295,7 @@ int mic_tcp_recv (int socket, char* mesg, int max_mesg_size)
|
|||
pdu.payload.data=mesg;
|
||||
pdu.payload.size=max_mesg_size;
|
||||
return app_buffer_get(pdu.payload);
|
||||
//prendre en compte le cas d'erreur
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -264,6 +308,7 @@ int mic_tcp_close (int socket)
|
|||
printf("[MIC-TCP] Appel de la fonction : "); printf(__FUNCTION__); printf("\n");
|
||||
sock.state=CLOSED;
|
||||
return 0;
|
||||
//faire cas -1 / 0
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -275,6 +320,7 @@ int mic_tcp_close (int socket)
|
|||
void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr)
|
||||
{
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
<<<<<<< HEAD
|
||||
if (sock.state == CONNECTED){
|
||||
printf("Paquet recu \n");
|
||||
mic_tcp_pdu ack;
|
||||
|
@ -297,6 +343,38 @@ void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr)
|
|||
}
|
||||
printf("Ack envoyé \n");
|
||||
}else{
|
||||
=======
|
||||
printf("Paquet recu \n");
|
||||
printf("ACK NUM %d\n",pdu.header.seq_num);
|
||||
|
||||
mic_tcp_pdu ack;
|
||||
|
||||
if(pdu.header.seq_num == PA){
|
||||
app_buffer_put(pdu.payload);
|
||||
PA = (PA+1) %2;
|
||||
}else{
|
||||
printf("Paquet Ack perdu\n");
|
||||
}
|
||||
|
||||
//construction pdu ack
|
||||
ack.header.ack=1;
|
||||
ack.header.ack_num=PA;
|
||||
ack.header.fin=0;
|
||||
ack.header.syn=0;
|
||||
//init source port, dest port ??
|
||||
|
||||
ack.payload.data ="";
|
||||
ack.payload.size=0;
|
||||
|
||||
if (IP_send(ack,addr)==-1)
|
||||
{
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
}
|
||||
//printf("Ack envoyé \n");
|
||||
/*
|
||||
printf("Je me connecte\n");
|
||||
>>>>>>> leo
|
||||
int test=0;
|
||||
int sent= -1;
|
||||
int max = 20;
|
||||
|
|
Loading…
Reference in a new issue