86
86
int listen ;
87
87
struct { int link , size ; uint32_t lsock , rsock ; } rcv , snd ;
88
88
void (* rrp_callback ) (int );
89
+ void (* rrp_timeout ) (int );
89
90
void (* rfnm_callback ) (int );
91
+ void (* rfnm_timeout ) (int );
90
92
} connection [CONNECTIONS ];
91
93
92
94
struct
@@ -126,9 +128,10 @@ static const char *type_name[] =
126
128
static uint8_t packet [200 ];
127
129
static uint8_t app [200 ];
128
130
129
- static void when_rrp (int i , void (* cb ) (int ))
131
+ static void when_rrp (int i , void (* cb ) (int ), void ( * to ) ( int ) )
130
132
{
131
133
connection [i ].rrp_callback = cb ;
134
+ connection [i ].rrp_timeout = to ;
132
135
}
133
136
134
137
static void check_rrp (int host )
@@ -146,9 +149,10 @@ static void check_rrp (int host)
146
149
}
147
150
}
148
151
149
- static void when_rfnm (int i , void (* cb ) (int ))
152
+ static void when_rfnm (int i , void (* cb ) (int ), void ( * to ) ( int ) )
150
153
{
151
154
connection [i ].rfnm_callback = cb ;
155
+ connection [i ].rfnm_timeout = to ;
152
156
}
153
157
154
158
static void check_rfnm (int host )
@@ -724,6 +728,20 @@ static int process_cls (uint8_t source, uint8_t *data)
724
728
return 8 ;
725
729
}
726
730
731
+ static void just_drop (int i )
732
+ {
733
+ destroy (i );
734
+ }
735
+
736
+ static void cls_and_drop (int i )
737
+ {
738
+ fprintf (stderr , "NCP: Timeout, drop connection %d.\n" , i );
739
+ ncp_cls (connection [i ].host ,
740
+ connection [i ].snd .lsock , connection [i ].snd .rsock );
741
+ ncp_cls (connection [i ].host ,
742
+ connection [i ].rcv .lsock , connection [i ].rcv .rsock );
743
+ }
744
+
727
745
static void send_rts (int i )
728
746
{
729
747
if (connection [i ].flags & CONN_SENT_RTS )
@@ -746,7 +764,7 @@ static void send_str_and_rts (int i)
746
764
connection [i ].snd .rsock , connection [i ].snd .size );
747
765
connection [i ].flags |= CONN_SENT_STR ;
748
766
}
749
- when_rfnm (i , send_rts );
767
+ when_rfnm (i , send_rts , cls_and_drop );
750
768
check_rfnm (connection [i ].host );
751
769
}
752
770
@@ -807,8 +825,8 @@ static int process_all (uint8_t source, uint8_t *data)
807
825
fprintf (stderr , "NCP: New connection %d.\n" , j );
808
826
connection [j ].snd .size = 8 ;
809
827
connection [j ].rcv .link = 44 ;
810
- when_rfnm (j , send_str_and_rts );
811
- when_rfnm (i , send_cls_snd );
828
+ when_rfnm (j , send_str_and_rts , cls_and_drop );
829
+ when_rfnm (i , send_cls_snd , just_drop );
812
830
check_rfnm (source );
813
831
}
814
832
return 7 ;
@@ -1044,7 +1062,7 @@ static void process_regular (uint8_t *packet, int length)
1044
1062
if (connection [i ].flags & CONN_CLIENT ) {
1045
1063
uint32_t s = sock (& packet [9 ]);
1046
1064
fprintf (stderr , "NCP: ICP link %u socket %u.\n" , link , s );
1047
- when_rfnm (i , send_cls_rcv );
1065
+ when_rfnm (i , send_cls_rcv , just_drop );
1048
1066
connection [i ].snd .rsock = s ;
1049
1067
1050
1068
j = find_rcv_sockets (source , connection [i ].rcv .lsock + 2 , s + 1 );
@@ -1057,7 +1075,7 @@ static void process_regular (uint8_t *packet, int length)
1057
1075
connection [j ].snd .size = 8 ;
1058
1076
connection [j ].rcv .link = 45 ;
1059
1077
fprintf (stderr , "NCP: New connection %d.\n" , j );
1060
- when_rfnm (j , send_str_and_rts );
1078
+ when_rfnm (j , send_str_and_rts , cls_and_drop );
1061
1079
}
1062
1080
connection [j ].listen = connection [i ].rcv .rsock ;
1063
1081
connection [j ].flags |= CONN_GOT_SOCKET ;
@@ -1261,6 +1279,11 @@ static void app_open_send_rts (int i)
1261
1279
connection [i ].rcv .rsock , connection [i ].rcv .link );
1262
1280
}
1263
1281
1282
+ static void app_open_fail (int i )
1283
+ {
1284
+ reply_open (connection [i ].host , connection [i ].rcv .rsock , 255 );
1285
+ }
1286
+
1264
1287
static void app_open (void )
1265
1288
{
1266
1289
uint32_t socket ;
@@ -1282,7 +1305,7 @@ static void app_open (void)
1282
1305
// We haven't communicated with this host yet.
1283
1306
ncp_rst (host );
1284
1307
// Wait for RRP, then send RTS.
1285
- when_rrp (i , app_open_send_rts );
1308
+ when_rrp (i , app_open_send_rts , app_open_fail );
1286
1309
} else {
1287
1310
// Ok to send RTS directly.
1288
1311
app_open_send_rts (i );
0 commit comments