BSD 4_4 release
[unix-history] / usr / src / usr.bin / uucp / uucico / tio.c
index ff6b910..d848307 100644 (file)
@@ -1,13 +1,50 @@
+/*-
+ * Copyright (c) 1982, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Adams.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)tio.c      4.6 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)tio.c      8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 
-#include <signal.h>
+#include <sys/param.h>
+#include <sys/signal.h>
+#include <sys/stat.h>
 #include "uucp.h"
 #include <setjmp.h>
 #include "uucp.h"
 #include <setjmp.h>
-#include <sys/stat.h>
 
 
-extern int pkfail();
+extern void pkfail();
 #define TPACKSIZE      512
 #define TBUFSIZE       1024
 #define min(a,b)       (((a)<(b))?(a):(b))
 #define TPACKSIZE      512
 #define TBUFSIZE       1024
 #define min(a,b)       (((a)<(b))?(a):(b))
@@ -32,6 +69,8 @@ struct tbuf {
 
 extern jmp_buf Failbuf;
 
 
 extern jmp_buf Failbuf;
 
+extern long Bytes_Sent, Bytes_Received;
+
 twrmsg(type, str, fn)
 char type;
 register char *str;
 twrmsg(type, str, fn)
 char type;
 register char *str;
@@ -43,7 +82,7 @@ register char *str;
        if(setjmp(Failbuf))
                return FAIL;
        signal(SIGALRM, pkfail);
        if(setjmp(Failbuf))
                return FAIL;
        signal(SIGALRM, pkfail);
-       alarm(MAXMSGTIME);
+       alarm(MAXMSGTIME*5);
        bufr[0] = type;
        s = &bufr[1];
        while (*str)
        bufr[0] = type;
        s = &bufr[1];
        while (*str)
@@ -69,12 +108,10 @@ register char *str;
        if(setjmp(Failbuf))
                return FAIL;
        signal(SIGALRM, pkfail);
        if(setjmp(Failbuf))
                return FAIL;
        signal(SIGALRM, pkfail);
-       alarm(MAXMSGTIME);
+       alarm(MAXMSGTIME*5);
        for (;;) {
                len = read(fn, str, TPACKSIZE);
        for (;;) {
                len = read(fn, str, TPACKSIZE);
-               if (len == 0)
-                       continue;
-               if (len < 0) {
+               if (len <= 0) {
                        alarm(0);
                        return FAIL;
                }
                        alarm(0);
                        return FAIL;
                }
@@ -96,6 +133,7 @@ FILE *fp1;
        struct timeb t1, t2;
        long bytes;
        char text[TBUFSIZE];
        struct timeb t1, t2;
        long bytes;
        char text[TBUFSIZE];
+       float ft;
 
        if(setjmp(Failbuf))
                return FAIL;
 
        if(setjmp(Failbuf))
                return FAIL;
@@ -116,7 +154,7 @@ FILE *fp1;
 #endif !vax and !pdp11 and !ns32000
                DEBUG(8,"twrdata sending %d bytes\n",len);
                len += sizeof(long);
 #endif !vax and !pdp11 and !ns32000
                DEBUG(8,"twrdata sending %d bytes\n",len);
                len += sizeof(long);
-               alarm(MAXMSGTIME);
+               alarm(MAXMSGTIME*5);
                ret = twrblk((char *)&bufr, len, fn);
                alarm(0);
                if (ret != len)
                ret = twrblk((char *)&bufr, len, fn);
                alarm(0);
                if (ret != len)
@@ -126,7 +164,7 @@ FILE *fp1;
        }
        bufr.t_nbytes = 0;
        len = sizeof(long);
        }
        bufr.t_nbytes = 0;
        len = sizeof(long);
-       alarm(MAXMSGTIME);
+       alarm(MAXMSGTIME*5);
        ret = twrblk((char *)&bufr, len, fn);
        alarm(0);
        if (ret != len)
        ret = twrblk((char *)&bufr, len, fn);
        alarm(0);
        if (ret != len)
@@ -144,11 +182,13 @@ FILE *fp1;
                --t2.time;
                mil += 1000;
        }
                --t2.time;
                mil += 1000;
        }
-       sprintf(text, "sent data %ld bytes %ld.%02d secs",
-                               bytes, (long)t2.time, mil/10);
+       ft = (float)t2.time + (float)mil/1000.;
+       sprintf(text, "sent data %ld bytes %.2f secs %ld bps",
+               bytes, ft, (long)((float)bytes*8./ft));
        sysacct(bytes, t2.time);
        sysacct(bytes, t2.time);
+       Bytes_Sent += bytes;
        DEBUG(1, "%s\n", text);
        DEBUG(1, "%s\n", text);
-       syslog(text);
+       log_xferstats(text);
        return SUCCESS;
 }
 
        return SUCCESS;
 }
 
@@ -160,6 +200,7 @@ FILE *fp2;
        struct timeb t1, t2;
        int mil;
        long bytes, Nbytes;
        struct timeb t1, t2;
        int mil;
        long bytes, Nbytes;
+       float ft;
 
        if(setjmp(Failbuf))
                return FAIL;
 
        if(setjmp(Failbuf))
                return FAIL;
@@ -172,7 +213,7 @@ FILE *fp2;
 #endif !USG
        bytes = 0L;
        for (;;) {
 #endif !USG
        bytes = 0L;
        for (;;) {
-               alarm(MAXMSGTIME);
+               alarm(MAXMSGTIME*5);
                len = trdblk((char *)&Nbytes,sizeof Nbytes,fn);
                alarm(0);
                if (len != sizeof Nbytes)
                len = trdblk((char *)&Nbytes,sizeof Nbytes,fn);
                alarm(0);
                if (len != sizeof Nbytes)
@@ -184,7 +225,7 @@ FILE *fp2;
                nread = Nbytes;
                if (nread == 0)
                        break;
                nread = Nbytes;
                if (nread == 0)
                        break;
-               alarm(MAXMSGTIME);
+               alarm(MAXMSGTIME*5);
                len = trdblk(bufr, nread, fn);
                alarm(0);
                if (len < 0) {
                len = trdblk(bufr, nread, fn);
                alarm(0);
                if (len < 0) {
@@ -210,11 +251,13 @@ FILE *fp2;
                --t2.time;
                mil += 1000;
        }
                --t2.time;
                mil += 1000;
        }
-       sprintf(bufr, "received data %ld bytes %ld.%02d secs",
-                               bytes, (long)t2.time, mil/10);
-       sysacct(bytes, t2.time - t1.time);
+       ft = (float)t2.time + (float)mil/1000.;
+       sprintf(bufr, "received data %ld bytes %.2f secs %ld bps",
+               bytes, ft, (long)((float)bytes*8./ft));
+       sysacct(bytes, t2.time);
+       Bytes_Received += bytes;
        DEBUG(1, "%s\n", bufr);
        DEBUG(1, "%s\n", bufr);
-       syslog(bufr);
+       log_xferstats(bufr);
        return SUCCESS;
 }
 
        return SUCCESS;
 }