better error checking

This commit is contained in:
Kelvin Sherlock 2019-07-08 21:22:03 -04:00
parent c2ec1d02b0
commit c8668f8d95
1 changed files with 28 additions and 16 deletions

44
nda.c
View File

@ -84,6 +84,7 @@ enum {
st_define2, st_define2,
st_define3, st_define3,
st_quit, st_quit,
st_force_quit,
st_disconnect, st_disconnect,
}; };
@ -178,13 +179,13 @@ void TCPLoop(void) {
switch (st) { switch (st) {
case st_idle: case st_idle:
if (GetTick() >= qtick) { if (GetTick() < qtick) break;
TCPIPWriteTCP(ipid, "QUIT\r\n", 6, 1, 0); case st_force_quit:
qtick = GetTick() + 60 * 30; TCPIPWriteTCP(ipid, "QUIT\r\n", 6, 1, 0);
st = st_quit; qtick = GetTick() + 60 * 30;
return; st = st_quit;
} return;
break; break;
case st_connect: case st_connect:
x = ConnectionPoll(&connection); x = ConnectionPoll(&connection);
@ -281,8 +282,10 @@ redo:
if (status == 220) { if (status == 220) {
++st; ++st;
terr = TCPIPWriteTCP(ipid, "CLIENT dict-nda-iigs\r\n", 22, 1, 0); terr = TCPIPWriteTCP(ipid, "CLIENT dict-nda-iigs\r\n", 22, 1, 0);
} else {
MarinettiCallback("\pLogin Error");
st = st_force_quit;
} }
/* else error... */
break; break;
case st_client: case st_client:
/* expect 250 status */ /* expect 250 status */
@ -290,14 +293,19 @@ redo:
++st; ++st;
/* send define string... */ /* send define string... */
define(ipid, NULL); define(ipid, NULL);
} else {
MarinettiCallback("\pClient Error");
AppendText(4, TBRed);
AppendText(rlr.rlrBuffCount, buffer);
SetText();
st = st_force_quit;
} }
/* else error */
break; break;
case st_define1: case st_define1:
/* expect 550, 552, or 150 status */ /* expect 550, 552, or 150 status */
if (status == 150) { if (status == 150) {
++st; ++st;
AppendText(4, TBBlack); MarinettiCallback("\pReceiving...");
break; break;
} }
@ -305,6 +313,7 @@ redo:
MarinettiCallback("\pNo match"); MarinettiCallback("\pNo match");
st = st_idle; st = st_idle;
} else { } else {
MarinettiCallback("\pServer Error");
AppendText(4, TBRed); AppendText(4, TBRed);
AppendText(rlr.rlrBuffCount, buffer); AppendText(rlr.rlrBuffCount, buffer);
SetText(); SetText();
@ -315,14 +324,20 @@ redo:
break; break;
case st_define2: case st_define2:
/* expect 151 */ /* expect 151 */
if (status == 151) if (status == 151) {
++st; ++st;
else if (status == 250) { } else if (status == 250) {
st = st_idle; st = st_idle;
qtick = GetTick() + 60 * 60 * 2; /* 2-minute timeout */ qtick = GetTick() + 60 * 60 * 2; /* 2-minute timeout */
SetText(); SetText();
EnableControls(); EnableControls();
MarinettiCallback("\pConnected");
} else { } else {
MarinettiCallback("\pServer Error");
AppendText(4, TBRed);
AppendText(rlr.rlrBuffCount, buffer);
SetText();
st = st_idle;
} }
break; break;
case st_define3: case st_define3:
@ -348,12 +363,9 @@ redo:
// activate/inactivate controls based on Marinetti status // activate/inactivate controls based on Marinetti status
void UpdateStatus(Boolean redraw) { void UpdateStatus(Boolean redraw) {
if (FlagTCP) // TCP started if (FlagTCP) {
{
SetInfoRefCon((LongWord) "\pNetwork Connected", MyWindow); SetInfoRefCon((LongWord) "\pNetwork Connected", MyWindow);
} else { } else {
SetInfoRefCon((LongWord) "\pNetwork Disconnected", MyWindow); SetInfoRefCon((LongWord) "\pNetwork Disconnected", MyWindow);
} }
if (redraw) if (redraw)