1 #ifndef lint 2 static char sccsid[] = "@(#)gio.c 5.4 (Berkeley) 06/20/85"; 3 #endif 4 5 #include "uucp.h" 6 #include "pk.h" 7 #include <setjmp.h> 8 9 jmp_buf Failbuf; 10 11 int Retries = 0; 12 struct pack *Pk; 13 14 pkfail() 15 { 16 longjmp(Failbuf, 1); 17 } 18 19 gturnon() 20 { 21 struct pack *pkopen(); 22 23 if (setjmp(Failbuf)) 24 return FAIL; 25 Pk = pkopen(Ifn, Ofn); 26 if (Pk == NULL) 27 return FAIL; 28 return SUCCESS; 29 } 30 31 gturnoff() 32 { 33 if(setjmp(Failbuf)) 34 return(FAIL); 35 pkclose(Pk); 36 return SUCCESS; 37 } 38 39 40 gwrmsg(type, str, fn) 41 char type; 42 register char *str; 43 { 44 char bufr[BUFSIZ]; 45 register char *s; 46 int len, i; 47 48 if(setjmp(Failbuf)) 49 return(FAIL); 50 bufr[0] = type; 51 s = &bufr[1]; 52 while (*str) 53 *s++ = *str++; 54 *s = '\0'; 55 if (*(--s) == '\n') 56 *s = '\0'; 57 len = strlen(bufr) + 1; 58 if ((i = len % PACKSIZE)) { 59 len = len + PACKSIZE - i; 60 bufr[len - 1] = '\0'; 61 } 62 gwrblk(bufr, len, fn); 63 return SUCCESS; 64 } 65 66 /*ARGSUSED*/ 67 grdmsg(str, fn) 68 register char *str; 69 { 70 unsigned len; 71 72 if(setjmp(Failbuf)) 73 return FAIL; 74 for (;;) { 75 len = pkread(Pk, str, PACKSIZE); 76 if (len == 0) 77 continue; 78 str += len; 79 if (*(str - 1) == '\0') 80 break; 81 } 82 return SUCCESS; 83 } 84 85 86 gwrdata(fp1, fn) 87 FILE *fp1; 88 { 89 char bufr[BUFSIZ]; 90 register int len; 91 int ret, mil; 92 struct timeb t1, t2; 93 long bytes; 94 char text[BUFSIZ]; 95 96 if(setjmp(Failbuf)) 97 return FAIL; 98 bytes = 0L; 99 Retries = 0; 100 #ifdef USG 101 time(&t1.time); 102 t1.millitm = 0; 103 #else !USG 104 ftime(&t1); 105 #endif !USG 106 while ((len = read(fileno(fp1), bufr, BUFSIZ)) > 0) { 107 bytes += len; 108 ret = gwrblk(bufr, len, fn); 109 if (ret != len) { 110 return FAIL; 111 } 112 if (len != BUFSIZ) 113 break; 114 } 115 ret = gwrblk(bufr, 0, fn); 116 #ifdef USG 117 time(&t2.time); 118 t2.millitm = 0; 119 #else !USG 120 ftime(&t2); 121 #endif !USG 122 Now = t2; 123 t2.time -= t1.time; 124 mil = t2.millitm - t1.millitm; 125 if (mil < 0) { 126 --t2.time; 127 mil += 1000; 128 } 129 sprintf(text, "sent data %ld bytes %ld.%02d secs", 130 bytes, (long)t2.time, mil/10); 131 sysacct(bytes, t2.time - t1.time); 132 if (Retries > 0) 133 sprintf((char *)text+strlen(text)," %d retries", Retries); 134 DEBUG(1, "%s\n", text); 135 syslog(text); 136 return SUCCESS; 137 } 138 139 grddata(fn, fp2) 140 FILE *fp2; 141 { 142 register int len; 143 char bufr[BUFSIZ]; 144 struct timeb t1, t2; 145 int mil; 146 long bytes; 147 char text[BUFSIZ]; 148 149 if(setjmp(Failbuf)) 150 return FAIL; 151 bytes = 0L; 152 Retries = 0; 153 #ifdef USG 154 time(&t1.time); 155 t1.millitm = 0; 156 #else !USG 157 ftime(&t1); 158 #endif !USG 159 for (;;) { 160 len = grdblk(bufr, BUFSIZ, fn); 161 if (len < 0) { 162 return FAIL; 163 } 164 bytes += len; 165 if (write(fileno(fp2), bufr, len) != len) 166 return FAIL; 167 if (len < BUFSIZ) 168 break; 169 } 170 #ifdef USG 171 time(&t2.time); 172 t2.millitm = 0; 173 #else !USG 174 ftime(&t2); 175 #endif !USG 176 Now = t2; 177 t2.time -= t1.time; 178 mil = t2.millitm - t1.millitm; 179 if (mil < 0) { 180 --t2.time; 181 mil += 1000; 182 } 183 sprintf(text, "received data %ld bytes %ld.%02d secs", 184 bytes, (long)t2.time, mil/10); 185 sysacct(bytes, t2.time - t1.time); 186 if (Retries > 0) 187 sprintf((char *)text+strlen(text)," %d retries", Retries); 188 DEBUG(1, "%s\n", text); 189 syslog(text); 190 return SUCCESS; 191 } 192 193 /* call ultouch every TC calls to either grdblk or gwrblk -- rti!trt */ 194 #define TC 20 195 static int tc = TC; 196 197 /*ARGSUSED*/ 198 grdblk(blk, len, fn) 199 register int len; 200 char *blk; 201 { 202 register int i, ret; 203 204 /* call ultouch occasionally */ 205 if (--tc < 0) { 206 tc = TC; 207 ultouch(); 208 } 209 for (i = 0; i < len; i += ret) { 210 ret = pkread(Pk, blk, len - i); 211 if (ret < 0) 212 return FAIL; 213 blk += ret; 214 if (ret == 0) 215 return i; 216 } 217 return i; 218 } 219 220 /*ARGSUSED*/ 221 gwrblk(blk, len, fn) 222 register char *blk; 223 { 224 register int ret; 225 226 /* call ultouch occasionally -- rti!trt */ 227 if (--tc < 0) { 228 tc = TC; 229 ultouch(); 230 } 231 ret = pkwrite(Pk, blk, len); 232 return ret; 233 } 234