?? tcp.lst
字號:
422 3 // Since timestamps are optional and we do not use
423 3 // them, do not have to send them
424 3 // After sending the SYN ACK the client browser will
425 3 // blast me with 2 messages, an ACK, and a HTTP GET
426 3 tcp_send(FLG_SYN | FLG_ACK, 28, nr);
427 3
C51 COMPILER V7.06 TCP 10/09/2006 21:51:55 PAGE 8
428 3 // My SYN flag increments my sequence number
429 3 // My sequence number is always updated to point to
430 3 // the next byte to be sent. So the incoming ack
431 3 // number should equal my sequence number
432 3 conxn[nr].my_sequence++;
433 3
434 3 conxn[nr].state = STATE_SYN_RCVD;
435 3
436 3 }
437 2 else
438 2 {
439 3 // Sender is out of sync so send reset
440 3 conxn[nr].ipaddr = 0;
441 3 tcp_send(FLG_RST, 20, NO_CONNECTION);
442 3 }
443 2 break;
444 2
445 2
446 2 case STATE_SYN_RCVD:
447 2 // He may already be sending me data - should process it
448 2 conxn[nr].his_sequence += data_len;
449 2 conxn[nr].his_ack = tcp->ack_number;
450 2
451 2 if (tcp->flags & FLG_FIN)
452 2 {
453 3 // His FIN counts as a byte of data
454 3 conxn[nr].his_sequence++;
455 3 tcp_send(FLG_ACK, 20, nr);
456 3 conxn[nr].state = STATE_CLOSE_WAIT;
457 3
458 3
459 3 // At this point we would normally wait for the application
460 3 // to close. For now, send FIN right away.
461 3 tcp_send(FLG_FIN | FLG_ACK, 20, nr);
462 3 conxn[nr].my_sequence++; // For my FIN
463 3 conxn[nr].state = STATE_LAST_ACK;
464 3
465 3 }
466 2
467 2 // Make sure he is ACKing my SYN
468 2 else if (tcp->ack_number == conxn[nr].my_sequence)
469 2 {
470 3 conxn[nr].state = STATE_ESTABLISHED;
471 3 // If sender sent data ignore it and he will resend
472 3 // Do not send response because we received no
473 3 // data... wait for client to send something to me
474 3 }
475 2 break;
476 2
477 2
478 2 case STATE_ESTABLISHED:
479 2 conxn[nr].his_ack = tcp->ack_number;
480 2
481 2 if (tcp->flags & FLG_FIN)
482 2 {
483 3 // His FIN counts as a byte of data
484 3 conxn[nr].his_sequence++;
485 3 tcp_send(FLG_ACK, 20, nr);
486 3 conxn[nr].state = STATE_CLOSE_WAIT;
487 3
488 3
489 3 // At this point we would normally wait for the application
C51 COMPILER V7.06 TCP 10/09/2006 21:51:55 PAGE 9
490 3 // to close. For now, send FIN immediately.
491 3 tcp_send(FLG_FIN | FLG_ACK, 20, nr);
492 3 conxn[nr].my_sequence++; // For my FIN
493 3 conxn[nr].state = STATE_LAST_ACK;
494 3
495 3 }
496 2 else if (data_len != 0)
497 2 {
498 3 // Received normal TCP segment from sender with data
499 3 // Send an ACK immediately and pass the data on to
500 3 // the application
501 3 conxn[nr].his_sequence += data_len;
502 3 tcp_send(FLG_ACK, 20, nr); // Send ACK
503 3
504 3
505 3 // Send pointer to start of TCP payload
506 3 // http_server increments my sequence number when
507 3 // sending so don't worry about it here
508 3 result = http_server(inbuf, header_len, nr, 0);
509 3
510 3 // Start timer to close conxn if no activity
511 3 conxn[nr].inactivity = INACTIVITY_TIME;
512 3 }
513 2 break;
514 2
515 2
516 2 case STATE_CLOSE_WAIT:
517 2 // With this code, should not get here
518 2
519 2 break;
520 2
521 2
522 2 case STATE_LAST_ACK:
523 2 conxn[nr].his_ack = tcp->ack_number;
524 2
525 2 // If he ACK's my FIN then close
526 2 if (tcp->ack_number == conxn[nr].my_sequence)
527 2 {
528 3 conxn[nr].state = STATE_CLOSED;
529 3 conxn[nr].ipaddr = 0; // Free up struct area
530 3 }
531 2 break;
532 2
533 2
534 2 case STATE_FIN_WAIT_1:
535 2 // He may still be sending me data - should process it
536 2 conxn[nr].his_sequence += data_len;
537 2 conxn[nr].his_ack = tcp->ack_number;
538 2
539 2 if (tcp->flags & FLG_FIN)
540 2 {
541 3 // His FIN counts as a byte of data
542 3 conxn[nr].his_sequence++;
543 3 tcp_send(FLG_ACK, 20, nr);
544 3
545 3 // If he has ACK'd my FIN then we can close connection
546 3 if (tcp->ack_number == conxn[nr].my_sequence)
547 3 {
548 4 conxn[nr].state = STATE_TIME_WAIT;
549 4
550 4 conxn[nr].state = STATE_CLOSED;
551 4 conxn[nr].ipaddr = 0; // Free up connection
C51 COMPILER V7.06 TCP 10/09/2006 21:51:55 PAGE 10
552 4
553 4 }
554 3 else
555 3 {
556 4 // He has not ACK'd my FIN. This happens when there is a simultaneous
557 4 // close - I got his FIN but he has not yet ACK'd my FIN
558 4 conxn[nr].state = STATE_CLOSING;
559 4
560 4 }
561 3 }
562 2 else if (tcp->ack_number == conxn[nr].my_sequence)
563 2 {
564 3 // He has ACK'd my FIN but has not sent a FIN yet himself
565 3 conxn[nr].state = STATE_FIN_WAIT_2;
566 3
567 3 }
568 2 break;
569 2
570 2
571 2 case STATE_FIN_WAIT_2:
572 2 // He may still be sending me data - should process it
573 2 conxn[nr].his_sequence += data_len;
574 2 conxn[nr].his_ack = tcp->ack_number;
575 2
576 2 if (tcp->flags & FLG_FIN)
577 2 {
578 3 conxn[nr].his_sequence++; // For his FIN flag
579 3 tcp_send(FLG_ACK, 20, nr);
580 3 conxn[nr].state = STATE_TIME_WAIT;
581 3 conxn[nr].state = STATE_CLOSED;
582 3 conxn[nr].ipaddr = 0; // Free up struct area
583 3 }
584 2 break;
585 2
586 2
587 2 case STATE_TIME_WAIT:
588 2 // With this code, should not get here
589 2 break;
590 2
591 2
592 2 case STATE_CLOSING:
593 2 // Simultaneous close has happened. I have received his FIN
594 2 // but he has not yet ACK'd my FIN. Waiting for ACK.
595 2 // Will not receive data in this state
596 2 conxn[nr].his_ack = tcp->ack_number;
597 2
598 2 if (tcp->ack_number == conxn[nr].my_sequence)
599 2 {
600 3 conxn[nr].state = STATE_TIME_WAIT;
601 3
602 3 // Do not send any response to his ACK
603 3 conxn[nr].state = STATE_CLOSED;
604 3 conxn[nr].ipaddr = 0; // Free up struct area
605 3
606 3 }
607 2 break;
608 2
609 2
610 2 default:
611 2 break;
612 2 }
613 1
C51 COMPILER V7.06 TCP 10/09/2006 21:51:55 PAGE 11
614 1
615 1
616 1 }
617
618
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 3722 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = 231 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 19
IDATA SIZE = 5 25
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -