Changeset d9ce049 in mainline
- Timestamp:
- 2011-10-04T20:40:05Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8c7a054
- Parents:
- 32105348
- Location:
- uspace/srv/net/tl/tcp
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/conn.c
r32105348 rd9ce049 70 70 71 71 /* Allocate receive buffer */ 72 fibril_mutex_initialize(&conn->rcv_buf_lock); 73 fibril_condvar_initialize(&conn->rcv_buf_cv); 72 74 conn->rcv_buf_size = RCV_BUF_SIZE; 73 75 conn->rcv_buf_used = 0; 76 74 77 conn->rcv_buf = calloc(1, conn->rcv_buf_size); 75 78 if (conn->rcv_buf == NULL) { … … 306 309 if ((seg->ctrl & CTL_ACK) != 0) { 307 310 conn->snd_una = seg->ack; 308 tcp_tqueue_remove_acked(conn); 311 312 /* 313 * Prune acked segments from retransmission queue and 314 * possibly transmit more data. 315 */ 316 tcp_tqueue_ack_received(conn); 309 317 } 310 318 … … 459 467 /* Update SND.UNA */ 460 468 conn->snd_una = seg->ack; 461 462 /* Prune acked segments from retransmission queue */463 tcp_tqueue_remove_acked(conn);464 469 } 465 470 … … 468 473 conn->snd_wl1 = seg->seq; 469 474 conn->snd_wl2 = seg->ack; 470 } 475 476 log_msg(LVL_DEBUG, "Updating send window, SND.WND=%" PRIu32 477 ", SND.WL1=%" PRIu32 ", SND.WL2=%" PRIu32, 478 conn->snd_wnd, conn->snd_wl1, conn->snd_wl2); 479 } 480 481 /* 482 * Prune acked segments from retransmission queue and 483 * possibly transmit more data. 484 */ 485 tcp_tqueue_ack_received(conn); 471 486 472 487 return cp_continue; … … 659 674 tcp_conn_trim_seg_to_wnd(conn, seg); 660 675 676 fibril_mutex_lock(&conn->rcv_buf_lock); 677 661 678 /* Determine how many bytes to copy */ 662 679 text_size = tcp_segment_text_size(seg); … … 664 681 665 682 /* Copy data to receive buffer */ 666 tcp_segment_text_copy(seg, conn->rcv_buf, xfer_size); 683 tcp_segment_text_copy(seg, conn->rcv_buf + conn->rcv_buf_used, 684 xfer_size); 685 conn->rcv_buf_used += xfer_size; 686 687 /* Signal to the receive function that new data has arrived */ 688 fibril_condvar_broadcast(&conn->rcv_buf_cv); 689 fibril_mutex_unlock(&conn->rcv_buf_lock); 667 690 668 691 log_msg(LVL_DEBUG, "Received %zu bytes of data.", xfer_size); -
uspace/srv/net/tl/tcp/iqueue.c
r32105348 rd9ce049 104 104 105 105 while (!seq_no_segment_acceptable(iqueue->conn, iqe->seg)) { 106 log_msg(LVL_DEBUG, "Skipping unacceptable segment"); 106 log_msg(LVL_DEBUG, "Skipping unacceptable segment (RCV.NXT=%" 107 PRIu32 ", RCV.NXT+RCV.WND=%" PRIu32 ", SEG.SEQ=%" PRIu32 108 ", SEG.LEN=%" PRIu32 ")", iqueue->conn->rcv_nxt, 109 iqueue->conn->rcv_nxt + iqueue->conn->rcv_wnd, 110 iqe->seg->seq, iqe->seg->len); 107 111 108 112 list_remove(&iqe->link); -
uspace/srv/net/tl/tcp/state.c
r32105348 rd9ce049 35 35 */ 36 36 37 #include <fibril_synch.h> 37 38 #include <io/log.h> 38 39 #include <macros.h> … … 107 108 xflags_t *xflags) 108 109 { 110 size_t xfer_size; 111 109 112 log_msg(LVL_DEBUG, "tcp_uc_receive()"); 113 114 fibril_mutex_lock(&conn->rcv_buf_lock); 115 116 /* Wait for data to become available */ 117 while (conn->rcv_buf_used == 0) { 118 log_msg(LVL_DEBUG, "tcp_uc_receive() - wait for data"); 119 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->rcv_buf_lock); 120 } 121 122 /* Copy data from receive buffer to user buffer */ 123 xfer_size = min(size, conn->rcv_buf_used); 124 memcpy(buf, conn->rcv_buf, xfer_size); 125 *rcvd = xfer_size; 126 127 /* Remove data from receive buffer */ 128 memmove(conn->rcv_buf, conn->rcv_buf + xfer_size, conn->rcv_buf_used - 129 xfer_size); 130 conn->rcv_buf_used -= xfer_size; 131 conn->rcv_wnd += xfer_size; 132 133 fibril_mutex_unlock(&conn->rcv_buf_lock); 134 135 /* TODO */ 136 *xflags = 0; 137 138 /* Send new size of receive window */ 139 tcp_tqueue_ctrl_seg(conn, CTL_ACK); 140 141 log_msg(LVL_DEBUG, "tcp_uc_receive() - returning %zu bytes", 142 xfer_size); 110 143 } 111 144 -
uspace/srv/net/tl/tcp/tcp_type.h
r32105348 rd9ce049 37 37 38 38 #include <adt/list.h> 39 #include <fibril_synch.h> 39 40 #include <sys/types.h> 40 41 … … 114 115 size_t rcv_buf_size; 115 116 size_t rcv_buf_used; 117 fibril_mutex_t rcv_buf_lock; 118 fibril_condvar_t rcv_buf_cv; 116 119 117 120 /** Send buffer */ -
uspace/srv/net/tl/tcp/test.c
r32105348 rd9ce049 45 45 #include "test.h" 46 46 47 #define RCV_BUF_SIZE 64 48 47 49 static void test_srv(void *arg) 48 50 { 49 51 tcp_conn_t *conn; 50 52 tcp_sock_t sock; 53 char rcv_buf[RCV_BUF_SIZE + 1]; 54 size_t rcvd; 55 xflags_t xflags; 51 56 52 57 printf("test_srv()\n"); … … 54 59 sock.addr.ipv4 = 0x7f000001; 55 60 tcp_uc_open(80, &sock, ap_passive, &conn); 61 62 while (true) { 63 printf("User receive...\n"); 64 tcp_uc_receive(conn, rcv_buf, RCV_BUF_SIZE, &rcvd, &xflags); 65 rcv_buf[rcvd] = '\0'; 66 printf("User received %zu bytes '%s'.\n", rcvd, rcv_buf); 67 68 async_usleep(1000*1000*2); 69 } 56 70 } 57 71 -
uspace/srv/net/tl/tcp/tqueue.c
r32105348 rd9ce049 72 72 seg->wnd = conn->rcv_wnd; 73 73 74 log_msg(LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32, 75 seg->seq, seg->wnd); 76 74 77 if ((seg->ctrl & CTL_ACK) != 0) 75 78 seg->ack = conn->rcv_nxt; … … 88 91 void tcp_tqueue_new_data(tcp_conn_t *conn) 89 92 { 93 size_t avail_wnd; 90 94 size_t data_size; 91 95 tcp_segment_t *seg; … … 93 97 log_msg(LVL_DEBUG, "tcp_tqueue_new_data()"); 94 98 95 data_size = min(conn->snd_buf_used, conn->snd_wnd); 99 /* Number of free sequence numbers in send window */ 100 avail_wnd = (conn->snd_una + conn->snd_wnd) - conn->snd_nxt; 101 102 data_size = min(conn->snd_buf_used, avail_wnd); 96 103 log_msg(LVL_DEBUG, "conn->snd_buf_used = %zu, SND.WND = %zu, " 97 104 "data_size = %zu", conn->snd_buf_used, conn->snd_wnd, data_size); … … 116 123 } 117 124 118 /** Remove ACKed segments from retransmission queue. 125 /** Remove ACKed segments from retransmission queue and possibly transmit 126 * more data. 119 127 * 120 128 * This should be called when SND.UNA is updated due to incoming ACK. 121 129 */ 122 void tcp_tqueue_ remove_acked(tcp_conn_t *conn)130 void tcp_tqueue_ack_received(tcp_conn_t *conn) 123 131 { 124 132 (void) conn; 133 134 tcp_tqueue_new_data(conn); 125 135 } 126 136 -
uspace/srv/net/tl/tcp/tqueue.h
r32105348 rd9ce049 42 42 extern void tcp_tqueue_seg(tcp_conn_t *, tcp_segment_t *); 43 43 extern void tcp_tqueue_new_data(tcp_conn_t *); 44 extern void tcp_tqueue_ remove_acked(tcp_conn_t *);44 extern void tcp_tqueue_ack_received(tcp_conn_t *); 45 45 extern void tcp_transmit_segment(tcp_sockpair_t *, tcp_segment_t *); 46 46 extern void tcp_header_setup(tcp_conn_t *, tcp_segment_t *, tcp_header_t *);
Note:
See TracChangeset
for help on using the changeset viewer.