Fixed zmodem timeout bug

This commit is contained in:
Michiel Broek 2003-09-17 19:33:34 +00:00
parent e5de4ddfa7
commit 9eadf0b143
6 changed files with 174 additions and 36 deletions

View File

@ -10,6 +10,14 @@ v0.37.8 14-Sep-2003
general: general:
This version is issued to prepare for a stable release. This version is issued to prepare for a stable release.
common.a:
Added a set of general purpose timers.
mbcico:
Session handshake and EMSI handshake use the general purpose
timers instead of the ttyio timers. This should prevent invalid
timeouts during zmodem transfers. (bug since 0.37.6).
v0.37.7 09-Sep-2003 - 14-09-2003 v0.37.7 09-Sep-2003 - 14-09-2003

View File

@ -11,12 +11,12 @@ COMMON_SRCS = attach.c falists.c hdr.c parsedate.c rfcmsg.c unpacker.c \
batchrd.c ftn.c pktname.c mangle.c sectest.c proglock.c \ batchrd.c ftn.c pktname.c mangle.c sectest.c proglock.c \
dostran.c ftnmsg.c mbfile.c nodelock.c rawio.c strcasestr.c \ dostran.c ftnmsg.c mbfile.c nodelock.c rawio.c strcasestr.c \
execute.c expipe.c getheader.c noderecord.c rfcaddr.c strutil.c \ execute.c expipe.c getheader.c noderecord.c rfcaddr.c strutil.c \
faddr.c gmtoffset.c packet.c rfcdate.c term.c endian.c faddr.c gmtoffset.c packet.c rfcdate.c term.c endian.c timers.c
COMMON_OBJS = ftscprod.o attach.o falists.o hdr.o parsedate.o rfcmsg.o unpacker.o \ COMMON_OBJS = ftscprod.o attach.o falists.o hdr.o parsedate.o rfcmsg.o unpacker.o \
batchrd.o ftn.o pktname.o mangle.o sectest.o proglock.o \ batchrd.o ftn.o pktname.o mangle.o sectest.o proglock.o \
dostran.o ftnmsg.o mbfile.o nodelock.o rawio.o strcasestr.o \ dostran.o ftnmsg.o mbfile.o nodelock.o rawio.o strcasestr.o \
execute.o expipe.o getheader.o noderecord.o rfcaddr.o strutil.o \ execute.o expipe.o getheader.o noderecord.o rfcaddr.o strutil.o \
faddr.o gmtoffset.o packet.o rfcdate.o term.o endian.o faddr.o gmtoffset.o packet.o rfcdate.o term.o endian.o timers.o
COMMON_HDRS = common.h COMMON_HDRS = common.h
NODELIST_SRCS = nodelist.c NODELIST_SRCS = nodelist.c
NODELIST_OBJS = nodelist.o NODELIST_OBJS = nodelist.o
@ -152,6 +152,7 @@ packet.o: ../config.h libs.h structs.h users.h records.h clcomm.h common.h dbnod
rfcdate.o: ../config.h libs.h structs.h common.h clcomm.h rfcdate.o: ../config.h libs.h structs.h common.h clcomm.h
term.o: ../config.h libs.h structs.h users.h ansi.h records.h common.h term.o: ../config.h libs.h structs.h users.h ansi.h records.h common.h
endian.o: ../config.h libs.h structs.h common.h endian.o: ../config.h libs.h structs.h common.h
timers.o: ../config.h libs.h structs.h clcomm.h common.h
dbcfg.o: ../config.h libs.h mbse.h structs.h users.h records.h mberrors.h dbcfg.h dbcfg.o: ../config.h libs.h mbse.h structs.h users.h records.h mberrors.h dbcfg.h
dbdupe.o: ../config.h libs.h structs.h clcomm.h mberrors.h dbdupe.h dbdupe.o: ../config.h libs.h structs.h clcomm.h mberrors.h dbdupe.h
dbftn.o: ../config.h libs.h structs.h users.h records.h dbcfg.h dbftn.h dbftn.o: ../config.h libs.h structs.h users.h records.h dbcfg.h dbftn.h

View File

@ -434,17 +434,6 @@ char *bgets(char *, int, FILE *);
/*
* some special chars values
*/
// #define NUL 0
// #define NL 10
// #define FF 12
// #define CR 13
// #define ESC 27
/* /*
* parsedate.c * parsedate.c
*/ */
@ -514,5 +503,16 @@ int Le_Access(securityrec, securityrec); /* Endian independant */
int lockprogram(char *); /* Lock a program */ int lockprogram(char *); /* Lock a program */
void ulockprogram(char *); /* Unlock a program */ void ulockprogram(char *); /* Unlock a program */
/*
* timers.c
*/
int gpt_resettimer(int); /* Reset timer no */
void gpt_resettimers(void); /* Reset all timers */
int gpt_settimer(int, int); /* Set timer no to time */
int gpt_expired(int); /* Is timer expired */
int gpt_running(int); /* Is timer running */
#endif #endif

129
lib/timers.c Normal file
View File

@ -0,0 +1,129 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: General Purpose Timers
*
*****************************************************************************
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "libs.h"
#include "structs.h"
#include "clcomm.h"
#include "common.h"
/*
* Number of timers
*/
#define GENTIMERS 3
static time_t gentimer[GENTIMERS];
/*
* Reset a timer
*/
int gpt_resettimer(int tno)
{
if (tno >= GENTIMERS) {
errno = EINVAL;
WriteError("invalid timer number for gpt_resettimer(%d)", tno);
return -1;
}
gentimer[tno] = (time_t) 0;
return 0;
}
void gpt_resettimers(void)
{
int i;
for (i = 0; i < GENTIMERS; i++)
gpt_resettimer(i);
}
/*
* Set timer
*/
int gpt_settimer(int tno, int interval)
{
if (tno >= GENTIMERS) {
errno = EINVAL;
WriteError("invalid timer number for gpt_settimer(%d)", tno);
return -1;
}
gentimer[tno] = time((time_t*)NULL) + interval;
return 0;
}
/*
* Check if timer is expired
*/
int gpt_expired(int tno)
{
time_t now;
if (tno >= GENTIMERS) {
errno = EINVAL;
WriteError("invalid timer number for gpt_expired(%d)", tno);
return -1;
}
/*
* Check if timer is running
*/
if (gentimer[tno] == (time_t) 0)
return 0;
now = time(NULL);
return (now >= gentimer[tno]);
}
int gpt_running(int tno)
{
if (tno >= GENTIMERS) {
errno = EINVAL;
WriteError("invalid timer number for gpt_running(%d)", tno);
return -1;
}
if (gentimer[tno] == (time_t) 0)
return 0;
else
return 1;
}

View File

@ -307,28 +307,28 @@ SM_START(init)
SM_STATE(init) SM_STATE(init)
Syslog('i', "RXEMSI: init"); Syslog('i', "RXEMSI: init");
RESETTIMERS(); gpt_resettimers();
SETTIMER(0, 60); gpt_settimer(0, 60);
SETTIMER(1, 20); gpt_settimer(1, 20);
SM_PROCEED(checkpkt); SM_PROCEED(checkpkt);
SM_STATE(waitpkt) SM_STATE(waitpkt)
Syslog('i', "RXEMSI: waitpkt"); Syslog('i', "RXEMSI: waitpkt");
standby = 0; standby = 0;
SETTIMER(1, 20); gpt_settimer(1, 20);
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
SM_STATE(waitchar) SM_STATE(waitchar)
Syslog('i', "RXEMSI: waitchar, tries=%d", tries); Syslog('i', "RXEMSI: waitchar, tries=%d", tries);
if (EXPIRED(0)) { if (gpt_expired(0)) {
Syslog('+', "EMSI receive 60 seconds timeout"); Syslog('+', "EMSI receive 60 seconds timeout");
SM_ERROR; SM_ERROR;
} }
if (EXPIRED(1)) { if (gpt_expired(1)) {
Syslog('s', "20 sec timeout"); Syslog('s', "20 sec timeout");
SM_PROCEED(sendnak); SM_PROCEED(sendnak);
} }
@ -517,8 +517,8 @@ SM_EDECL
p = buf; p = buf;
memset(&buf, 0, sizeof(buf)); memset(&buf, 0, sizeof(buf));
strncpy(buf, intro, sizeof(buf) - 1); strncpy(buf, intro, sizeof(buf) - 1);
RESETTIMERS(); gpt_resettimers();
SETTIMER(0, 60); gpt_settimer(0, 60);
Syslog('i', "TXEMSI: 60 seconds timer set"); Syslog('i', "TXEMSI: 60 seconds timer set");
SM_START(senddata) SM_START(senddata)
@ -534,7 +534,7 @@ SM_STATE(senddata)
PUTSTR(trailer); PUTSTR(trailer);
Syslog('i', "TXEMSI: send **%s%04X", p, crc16xmodem(p, strlen(p))); Syslog('i', "TXEMSI: send **%s%04X", p, crc16xmodem(p, strlen(p)));
free(p); free(p);
SETTIMER(1, 20); gpt_settimer(1, 20);
SM_PROCEED(waitpkt); SM_PROCEED(waitpkt);
SM_STATE(waitpkt) SM_STATE(waitpkt)
@ -544,12 +544,12 @@ SM_STATE(waitpkt)
SM_STATE(waitchar) SM_STATE(waitchar)
if (EXPIRED(0)) { if (gpt_expired(0)) {
Syslog('+', "EMSI transmit 60 seconds timeout"); Syslog('+', "EMSI transmit 60 seconds timeout");
SM_ERROR; SM_ERROR;
} }
if (EXPIRED(1)) { if (gpt_expired(1)) {
Syslog('i', "TXEMSI: 20 seconds timeout"); Syslog('i', "TXEMSI: 20 seconds timeout");
if (++tries > 19) { if (++tries > 19) {
Syslog('+', "too many tries sending EMSI"); Syslog('+', "too many tries sending EMSI");

View File

@ -232,8 +232,8 @@ SM_STATE(skipjunk)
Syslog('s', "tx_define_type SKIPJUNK"); Syslog('s', "tx_define_type SKIPJUNK");
while ((c = GETCHAR(1)) >= 0) /*nothing*/ ; while ((c = GETCHAR(1)) >= 0) /*nothing*/ ;
if (c == TIMEOUT) { if (c == TIMEOUT) {
RESETTIMERS(); gpt_resettimers();
SETTIMER(0, 60); /* 60 second master timer */ gpt_settimer(0, 60); /* 60 second master timer */
SM_PROCEED(wake); SM_PROCEED(wake);
} else { } else {
SM_ERROR; SM_ERROR;
@ -242,7 +242,7 @@ SM_STATE(skipjunk)
SM_STATE(wake) SM_STATE(wake)
Syslog('s', "tx_define_type WAKE"); Syslog('s', "tx_define_type WAKE");
if (EXPIRED(0)) { if (gpt_expired(0)) {
Syslog('+', "Remote did not respond"); Syslog('+', "Remote did not respond");
SM_ERROR; SM_ERROR;
} }
@ -255,7 +255,7 @@ SM_STATE(wake)
WriteError("Error while waking remote"); WriteError("Error while waking remote");
SM_ERROR; SM_ERROR;
} else { } else {
SETTIMER(0, 60); gpt_settimer(0, 60);
Syslog('S', "Got %c wakeup", c); Syslog('S', "Got %c wakeup", c);
SM_PROCEED(nextchar); SM_PROCEED(nextchar);
} }
@ -266,7 +266,7 @@ SM_STATE(waitchar)
standby = 0; standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
if (EXPIRED(0)) { if (gpt_expired(0)) {
Syslog('+', "Too many tries waking remote"); Syslog('+', "Too many tries waking remote");
SM_ERROR; SM_ERROR;
} }
@ -413,9 +413,9 @@ SM_EDECL
session_flags|=FTSC_XMODEM_CRC; session_flags|=FTSC_XMODEM_CRC;
ebuf[0]='\0'; ebuf[0]='\0';
ep=ebuf; ep=ebuf;
RESETTIMERS(); gpt_resettimers();
SETTIMER(0, 60); gpt_settimer(0, 60);
SETTIMER(1, 20); gpt_settimer(1, 20);
SM_START(sendintro) SM_START(sendintro)
@ -457,17 +457,17 @@ SM_STATE(sendintro)
SM_STATE(settimer) SM_STATE(settimer)
Syslog('s', "Set 20 secs timer"); Syslog('s', "Set 20 secs timer");
SETTIMER(1, 20); gpt_settimer(1, 20);
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
SM_STATE(waitchar) SM_STATE(waitchar)
if (EXPIRED(0)) { if (gpt_expired(0)) {
Syslog('+', "Session setup timeout"); Syslog('+', "Session setup timeout");
SM_ERROR; SM_ERROR;
} }
if (EXPIRED(1)) { if (gpt_expired(1)) {
Syslog('s', "20 sec timer timeout"); Syslog('s', "20 sec timer timeout");
SM_PROCEED(sendintro); SM_PROCEED(sendintro);
} }
@ -535,7 +535,7 @@ SM_STATE(nextchar)
* first sendintro, send the intro again. After * first sendintro, send the intro again. After
* that take it easy. * that take it easy.
*/ */
if (EXPIRED(1) || (count == 1)) { if (gpt_expired(1) || (count == 1)) {
Syslog('s', "sendintro after eol char"); Syslog('s', "sendintro after eol char");
SM_PROCEED(sendintro); SM_PROCEED(sendintro);
} else { } else {