Better separation of transport and network layer, extension of IP_send and IP_receive to enable easy development of multiple sockets in mictcp
This commit is contained in:
parent
13766b7c78
commit
25b296efea
7 changed files with 37 additions and 22 deletions
|
@ -10,8 +10,8 @@
|
|||
|
||||
int initialize_components(start_mode sm);
|
||||
|
||||
int IP_send(mic_tcp_pdu, mic_tcp_sock_addr);
|
||||
int IP_recv(mic_tcp_pdu*, mic_tcp_sock_addr*, unsigned long timeout);
|
||||
int IP_send(mic_tcp_pdu, mic_tcp_ip_addr);
|
||||
int IP_recv(mic_tcp_pdu* pk, mic_tcp_ip_addr* local_addr, mic_tcp_ip_addr* remote_addr, unsigned long timeout);
|
||||
int app_buffer_get(mic_tcp_payload);
|
||||
void app_buffer_put(mic_tcp_payload);
|
||||
|
||||
|
|
|
@ -30,13 +30,21 @@ typedef enum protocol_state
|
|||
*/
|
||||
typedef enum start_mode { CLIENT, SERVER } start_mode;
|
||||
|
||||
/*
|
||||
* Structure d’une adresse IP
|
||||
*/
|
||||
typedef struct mic_tcp_ip_addr
|
||||
{
|
||||
char * addr;
|
||||
int addr_size;
|
||||
} mic_tcp_ip_addr;
|
||||
|
||||
/*
|
||||
* Structure d’une adresse de socket
|
||||
*/
|
||||
typedef struct mic_tcp_sock_addr
|
||||
{
|
||||
char * ip_addr;
|
||||
int ip_addr_size;
|
||||
mic_tcp_ip_addr ip_addr;
|
||||
unsigned short port;
|
||||
} mic_tcp_sock_addr;
|
||||
|
||||
|
@ -47,7 +55,8 @@ typedef struct mic_tcp_sock
|
|||
{
|
||||
int fd; /* descripteur du socket */
|
||||
protocol_state state; /* état du protocole */
|
||||
mic_tcp_sock_addr addr; /* adresse du socket */
|
||||
mic_tcp_sock_addr local_addr; /* adresse locale du socket */
|
||||
mic_tcp_sock_addr remote_addr; /* adresse distante du socket */
|
||||
} mic_tcp_sock;
|
||||
|
||||
/*
|
||||
|
@ -99,7 +108,7 @@ int mic_tcp_accept(int socket, mic_tcp_sock_addr* addr);
|
|||
int mic_tcp_connect(int socket, mic_tcp_sock_addr addr);
|
||||
int mic_tcp_send (int socket, char* mesg, int mesg_size);
|
||||
int mic_tcp_recv (int socket, char* mesg, int max_mesg_size);
|
||||
void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr);
|
||||
void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_ip_addr local_addr, mic_tcp_ip_addr remote_addr);
|
||||
int mic_tcp_close(int socket);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -94,7 +94,7 @@ int initialize_components(start_mode mode)
|
|||
|
||||
|
||||
|
||||
int IP_send(mic_tcp_pdu pk, mic_tcp_sock_addr addr)
|
||||
int IP_send(mic_tcp_pdu pk, mic_tcp_ip_addr addr)
|
||||
{
|
||||
|
||||
int result = 0;
|
||||
|
@ -115,7 +115,7 @@ int IP_send(mic_tcp_pdu pk, mic_tcp_sock_addr addr)
|
|||
return result;
|
||||
}
|
||||
|
||||
int IP_recv(mic_tcp_pdu* pk, mic_tcp_sock_addr* addr, unsigned long timeout)
|
||||
int IP_recv(mic_tcp_pdu* pk, mic_tcp_ip_addr* local_addr, mic_tcp_ip_addr* remote_addr, unsigned long timeout)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
|
@ -148,12 +148,15 @@ int IP_recv(mic_tcp_pdu* pk, mic_tcp_sock_addr* addr, unsigned long timeout)
|
|||
memcpy (pk->payload.data, buffer + API_HD_Size, pk->payload.size);
|
||||
|
||||
/* Generate a stub address */
|
||||
if (addr != NULL) {
|
||||
addr->ip_addr = "localhost";
|
||||
addr->ip_addr_size = strlen(addr->ip_addr) + 1; // don't forget '\0'
|
||||
addr->port = pk->header.source_port;
|
||||
if (remote_addr != NULL) {
|
||||
remote_addr->addr = "localhost";
|
||||
remote_addr->addr_size = strlen(remote_addr->addr) + 1; // don't forget '\0'
|
||||
}
|
||||
|
||||
if (local_addr != NULL) {
|
||||
local_addr->addr = "localhost";
|
||||
local_addr->addr_size = strlen(local_addr->addr) + 1; // don't forget '\0'
|
||||
}
|
||||
/* Correct the receved size */
|
||||
result -= API_HD_Size;
|
||||
}
|
||||
|
@ -290,7 +293,8 @@ void* listening(void* arg)
|
|||
{
|
||||
mic_tcp_pdu pdu_tmp;
|
||||
int recv_size;
|
||||
mic_tcp_sock_addr remote;
|
||||
mic_tcp_ip_addr remote;
|
||||
mic_tcp_ip_addr local;
|
||||
|
||||
pthread_mutex_init(&lock, NULL);
|
||||
|
||||
|
@ -304,11 +308,11 @@ void* listening(void* arg)
|
|||
while(1)
|
||||
{
|
||||
pdu_tmp.payload.size = payload_size;
|
||||
recv_size = IP_recv(&pdu_tmp, &remote, 0);
|
||||
recv_size = IP_recv(&pdu_tmp, &local, &remote, 0);
|
||||
|
||||
if(recv_size != -1)
|
||||
{
|
||||
process_received_PDU(pdu_tmp, remote);
|
||||
process_received_PDU(pdu_tmp, local, remote);
|
||||
} else {
|
||||
/* This should never happen */
|
||||
printf("Error in recv\n");
|
||||
|
|
|
@ -10,7 +10,8 @@ int main()
|
|||
int sockfd = 0;
|
||||
char chaine[MAX_SIZE];
|
||||
mic_tcp_sock_addr addr;
|
||||
addr.ip_addr = "127.0.0.1";
|
||||
addr.ip_addr.addr = "127.0.0.1";
|
||||
addr.ip_addr.addr_size = strlen("127.0.0.1") + 1;
|
||||
addr.port = 1234;
|
||||
|
||||
if ((sockfd = mic_tcp_socket(CLIENT)) == -1)
|
||||
|
|
|
@ -218,8 +218,8 @@ static void file_to_mictcp(char* filename)
|
|||
|
||||
/* On effectue la connexion */
|
||||
mic_tcp_sock_addr dest_addr;
|
||||
dest_addr.ip_addr = "localhost";
|
||||
dest_addr.ip_addr_size = strlen(dest_addr.ip_addr) + 1; // '\0'
|
||||
dest_addr.ip_addr.addr = "localhost";
|
||||
dest_addr.ip_addr.addr_size = strlen(dest_addr.ip_addr.addr) + 1; // '\0'
|
||||
dest_addr.port = MICTCP_PORT;
|
||||
if (mic_tcp_connect(sockfd, dest_addr) == -1) {
|
||||
printf("ERROR connecting the MICTCP socket\n");
|
||||
|
@ -288,8 +288,8 @@ static void mictcp_to_udp(char *host, int port)
|
|||
|
||||
/* On bind le socket mictcp à une adresse locale */
|
||||
mic_tcp_sock_addr mt_local_addr;
|
||||
mt_local_addr.ip_addr = NULL;
|
||||
mt_local_addr.ip_addr_size = 0;
|
||||
mt_local_addr.ip_addr.addr = NULL;
|
||||
mt_local_addr.ip_addr.addr_size = 0;
|
||||
mt_local_addr.port = MICTCP_PORT;
|
||||
if (mic_tcp_bind(mictcp_sockfd, mt_local_addr) == -1) {
|
||||
printf("ERROR on binding the MICTCP socket\n");
|
||||
|
|
|
@ -10,7 +10,8 @@ int main()
|
|||
mic_tcp_sock_addr remote_addr;
|
||||
char chaine[MAX_SIZE];
|
||||
|
||||
addr.ip_addr = "127.0.0.1";
|
||||
addr.ip_addr.addr = "127.0.0.1";
|
||||
addr.ip_addr.addr_size = strlen(addr.ip_addr.addr) + 1;
|
||||
addr.port = 1234;
|
||||
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ int mic_tcp_close (int socket)
|
|||
* le buffer de réception du socket. Cette fonction utilise la fonction
|
||||
* app_buffer_put().
|
||||
*/
|
||||
void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr)
|
||||
void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_ip_addr local_addr, mic_tcp_ip_addr remote_addr)
|
||||
{
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue