Removed some ttyio heavy debug from mbcico

This commit is contained in:
Michiel Broek 2003-04-12 16:04:14 +00:00
parent b3b4b5dcb5
commit 821e1dc5b6
2 changed files with 253 additions and 260 deletions

View File

@ -20,6 +20,10 @@ v0.37.3 09-Apr-2003.
Added menu function display file. Added menu function display file.
Display ascii textfiles now uses the More Y/n/= prompt. Display ascii textfiles now uses the More Y/n/= prompt.
mbcico:
Removed some heavy debug code from ttyio functions to increase
throughput.
lang: lang:
New language prompt number 17. New language prompt number 17.
Erased language prompts 18..36. Erased language prompts 18..36.

View File

@ -4,7 +4,7 @@
* Purpose ...............: Fidonet mailer * Purpose ...............: Fidonet mailer
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2002 * Copyright (C) 1997-2003
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -74,83 +74,79 @@ char *ttystat[]= {(char *)"Ok",
int tty_resettimer(int tno) int tty_resettimer(int tno)
{ {
if (tno >= NUMTIMERS) { if (tno >= NUMTIMERS) {
errno = EINVAL; errno = EINVAL;
WriteError("$ttyio: invalid timer No for resettimer()"); WriteError("ttyio: invalid timer No for resettimer(%d)", tno);
return -1; return -1;
} }
Syslog('T', "ttyio: resettimer(%d)", tno); timer[tno] = (time_t) 0;
timer[tno] = (time_t) 0; return 0;
return 0;
} }
void tty_resettimers(void) void tty_resettimers(void)
{ {
int i; int i;
Syslog('T', "ttyio: resettimers"); for (i = 0; i < NUMTIMERS; i++)
for (i = 0; i < NUMTIMERS; i++) timer[i] = (time_t)0;
timer[i] = (time_t)0;
} }
int tty_settimer(int tno, int interval) int tty_settimer(int tno, int interval)
{ {
if (tno >= NUMTIMERS) { if (tno >= NUMTIMERS) {
errno = EINVAL; errno = EINVAL;
WriteError("$ttyio: invalid timer No for settimer()"); WriteError("ttyio: invalid timer No for settimer(%d)", tno);
return -1; return -1;
} }
Syslog('T', "ttyio: settimer(%d,%d)",tno,interval); timer[tno]=time((time_t*)NULL)+interval;
timer[tno]=time((time_t*)NULL)+interval; return 0;
return 0;
} }
int tty_expired(int tno) int tty_expired(int tno)
{ {
time_t now; time_t now;
if (tno >= NUMTIMERS) { if (tno >= NUMTIMERS) {
errno = EINVAL; errno = EINVAL;
WriteError("$ttyio: invalid timer No for expired(%d)", tno); WriteError("ttyio: invalid timer No for expired(%d)", tno);
return -1; return -1;
} }
/* /*
* Check if timer is running * Check if timer is running
*/ */
if (timer[tno] == (time_t) 0) if (timer[tno] == (time_t) 0)
return 0; return 0;
now = time(NULL); now = time(NULL);
Syslog('T', "ttyio: expired(%d) now=%lu,timer=%lu,return %s", tno,now,timer[tno],(now >= timer[tno])?"yes":"no"); return (now >= timer[tno]);
return (now >= timer[tno]);
} }
int tty_running(int tno) int tty_running(int tno)
{ {
if (tno > NUMTIMERS) { if (tno > NUMTIMERS) {
errno = EINVAL; errno = EINVAL;
WriteError("$ttyio: invalid timer for tty_running(%d)", tno); WriteError("ttyio: invalid timer for tty_running(%d)", tno);
return -1; return -1;
} }
/* /*
* check if timer is running * check if timer is running
*/ */
if (timer[tno] == (time_t) 0) if (timer[tno] == (time_t) 0)
return 0; return 0;
else else
return 1; return 1;
} }
@ -161,302 +157,295 @@ int tty_running(int tno)
static int tty_read(char *buf, int size, int tot) static int tty_read(char *buf, int size, int tot)
{ {
time_t timeout, now; time_t timeout, now;
int i, rc; int i, rc;
fd_set readfds, writefds, exceptfds; fd_set readfds, writefds, exceptfds;
struct timeval seltimer; struct timeval seltimer;
Syslog('T', "tty_read: (%08lx,%d,%d)",buf,size,tot); if (size == 0)
if (size == 0) return 0;
return 0; tty_status = 0;
tty_status = 0;
now = time(NULL); now = time(NULL);
timeout = (time_t)300; /* maximum of 5 minutes */ timeout = (time_t)300; /* maximum of 5 minutes */
for (i = 0; i < TIMERNO_TX; i++) { for (i = 0; i < TIMERNO_TX; i++) {
if (timer[i]) { if (timer[i]) {
if (now >= timer[i]) { if (now >= timer[i]) {
tty_status=STAT_TIMEOUT; tty_status=STAT_TIMEOUT;
Syslog('-', "tty_read: timer %d already expired, return",i); Syslog('!', "tty_read: timer %d already expired, return", i);
// Syslog('t', "tty_read: timer %d already expired, return",i);
return -tty_status;
} else {
if (timeout > (timer[i]-now))
timeout=timer[i]-now;
}
}
}
if ((tot != -1) && (timeout > tot))
timeout=tot;
Syslog('T', "tty_read: timeout = %d", timeout);
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
FD_SET(0,&readfds);
FD_SET(0,&exceptfds);
seltimer.tv_sec=timeout;
seltimer.tv_usec=0;
rc = select(1,&readfds,&writefds,&exceptfds,&seltimer);
if (rc < 0) {
if (hanged_up) {
tty_status=STAT_HANGUP;
WriteError("$tty_read: hanged_up flag");
} else {
WriteError("$tty_read: select for read failed");
tty_status = STAT_ERROR;
}
} else if (rc == 0) {
tty_status = STAT_TIMEOUT;
} else { /* rc > 0 */
if (FD_ISSET(0,&exceptfds)) {
Syslog('+', "$tty_read: exeption error");
tty_status = STAT_ERROR;
}
}
if (tty_status) {
Syslog('T', "tty_read: return after select: %s",ttystat[tty_status]);
return -tty_status; return -tty_status;
} else {
if (timeout > (timer[i]-now))
timeout=timer[i]-now;
}
} }
}
if ((tot != -1) && (timeout > tot))
timeout=tot;
if (!FD_ISSET(0,&readfds)) { FD_ZERO(&readfds);
WriteError("tty_read: Cannot be: select returned but read fd not set"); FD_ZERO(&writefds);
tty_status = STAT_ERROR; FD_ZERO(&exceptfds);
return -tty_status; FD_SET(0,&readfds);
FD_SET(0,&exceptfds);
seltimer.tv_sec=timeout;
seltimer.tv_usec=0;
rc = select(1,&readfds,&writefds,&exceptfds,&seltimer);
if (rc < 0) {
if (hanged_up) {
tty_status=STAT_HANGUP;
WriteError("tty_read: hanged_up flag");
} else {
WriteError("$tty_read: select for read failed");
tty_status = STAT_ERROR;
} }
} else if (rc == 0) {
tty_status = STAT_TIMEOUT;
} else { /* rc > 0 */
if (FD_ISSET(0,&exceptfds)) {
Syslog('!', "$tty_read: exeption error");
tty_status = STAT_ERROR;
}
}
rc = read(0,buf,size); if (tty_status) {
if (rc <= 0) { return -tty_status;
Syslog('t', "tty_read: return %d",rc); }
if (hanged_up || (errno == EPIPE) || (errno == ECONNRESET)) {
tty_status = STAT_HANGUP; if (!FD_ISSET(0,&readfds)) {
WriteError("$tty_read: hanged_up flag"); WriteError("tty_read: Cannot be: select returned but read fd not set");
} else { tty_status = STAT_ERROR;
tty_status = STAT_ERROR; return -tty_status;
Syslog('-', "tty_read: error flag"); }
}
rc=-tty_status; rc = read(0,buf,size);
} else if (rc <= 0) {
Syslog('T', "tty_read: %s %d characters", printable(buf, rc), rc); Syslog('t', "tty_read: return %d",rc);
return rc; if (hanged_up || (errno == EPIPE) || (errno == ECONNRESET)) {
tty_status = STAT_HANGUP;
WriteError("tty_read: hanged_up flag");
} else {
tty_status = STAT_ERROR;
Syslog('!', "tty_read: error flag");
}
rc=-tty_status;
}
return rc;
} }
int tty_write(char *buf, int size) int tty_write(char *buf, int size)
{ {
int result; int result;
Syslog('T', "tty_write(%08lx,%d)",buf,size); tty_status=0;
result = write(1,buf,size);
tty_status=0; if (result != size) {
result = write(1,buf,size); if (hanged_up || (errno == EPIPE) || (errno == ECONNRESET)) {
tty_status = STAT_HANGUP;
if (result != size) { WriteError("tty_write: hanged_up flag");
if (hanged_up || (errno == EPIPE) || (errno == ECONNRESET)) { } else {
tty_status = STAT_HANGUP; tty_status=STAT_ERROR;
WriteError("$tty_write: hanged_up flag"); Syslog('!', "tty_write: error flag");
} else {
tty_status=STAT_ERROR;
Syslog('-', "tty_write: error flag");
}
} }
if (tty_status) }
Syslog('t', "tty_write: error %s", ttystat[tty_status]); if (tty_status)
Syslog('t', "tty_write: error %s", ttystat[tty_status]);
return -tty_status; return -tty_status;
} }
/* public r/w functions */ /* public r/w functions */
/** /*
* Check if there is data available on stdin. * Check if there is data available on stdin.
*/ */
int tty_check(void) int tty_check(void)
{ {
int rc; int rc;
// try to read available (timeout = 0) data if we have no data in // try to read available (timeout = 0) data if we have no data in
// our buffer // our buffer
if (!left) { if (!left) {
rc = tty_read(buffer, TT_BUFSIZ, 0); rc = tty_read(buffer, TT_BUFSIZ, 0);
if (rc > 0) { if (rc > 0) {
left = rc; left = rc;
}
} }
}
return (left > 0); return (left > 0);
} }
int tty_putcheck(int size) int tty_putcheck(int size)
{ {
fd_set set; fd_set set;
struct timeval timeout; struct timeval timeout;
/* /*
* Initialize the file descriptor set. * Initialize the file descriptor set.
*/ */
FD_ZERO(&set); FD_ZERO(&set);
FD_SET(1, &set); FD_SET(1, &set);
/* /*
* Initialize the timeout data structure. * Initialize the timeout data structure.
*/ */
timeout.tv_sec = 0; timeout.tv_sec = 0;
timeout.tv_usec = 0; timeout.tv_usec = 0;
/* /*
* `select' returns 0 if timeout, 1 if input available, -1 if error. * `select' returns 0 if timeout, 1 if input available, -1 if error.
*/ */
return select(FD_SETSIZE, NULL, &set, NULL, &timeout); return select(FD_SETSIZE, NULL, &set, NULL, &timeout);
} }
int tty_waitputget(int tot) int tty_waitputget(int tot)
{ {
int i, rc; int i, rc;
time_t timeout, now; time_t timeout, now;
fd_set readfds, writefds, exceptfds; fd_set readfds, writefds, exceptfds;
struct timeval seltimer; struct timeval seltimer;
tty_status=0; tty_status=0;
now = time(NULL); now = time(NULL);
timeout=(time_t)300; /* maximum of 5 minutes */ timeout=(time_t)300; /* maximum of 5 minutes */
for (i = 0; i < NUMTIMERS; i++) { for (i = 0; i < NUMTIMERS; i++) {
if (timer[i]) { if (timer[i]) {
if (now >= timer[i]) { if (now >= timer[i]) {
tty_status = STAT_TIMEOUT; tty_status = STAT_TIMEOUT;
WriteError("tty_waitputget: timer %d already expired, return",i); WriteError("tty_waitputget: timer %d already expired, return",i);
return -tty_status;
} else {
if (timeout > (timer[i]-now))
timeout = timer[i]-now;
}
}
}
if ((tot != -1) && (timeout > tot))
timeout=tot;
Syslog('t', "tty_waitputget: timeout=%d",timeout);
/*
* Initialize the file descriptor set.
*/
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
FD_SET(0, &readfds);
FD_SET(1, &writefds);
FD_SET(0, &exceptfds);
FD_SET(1, &exceptfds);
/*
* Initialize the timeout data structure.
*/
seltimer.tv_sec = timeout;
seltimer.tv_usec = 0;
/*
* `select' returns 0 if timeout, 1 if input available, -1 if error.
*/
rc = select(FD_SETSIZE, &readfds, &writefds, &exceptfds, &seltimer);
if (rc < 0) {
if (hanged_up) {
tty_status=STAT_HANGUP;
WriteError("tty_waitputget: hanged_up flag");
} else {
WriteError("$tty_waitputget: select failed");
tty_status=STAT_ERROR;
}
} else if (rc == 0) {
tty_status=STAT_TIMEOUT;
} else {
/* rc > 0 */
if ((FD_ISSET(0,&exceptfds)) || (FD_ISSET(1,&exceptfds))) {
WriteError("$tty_waitputget: exeption error");
tty_status=STAT_ERROR;
}
}
if (tty_status) {
Syslog('t', "tty_waitputget: return after select status %s",ttystat[tty_status]);
return -tty_status; return -tty_status;
} else {
if (timeout > (timer[i]-now))
timeout = timer[i]-now;
}
} }
}
if ((tot != -1) && (timeout > tot))
timeout=tot;
Syslog('t', "tty_waitputget: timeout=%d",timeout);
rc = 0; /*
* Initialize the file descriptor set.
*/
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
if (FD_ISSET(0,&readfds)) FD_SET(0, &readfds);
rc |= 1; FD_SET(1, &writefds);
FD_SET(0, &exceptfds);
FD_SET(1, &exceptfds);
if (FD_ISSET(1,&writefds)) /*
rc |= 2; * Initialize the timeout data structure.
*/
seltimer.tv_sec = timeout;
seltimer.tv_usec = 0;
return rc; /*
* `select' returns 0 if timeout, 1 if input available, -1 if error.
*/
rc = select(FD_SETSIZE, &readfds, &writefds, &exceptfds, &seltimer);
if (rc < 0) {
if (hanged_up) {
tty_status=STAT_HANGUP;
WriteError("tty_waitputget: hanged_up flag");
} else {
WriteError("$tty_waitputget: select failed");
tty_status=STAT_ERROR;
}
} else if (rc == 0) {
tty_status=STAT_TIMEOUT;
} else {
/* rc > 0 */
if ((FD_ISSET(0,&exceptfds)) || (FD_ISSET(1,&exceptfds))) {
WriteError("$tty_waitputget: exeption error");
tty_status=STAT_ERROR;
}
}
if (tty_status) {
Syslog('t', "tty_waitputget: return after select status %s",ttystat[tty_status]);
return -tty_status;
}
rc = 0;
if (FD_ISSET(0,&readfds))
rc |= 1;
if (FD_ISSET(1,&writefds))
rc |= 2;
return rc;
} }
void tty_flushin(void) void tty_flushin(void)
{ {
tcflush(0, TCIFLUSH); tcflush(0, TCIFLUSH);
} }
void tty_flushout(void) void tty_flushout(void)
{ {
tcflush(1, TCOFLUSH); tcflush(1, TCOFLUSH);
} }
int tty_ungetc(int c) int tty_ungetc(int c)
{ {
if (next == buffer) { if (next == buffer) {
if (left >= TT_BUFSIZ) { if (left >= TT_BUFSIZ) {
return -1; return -1;
}
next = buffer + TT_BUFSIZ - left;
memcpy(next, buffer, left);
} }
next--; next = buffer + TT_BUFSIZ - left;
*next = c; memcpy(next, buffer, left);
left++; }
return 0; next--;
*next = c;
left++;
return 0;
} }
int tty_getc(int tot) int tty_getc(int tot)
{ {
if (!left) { if (!left) {
left=tty_read(buffer,TT_BUFSIZ,tot); left=tty_read(buffer,TT_BUFSIZ,tot);
next=buffer; next=buffer;
} }
if (left <= 0) { if (left <= 0) {
left=0; left=0;
return -tty_status; return -tty_status;
} else { } else {
left--; left--;
return (*next++)&0xff; return (*next++)&0xff;
} }
} }