📄 tcp.lst
字号:
879
880 return;
881 }
882
883 /* Is there unacked data? */
884
885 if(temp == 0)
886 break;
887
888 /* Is there timeout? */
889
890 if( check_timer(soc->retransmit_timerh) != 0 )
891 break;
892
893 /* De we have retries left */
894
895 if(soc->retries_left == 0) {
896 /* No retries, must reset */
897
898 TCP_DEBUGOUT("Retries used up, resetting\r\n");
899
900 soc->myflags = TCP_FLAG_RESET;
901 tcp_sendcontrol(handle);
902
903 /* Inform application */
904
905 soc->event_listener(handle, TCP_EVENT_ABORT, soc->rem_ip, soc->remport);
906
907 if(soc->type & TCP_TYPE_SERVER )
908 tcp_newstate(soc, TCP_STATE_LISTENING);
909 else
910 tcp_newstate(soc, TCP_STATE_CLOSED);
C51 COMPILER V7.06 TCP 11/26/2004 11:32:45 PAGE 16
911
912 handle++;
913
914 return;
915 }
916
917 soc->retries_left--;
918 init_timer(soc->retransmit_timerh, TCP_DEF_RETRY_TOUT*TIMERTIC);
919
920 /* Yep, there is unacked data */
921 /* Application should send the old data */
922
923 if(temp>soc->send_mtu)
924 temp = soc->send_mtu;
925
926 /* Rewind Send Next because the send process will adjust it */
927 /* So cheat the tcp_send to think there is no unacked data */
928
929 soc->send_next = soc->send_unacked;
930
931 /* tcp_send will set the retiries_left to maximum but this is */
932 /* retransmitting already so we need to retain it in order to */
933 /* avoid dead-lock */
934
935 old_retries = soc->retries_left;
936
937 temp = soc->event_listener(handle, TCP_EVENT_REGENERATE, (UINT32)temp, 0);
938
939 soc->retries_left = old_retries;
940
941 if(temp <= 0) {
942
943 /* No data by application, must be something wrong */
944 soc->myflags = TCP_FLAG_RESET;
945 tcp_sendcontrol(handle);
946
947 /* Inform application */
948
949 soc->event_listener(handle, TCP_EVENT_ABORT, soc->rem_ip, soc->remport);
950
951 if(soc->type & TCP_TYPE_SERVER )
952 tcp_newstate(soc, TCP_STATE_LISTENING);
953 else
954 tcp_newstate(soc, TCP_STATE_CLOSED);
955
956 handle++;
957
958 return;
959
960 }
961
962 /* Application has send data */
963
964 handle++;
965
966 return;
967
968
969 case TCP_STATE_SYN_SENT:
970 case TCP_STATE_SYN_RECEIVED:
971
972 /* Is there timeout? */
C51 COMPILER V7.06 TCP 11/26/2004 11:32:45 PAGE 17
973 if( check_timer(soc->retransmit_timerh) != 0 )
974 break;
975
976 TCP_DEBUGOUT("Timeout\r\n");
977
978 /* Yep, timeout. Is there reties left? */
979 if( soc->retries_left ) {
980 soc->retries_left--;
981 init_timer(soc->retransmit_timerh, TCP_DEF_RETRY_TOUT*TIMERTIC);
982 tcp_sendcontrol(handle);
983
984 handle++;
985
986 return;
987 } else {
988 /* Retries used up */
989 TCP_DEBUGOUT("Retries used up, resetting\r\n");
990
991 if(soc->type & TCP_TYPE_SERVER )
992 tcp_newstate(soc, TCP_STATE_LISTENING);
993 else
994 tcp_newstate(soc, TCP_STATE_CLOSED);
995
996 soc->myflags = TCP_FLAG_RESET;
997 tcp_sendcontrol(handle);
998
999 /* Inform application */
1000
1001 soc->event_listener(handle, TCP_EVENT_ABORT, soc->rem_ip, soc->remport);
1002
1003 handle++;
1004
1005 return;
1006 }
1007
1008 break;
1009
1010 case TCP_STATE_TIMED_WAIT:
1011
1012 /* Is there timeout? */
1013
1014 if( check_timer(soc->retransmit_timerh) != 0 )
1015 break;
1016
1017 TCP_DEBUGOUT("Timeout\r\n");
1018
1019 if(soc->retries_left) {
1020 soc->retries_left--;
1021 init_timer(soc->retransmit_timerh, TCP_DEF_RETRY_TOUT*TIMERTIC);
1022 break;
1023 }
1024
1025 if(soc->type & TCP_TYPE_SERVER )
1026 tcp_newstate(soc, TCP_STATE_LISTENING);
1027 else
1028 tcp_newstate(soc, TCP_STATE_CLOSED);
1029
1030 break;
1031
1032 case TCP_STATE_LAST_ACK:
1033 case TCP_STATE_FINW1:
1034 case TCP_STATE_CLOSING:
C51 COMPILER V7.06 TCP 11/26/2004 11:32:45 PAGE 18
1035
1036 /* Is there timeout? */
1037
1038 if( check_timer(soc->retransmit_timerh) != 0 )
1039 break;
1040
1041 TCP_DEBUGOUT("Timeout\r\n");
1042
1043 /* Yep, timeout. Is there reties left? */
1044
1045 if( soc->retries_left ) {
1046 soc->retries_left--;
1047 init_timer(soc->retransmit_timerh, TCP_DEF_RETRY_TOUT*TIMERTIC);
1048 soc->myflags = TCP_FLAG_FIN | TCP_FLAG_ACK;
1049 tcp_sendcontrol(handle);
1050
1051 handle++;
1052
1053
1054 return;
1055 } else {
1056 /* Retries used up */
1057 TCP_DEBUGOUT("Retries used up, resetting\r\n");
1058
1059 if(soc->type & TCP_TYPE_SERVER )
1060 tcp_newstate(soc, TCP_STATE_LISTENING);
1061 else
1062 tcp_newstate(soc, TCP_STATE_CLOSED);
1063
1064 soc->myflags = TCP_FLAG_RESET;
1065 tcp_sendcontrol(handle);
1066
1067 /* Inform application */
1068
1069 soc->event_listener(handle, TCP_EVENT_ABORT, soc->rem_ip, soc->remport);
1070
1071 handle++;
1072
1073 return;
1074 }
1075
1076 break;
1077
1078 case TCP_STATE_FINW2:
1079
1080 /* Is there timeout? */
1081
1082 if( check_timer(soc->retransmit_timerh) != 0 )
1083 break;
1084
1085 TCP_DEBUGOUT("Timeout\r\n");
1086
1087 /* Yep, timeout. Is there reties left? */
1088
1089 if( soc->retries_left ) {
1090 /* Still keep waiting for FIN */
1091
1092 soc->retries_left--;
1093 init_timer(soc->retransmit_timerh, TCP_DEF_RETRY_TOUT*TIMERTIC);
1094 break;
1095 } else {
1096 /* Retries used up */
C51 COMPILER V7.06 TCP 11/26/2004 11:32:45 PAGE 19
1097 TCP_DEBUGOUT("Retries used up, resetting\r\n");
1098
1099 if(soc->type & TCP_TYPE_SERVER )
1100 tcp_newstate(soc, TCP_STATE_LISTENING);
1101
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -