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

Defined functions

trdblk defined in line 228; used 2 times
trddata defined in line 157; used 2 times
trdmsg defined in line 66; used 2 times
twrblk defined in line 253; used 3 times
twrdata defined in line 92; used 2 times
twrmsg defined in line 37; used 2 times

Defined variables

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

Defined struct's

tbuf defined in line 30; used 2 times
  • in line 95(2)

Defined macros

LBUFSIZE defined in line 14; used 1 times
TBUFSIZE defined in line 13; used 5 times
TC defined in line 224; used 3 times
TPACKSIZE defined in line 12; used 4 times
min defined in line 15; never used
Last modified: 1988-12-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3466
Valid CSS Valid XHTML 1.0 Strict