Changeset 0093ab6 in mainline for uspace/srv/net/tl/tcp/conn.c
- Timestamp:
- 2011-09-21T19:56:41Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 032bbe7
- Parents:
- 4c55a64
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/conn.c
r4c55a64 r0093ab6 38 38 #include <errno.h> 39 39 #include <io/log.h> 40 #include <macros.h> 40 41 #include <stdlib.h> 41 42 #include "conn.h" … … 46 47 #include "tqueue.h" 47 48 49 #define RCV_BUF_SIZE 4096 50 48 51 LIST_INITIALIZE(conn_list); 49 52 … … 54 57 tcp_conn_t *conn; 55 58 59 /* Allocate connection structure */ 56 60 conn = calloc(1, sizeof(tcp_conn_t)); 57 61 if (conn == NULL) 58 62 return NULL; 59 63 64 /* Allocate receive buffer */ 65 conn->rcv_buf_size = RCV_BUF_SIZE; 66 conn->rcv_buf_used = 0; 67 conn->rcv_buf = calloc(1, conn->rcv_buf_size); 68 if (conn->rcv_buf == NULL) { 69 free(conn); 70 return NULL; 71 } 72 73 /* Set up receive window. */ 74 conn->rcv_wnd = conn->rcv_buf_size; 75 76 /* Initialize incoming segment queue */ 60 77 tcp_iqueue_init(&conn->incoming, conn); 61 78 … … 175 192 176 193 tcp_tqueue_ctrl_seg(conn, CTL_SYN | CTL_ACK /* XXX */); 194 195 tcp_segment_delete(seg); 177 196 } 178 197 … … 225 244 tcp_tqueue_ctrl_seg(conn, CTL_SYN | CTL_ACK /* XXX */); 226 245 } 246 247 tcp_segment_delete(seg); 227 248 } 228 249 … … 288 309 static cproc_t tcp_conn_seg_proc_ack_est(tcp_conn_t *conn, tcp_segment_t *seg) 289 310 { 311 log_msg(LVL_DEBUG, "tcp_conn_seg_proc_ack_est(%p, %p)", conn, seg); 312 313 log_msg(LVL_DEBUG, "SEG.ACK=%u, SND.UNA=%u, SND.NXT=%u", 314 (unsigned)seg->ack, (unsigned)conn->snd_una, 315 (unsigned)conn->snd_nxt); 316 290 317 if (!seq_no_ack_acceptable(conn, seg->ack)) { 318 log_msg(LVL_DEBUG, "ACK not acceptable."); 291 319 if (!seq_no_ack_duplicate(conn, seg->ack)) { 320 log_msg(LVL_WARN, "Not acceptable, not duplicate. " 321 "Send ACK and drop."); 292 322 /* Not acceptable, not duplicate. Send ACK and drop. */ 293 323 tcp_tqueue_ctrl_seg(conn, CTL_ACK); 294 324 tcp_segment_delete(seg); 295 325 return cp_done; 326 } else { 327 log_msg(LVL_DEBUG, "Ignoring duplicate ACK."); 296 328 } 297 329 } else { … … 401 433 } 402 434 435 /** Process segment text. */ 403 436 static cproc_t tcp_conn_seg_proc_text(tcp_conn_t *conn, tcp_segment_t *seg) 404 437 { 438 size_t text_size; 439 size_t xfer_size; 440 441 log_msg(LVL_DEBUG, "tcp_conn_seg_proc_text(%p, %p)", conn, seg); 442 405 443 switch (conn->cstate) { 406 444 case st_established: … … 422 460 } 423 461 424 /* TODO Process segment text */ 462 /* 463 * Process segment text 464 */ 465 assert(seq_no_segment_ready(conn, seg)); 466 467 /* Trim anything outside our receive window */ 468 tcp_conn_trim_seg_to_wnd(conn, seg); 469 470 /* Determine how many bytes to copy */ 471 text_size = tcp_segment_text_size(seg); 472 xfer_size = min(text_size, conn->rcv_buf_size - conn->rcv_buf_used); 473 474 /* Copy data to receive buffer */ 475 tcp_segment_text_copy(seg, conn->rcv_buf, xfer_size); 476 477 /* Advance RCV.NXT */ 478 conn->rcv_nxt += xfer_size; 479 480 /* Update receive window. XXX Not an efficient strategy. */ 481 conn->rcv_wnd -= xfer_size; 482 483 /* XXX Signal user that some data arrived. */ 484 485 /* Send ACK */ 486 if (xfer_size > 0) 487 tcp_tqueue_ctrl_seg(conn, CTL_ACK); 488 489 /* Anything left in the segment? (text, FIN) */ 490 if (xfer_size < seg->len) { 491 /* 492 * Some text or control remains. Insert remainder back 493 * into the incoming queue. 494 */ 495 tcp_conn_trim_seg_to_wnd(conn, seg); 496 tcp_iqueue_insert_seg(&conn->incoming, seg); 497 498 return cp_done; 499 } 500 425 501 return cp_continue; 426 502 } … … 472 548 if (tcp_conn_seg_proc_fin(conn, seg) == cp_done) 473 549 return; 550 551 tcp_segment_delete(seg); 474 552 } 475 553 … … 498 576 } 499 577 578 void tcp_conn_trim_seg_to_wnd(tcp_conn_t *conn, tcp_segment_t *seg) 579 { 580 uint32_t left, right; 581 582 seq_no_seg_trim_calc(conn, seg, &left, &right); 583 tcp_segment_trim(seg, left, right); 584 } 585 500 586 void tcp_unexpected_segment(tcp_sockpair_t *sp, tcp_segment_t *seg) 501 587 {
Note:
See TracChangeset
for help on using the changeset viewer.