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

@@ -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 \
dostran.c ftnmsg.c mbfile.c nodelock.c rawio.c strcasestr.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 \
batchrd.o ftn.o pktname.o mangle.o sectest.o proglock.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 \
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
NODELIST_SRCS = nodelist.c
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
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
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
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

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
*/
@@ -514,5 +503,16 @@ int Le_Access(securityrec, securityrec); /* Endian independant */
int lockprogram(char *); /* Lock 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

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;
}