[sys net destiny]

- added dynamic treatment of sending data via send() > MSS
This commit is contained in:
Oliver 2012-02-08 04:46:54 +01:00
parent eed1de6d29
commit cc7f4e0a7b
3 changed files with 85 additions and 73 deletions

View File

@ -94,7 +94,7 @@ void tcp_ch(void)
read_bytes = recv(SocketFD, buff_msg, MAX_TCP_BUFFER, 0); read_bytes = recv(SocketFD, buff_msg, MAX_TCP_BUFFER, 0);
if (read_bytes > 0) if (read_bytes > 0)
{ {
// printf("--- Message: %s ---\n", buff_msg); printf("--- Message: %s ---\n", buff_msg);
} }
} }
@ -184,7 +184,7 @@ void init_tcp_server(void)
if (read_bytes > 0) if (read_bytes > 0)
{ {
// printf("--- Read bytes: %i, Strlen(): %i, Message: %s ---\n", read_bytes, strlen(buff_msg), buff_msg); printf("--- Read bytes: %i, Strlen(): %i, Message: %s ---\n", read_bytes, strlen(buff_msg), buff_msg);
} }
} }
} }

View File

@ -530,13 +530,12 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
{ {
// Variables // Variables
msg_t recv_msg; msg_t recv_msg;
int32_t sent_bytes = 0; int32_t sent_bytes = 0, total_sent_bytes = 0;
socket_internal_t *current_int_tcp_socket; socket_internal_t *current_int_tcp_socket;
socket_t *current_tcp_socket; socket_t *current_tcp_socket;
uint8_t send_buffer[BUFFER_SIZE]; uint8_t send_buffer[BUFFER_SIZE];
ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t*)(&send_buffer)); ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t*)(&send_buffer));
tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t*)(&send_buffer[IPV6_HDR_LEN])); tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t*)(&send_buffer[IPV6_HDR_LEN]));
// msg_init_queue(send_msg_queue, SEND_MSG_BUF_SIZE);
// Check if socket exists and is TCP socket // Check if socket exists and is TCP socket
if (!isTCPSocket(s)) if (!isTCPSocket(s))
@ -555,7 +554,8 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
// Add thread PID // Add thread PID
current_int_tcp_socket->send_pid = thread_getpid(); current_int_tcp_socket->send_pid = thread_getpid();
while (1)
{
current_tcp_socket->tcp_control.no_of_retry = 0; current_tcp_socket->tcp_control.no_of_retry = 0;
#ifdef TCP_HC #ifdef TCP_HC
@ -568,15 +568,17 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
while (1) while (1)
{ {
// Add packet data // Add packet data
if (len > current_tcp_socket->tcp_control.send_wnd) if ((len-total_sent_bytes) > current_tcp_socket->tcp_control.send_wnd)
{ {
memcpy(&send_buffer[IPV6_HDR_LEN+TCP_HDR_LEN], msg, current_tcp_socket->tcp_control.send_wnd); memcpy(&send_buffer[IPV6_HDR_LEN+TCP_HDR_LEN], msg, current_tcp_socket->tcp_control.send_wnd);
sent_bytes = current_tcp_socket->tcp_control.send_wnd; sent_bytes = current_tcp_socket->tcp_control.send_wnd;
total_sent_bytes += sent_bytes;
} }
else else
{ {
memcpy(&send_buffer[IPV6_HDR_LEN+TCP_HDR_LEN], msg, len); memcpy(&send_buffer[IPV6_HDR_LEN+TCP_HDR_LEN], msg+total_sent_bytes, len-total_sent_bytes);
sent_bytes = len; sent_bytes = len-total_sent_bytes;
total_sent_bytes = len;
} }
current_tcp_socket->tcp_control.send_nxt += sent_bytes; current_tcp_socket->tcp_control.send_nxt += sent_bytes;
@ -603,7 +605,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
case TCP_ACK: case TCP_ACK:
{ {
tcp_hdr_t *tcp_header = ((tcp_hdr_t*)(recv_msg.content.ptr)); tcp_hdr_t *tcp_header = ((tcp_hdr_t*)(recv_msg.content.ptr));
if (current_tcp_socket->tcp_control.send_nxt == tcp_header->ack_nr) if ((current_tcp_socket->tcp_control.send_nxt == tcp_header->ack_nr) && (total_sent_bytes == len))
{ {
current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr;
current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr;
@ -614,9 +616,20 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
#endif #endif
return sent_bytes; return sent_bytes;
} }
else if ((current_tcp_socket->tcp_control.send_nxt == tcp_header->ack_nr) && (total_sent_bytes != len))
{
current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr;
current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr;
current_tcp_socket->tcp_control.send_wnd = tcp_header->window;
// Got ACK for every sent byte
#ifdef TCP_HC
current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
#endif
break;
}
else else
{ {
// TODO: Handle retransmit of missing bytes // TODO: If window size > MSS, ACK was valid only for a few segments, handle retransmit of missing segments
break; break;
} }
} }
@ -643,6 +656,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
} }
} }
} }
}
return sent_bytes; return sent_bytes;
} }
@ -688,14 +702,12 @@ int recv(int s, void *buf, uint64_t len, int flags)
// Setting Thread PID // Setting Thread PID
current_int_tcp_socket->recv_pid = thread_getpid(); current_int_tcp_socket->recv_pid = thread_getpid();
if (current_int_tcp_socket->tcp_input_buffer_end > 0) if (current_int_tcp_socket->tcp_input_buffer_end > 0)
{ {
return read_from_socket(current_int_tcp_socket, buf, len); return read_from_socket(current_int_tcp_socket, buf, len);
} }
msg_receive(&m_recv); msg_receive(&m_recv);
if ((exists_socket(s)) && (current_int_tcp_socket->tcp_input_buffer_end > 0)) if ((exists_socket(s)) && (current_int_tcp_socket->tcp_input_buffer_end > 0))
{ {
read_bytes = read_from_socket(current_int_tcp_socket, buf, len); read_bytes = read_from_socket(current_int_tcp_socket, buf, len);

View File

@ -112,7 +112,7 @@
#define EPHEMERAL_PORTS 49152 #define EPHEMERAL_PORTS 49152
#define STATIC_MSS 48 #define STATIC_MSS 16
#define STATIC_WINDOW 1 * STATIC_MSS #define STATIC_WINDOW 1 * STATIC_MSS
#define MAX_TCP_BUFFER 1 * STATIC_WINDOW #define MAX_TCP_BUFFER 1 * STATIC_WINDOW