Skip to content

Commit 832cee6

Browse files
committed
Do something about time outs.
1 parent 05a2e67 commit 832cee6

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

src/ncp.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ struct
8686
int listen;
8787
struct { int link, size; uint32_t lsock, rsock; } rcv, snd;
8888
void (*rrp_callback) (int);
89+
void (*rrp_timeout) (int);
8990
void (*rfnm_callback) (int);
91+
void (*rfnm_timeout) (int);
9092
} connection[CONNECTIONS];
9193

9294
struct
@@ -126,9 +128,10 @@ static const char *type_name[] =
126128
static uint8_t packet[200];
127129
static uint8_t app[200];
128130

129-
static void when_rrp (int i, void (*cb) (int))
131+
static void when_rrp (int i, void (*cb) (int), void (*to) (int))
130132
{
131133
connection[i].rrp_callback = cb;
134+
connection[i].rrp_timeout = to;
132135
}
133136

134137
static void check_rrp (int host)
@@ -146,9 +149,10 @@ static void check_rrp (int host)
146149
}
147150
}
148151

149-
static void when_rfnm (int i, void (*cb) (int))
152+
static void when_rfnm (int i, void (*cb) (int), void (*to) (int))
150153
{
151154
connection[i].rfnm_callback = cb;
155+
connection[i].rfnm_timeout = to;
152156
}
153157

154158
static void check_rfnm (int host)
@@ -724,6 +728,20 @@ static int process_cls (uint8_t source, uint8_t *data)
724728
return 8;
725729
}
726730

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+
727745
static void send_rts (int i)
728746
{
729747
if (connection[i].flags & CONN_SENT_RTS)
@@ -746,7 +764,7 @@ static void send_str_and_rts (int i)
746764
connection[i].snd.rsock, connection[i].snd.size);
747765
connection[i].flags |= CONN_SENT_STR;
748766
}
749-
when_rfnm (i, send_rts);
767+
when_rfnm (i, send_rts, cls_and_drop);
750768
check_rfnm (connection[i].host);
751769
}
752770

@@ -807,8 +825,8 @@ static int process_all (uint8_t source, uint8_t *data)
807825
fprintf (stderr, "NCP: New connection %d.\n", j);
808826
connection[j].snd.size = 8;
809827
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);
812830
check_rfnm (source);
813831
}
814832
return 7;
@@ -1044,7 +1062,7 @@ static void process_regular (uint8_t *packet, int length)
10441062
if (connection[i].flags & CONN_CLIENT) {
10451063
uint32_t s = sock (&packet[9]);
10461064
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);
10481066
connection[i].snd.rsock = s;
10491067

10501068
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)
10571075
connection[j].snd.size = 8;
10581076
connection[j].rcv.link = 45;
10591077
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);
10611079
}
10621080
connection[j].listen = connection[i].rcv.rsock;
10631081
connection[j].flags |= CONN_GOT_SOCKET;
@@ -1261,6 +1279,11 @@ static void app_open_send_rts (int i)
12611279
connection[i].rcv.rsock, connection[i].rcv.link);
12621280
}
12631281

1282+
static void app_open_fail (int i)
1283+
{
1284+
reply_open (connection[i].host, connection[i].rcv.rsock, 255);
1285+
}
1286+
12641287
static void app_open (void)
12651288
{
12661289
uint32_t socket;
@@ -1282,7 +1305,7 @@ static void app_open (void)
12821305
// We haven't communicated with this host yet.
12831306
ncp_rst (host);
12841307
// 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);
12861309
} else {
12871310
// Ok to send RTS directly.
12881311
app_open_send_rts (i);

0 commit comments

Comments
 (0)