1: #ifndef lint
   2: static char sccsid[] = "@(#)tio.c	4.6 (Berkeley) 1/24/86";
   3: #endif
   4: 
   5: #include <signal.h>
   6: #include "uucp.h"
   7: #include <setjmp.h>
   8: #include <sys/stat.h>
   9: 
  10: extern int pkfail();
  11: #define TPACKSIZE   512
  12: #define TBUFSIZE    1024
  13: #define min(a,b)    (((a)<(b))?(a):(b))
  14: 
  15: /*
  16:  *	htonl is a function that converts a long from host
  17:  *		order to network order
  18:  *	ntohl is a function that converts a long from network
  19:  *		order to host order
  20:  *
  21:  *	network order is 		0 1 2 3 (bytes in a long)
  22:  *	host order on a vax is		3 2 1 0
  23:  *	host order on a pdp11 is	1 0 3 2
  24:  *	host order on a 68000 is	0 1 2 3
  25:  *	most other machines are		0 1 2 3
  26:  */
  27: 
  28: struct tbuf {
  29:     long t_nbytes;
  30:     char t_data[TBUFSIZE];
  31: };
  32: 
  33: extern jmp_buf Failbuf;
  34: 
  35: twrmsg(type, str, fn)
  36: char type;
  37: register char *str;
  38: {
  39:     char bufr[TBUFSIZE];
  40:     register char *s;
  41:     int len, i;
  42: 
  43:     if(setjmp(Failbuf))
  44:         return FAIL;
  45:     signal(SIGALRM, pkfail);
  46:     alarm(MAXMSGTIME);
  47:     bufr[0] = type;
  48:     s = &bufr[1];
  49:     while (*str)
  50:         *s++ = *str++;
  51:     *s = '\0';
  52:     if (*(--s) == '\n')
  53:         *s = '\0';
  54:     len = strlen(bufr) + 1;
  55:     if ((i = len % TPACKSIZE)) {
  56:         len = len + TPACKSIZE - i;
  57:         bufr[len - 1] = '\0';
  58:     }
  59:     twrblk(bufr, len, fn);
  60:     alarm(0);
  61:     return SUCCESS;
  62: }
  63: 
  64: trdmsg(str, fn)
  65: register char *str;
  66: {
  67:     int len, cnt = 0;
  68: 
  69:     if(setjmp(Failbuf))
  70:         return FAIL;
  71:     signal(SIGALRM, pkfail);
  72:     alarm(MAXMSGTIME);
  73:     for (;;) {
  74:         len = read(fn, str, TPACKSIZE);
  75:         if (len == 0)
  76:             continue;
  77:         if (len < 0) {
  78:             alarm(0);
  79:             return FAIL;
  80:         }
  81:         str += len;
  82:         cnt += len;
  83:         if (*(str - 1) == '\0' && (cnt % TPACKSIZE) == 0)
  84:             break;
  85:     }
  86:     alarm(0);
  87:     return SUCCESS;
  88: }
  89: 
  90: twrdata(fp1, fn)
  91: FILE *fp1;
  92: {
  93:     struct tbuf bufr;
  94:     register int len;
  95:     int ret, mil;
  96:     struct timeb t1, t2;
  97:     long bytes;
  98:     char text[TBUFSIZE];
  99: 
 100:     if(setjmp(Failbuf))
 101:         return FAIL;
 102:     signal(SIGALRM, pkfail);
 103:     bytes = 0L;
 104: #ifdef USG
 105:     time(&t1.time);
 106:     t1.millitm = 0;
 107: #else !USG
 108:     ftime(&t1);
 109: #endif !USG
 110:     while ((len = read(fileno(fp1), bufr.t_data, TBUFSIZE)) > 0) {
 111:         bytes += len;
 112: #if defined(vax) || defined(pdp11) || defined(ns32000)
 113:         bufr.t_nbytes = htonl((long)len);
 114: #else !vax and !pdp11 and !ns32000
 115:         bufr.t_nbytes = len;
 116: #endif !vax and !pdp11 and !ns32000
 117:         DEBUG(8,"twrdata sending %d bytes\n",len);
 118:         len += sizeof(long);
 119:         alarm(MAXMSGTIME);
 120:         ret = twrblk((char *)&bufr, len, fn);
 121:         alarm(0);
 122:         if (ret != len)
 123:             return FAIL;
 124:         if (len != TBUFSIZE+sizeof(long))
 125:             break;
 126:     }
 127:     bufr.t_nbytes = 0;
 128:     len = sizeof(long);
 129:     alarm(MAXMSGTIME);
 130:     ret = twrblk((char *)&bufr, len, fn);
 131:     alarm(0);
 132:     if (ret != len)
 133:         return FAIL;
 134: #ifdef USG
 135:     time(&t2.time);
 136:     t2.millitm = 0;
 137: #else !USG
 138:     ftime(&t2);
 139: #endif !USG
 140:     Now = t2;
 141:     t2.time -= t1.time;
 142:     mil = t2.millitm - t1.millitm;
 143:     if (mil < 0) {
 144:         --t2.time;
 145:         mil += 1000;
 146:     }
 147:     sprintf(text, "sent data %ld bytes %ld.%02d secs",
 148:                 bytes, (long)t2.time, mil/10);
 149:     sysacct(bytes, t2.time);
 150:     DEBUG(1, "%s\n", text);
 151:     syslog(text);
 152:     return SUCCESS;
 153: }
 154: 
 155: trddata(fn, fp2)
 156: FILE *fp2;
 157: {
 158:     register int len, nread;
 159:     char bufr[TBUFSIZE];
 160:     struct timeb t1, t2;
 161:     int mil;
 162:     long bytes, Nbytes;
 163: 
 164:     if(setjmp(Failbuf))
 165:         return FAIL;
 166:     signal(SIGALRM, pkfail);
 167: #ifdef USG
 168:     time(&t1.time);
 169:     t1.millitm = 0;
 170: #else !USG
 171:     ftime(&t1);
 172: #endif !USG
 173:     bytes = 0L;
 174:     for (;;) {
 175:         alarm(MAXMSGTIME);
 176:         len = trdblk((char *)&Nbytes,sizeof Nbytes,fn);
 177:         alarm(0);
 178:         if (len != sizeof Nbytes)
 179:             return FAIL;
 180: #if defined(vax) || defined(pdp11) || defined(ns32000)
 181:         Nbytes = ntohl(Nbytes);
 182: #endif vax or pdp11 or ns32000
 183:         DEBUG(8,"trddata expecting %ld bytes\n",Nbytes);
 184:         nread = Nbytes;
 185:         if (nread == 0)
 186:             break;
 187:         alarm(MAXMSGTIME);
 188:         len = trdblk(bufr, nread, fn);
 189:         alarm(0);
 190:         if (len < 0) {
 191:             return FAIL;
 192:         }
 193:         bytes += len;
 194:         DEBUG(11,"trddata got %ld\n",bytes);
 195:         if (write(fileno(fp2), bufr, len) != len) {
 196:             alarm(0);
 197:             return FAIL;
 198:         }
 199:     }
 200: #ifdef USG
 201:     time(&t2.time);
 202:     t2.millitm = 0;
 203: #else !USG
 204:     ftime(&t2);
 205: #endif !USG
 206:     Now = t2;
 207:     t2.time -= t1.time;
 208:     mil = t2.millitm - t1.millitm;
 209:     if (mil < 0) {
 210:         --t2.time;
 211:         mil += 1000;
 212:     }
 213:     sprintf(bufr, "received data %ld bytes %ld.%02d secs",
 214:                 bytes, (long)t2.time, mil/10);
 215:     sysacct(bytes, t2.time - t1.time);
 216:     DEBUG(1, "%s\n", bufr);
 217:     syslog(bufr);
 218:     return SUCCESS;
 219: }
 220: 
 221: #if !defined(BSD4_2) && !defined(USG)
 222: #define TC  1024
 223: static  int tc = TC;
 224: #endif !BSD4_2 && !USG
 225: 
 226: trdblk(blk, len,  fn)
 227: register int len;
 228: char *blk;
 229: {
 230:     register int i, ret;
 231: 
 232: #if !defined(BSD4_2) && !defined(USG)
 233:     /* call ultouch occasionally */
 234:     if (--tc < 0) {
 235:         tc = TC;
 236:         ultouch();
 237:     }
 238: #endif !BSD4_2 && !USG
 239:     for (i = 0; i < len; i += ret) {
 240:         ret = read(fn, blk, len - i);
 241:         if (ret < 0)
 242:             return FAIL;
 243:         blk += ret;
 244:         if (ret == 0)
 245:             return i;
 246:     }
 247:     return i;
 248: }
 249: 
 250: 
 251: twrblk(blk, len, fn)
 252: register char *blk;
 253: {
 254: #if !defined(BSD4_2) && !defined(USG)
 255:     /* call ultouch occasionally */
 256:     if (--tc < 0) {
 257:         tc = TC;
 258:         ultouch();
 259:     }
 260: #endif !BSD4_2 && !USG
 261:     return write(fn, blk, len);
 262: }

Defined functions

trdblk defined in line 226; used 2 times
trddata defined in line 155; used 2 times
trdmsg defined in line 64; used 2 times
twrblk defined in line 251; used 3 times
twrdata defined in line 90; used 2 times
twrmsg defined in line 35; used 2 times

Defined variables

sccsid defined in line 2; never used
tc defined in line 223; used 4 times

Defined struct's

tbuf defined in line 28; used 2 times
  • in line 93(2)

Defined macros

TBUFSIZE defined in line 12; used 6 times
TC defined in line 222; used 3 times
TPACKSIZE defined in line 11; used 4 times
min defined in line 13; never used
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1547
Valid CSS Valid XHTML 1.0 Strict