Codebase list mbuffer / 7d92004
New upstream version 20211004+ds1 Peter Pentchev 2 years ago
8 changed file(s) with 92 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
00 repo: 6e3b485d74645931e2408ed1f57e659029b5639a
1 node: 5a083db6c04c3286fabaa5e75021ee1d4e4ca3db
1 node: 3b8642c23858eaa90737280ac2c0cd0761ecb62a
22 branch: default
3 latesttag: R20210829
4 latesttagdistance: 1
5 changessincelatesttag: 1
3 tag: R20211004
0 20211004:
1 - make TCPTimeout=0 disable the TCP timeout
2 - changed default TCP timeout from 10s to 100s
3 - TCP timeout now can be give with suffixes ms,s,min,h
4 - documented option for TCP timeout
5
06 20210829:
17 - enhancement: accept IPv6 addresses in square bracket format
28 - enhancement: more detailed warning message for connect failures
142142 fail with 'no space left', indicating the real end of the tape. This will allow
143143 a little extra data to fit on each tape.
144144 .TP
145 \fB\-\-tcptimeo\fR <\fItime\fP>
146 Set the TCP timeout threshold. The default value is 10s. Arguments
147 without dimension are interpreted as usec. Argument dimensions can be
148 us, ms, s or sec, m or min, h.
145149 \fB\-6\fR
146150 Force IPv6 mode for the following network I/O options on command line.
147151 \fB\-4\fR
7272 # TCPbufsize = 0
7373
7474 ## TCP transmission timeout [msec]
75 # TCPtimeout = 0
75 # accepts dimensions sec,s,ms,us,min,h
76 # TCPtimeout = 100s
7677
7778 ## tape aware out-of-space handling
7879 ## valid values are: true, false, 0, 1, on, off
0 #!/bin/bash -x
0 #!/bin/bash
11
22 VERSION_H=${1:-version.h}
33 NEWFILE=`mktemp -t version.h.XXXXXXXXXX`
2424
2525
2626 #include <errno.h>
27 #include <math.h>
2728 #include <netdb.h>
2829 #include <net/if.h>
2930 #include <stdio.h>
4344 #include "settings.h"
4445 #include "log.h"
4546
46 int32_t TCPBufSize = 0, TCPTimeout = 10000000;
47 int32_t TCPBufSize = 0;
48 double TCPTimeout = 100;
4749 #if defined(PF_INET6) && defined(PF_UNSPEC)
4850 int AddrFam = PF_UNSPEC;
4951 #else
247249 if (TCPBufSize)
248250 setTCPBufferSize(In,SO_RCVBUF);
249251 struct timeval timeo;
250 timeo.tv_sec = TCPTimeout/1000000;
251 timeo.tv_usec = TCPTimeout%1000000;
252 timeo.tv_sec = floor(TCPTimeout);
253 timeo.tv_usec = TCPTimeout-timeo.tv_sec*1000000;
252254 if (-1 == setsockopt(In, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)))
253255 warningmsg("cannot set socket send timeout: %s\n",strerror(errno));
256 else
257 debugmsg("disabled TCP receive timeout\n");
254258 (void) close(sock);
255259 }
256260
306310 } else {
307311 if (TCPBufSize)
308312 setTCPBufferSize(fd,SO_SNDBUF);
309 struct timeval timeo;
310 timeo.tv_sec = TCPTimeout/1000000;
311 timeo.tv_usec = TCPTimeout%1000000;
312 if (-1 == setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)))
313 warningmsg("cannot set socket send timeout: %s\n",strerror(errno));
313 if (TCPTimeout) {
314 struct timeval timeo;
315 timeo.tv_sec = floor(TCPTimeout);
316 timeo.tv_usec = (TCPTimeout-timeo.tv_sec)*1E6;
317 if (-1 == setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)))
318 warningmsg("cannot set socket send timeout: %s\n",strerror(errno));
319 } else {
320 debugmsg("disabled TCP send timeout\n");
321 }
314322 }
315323 d = (dest_t *) malloc(sizeof(dest_t));
316324 d->arg = addr;
381389 if (host[0] == 0) {
382390 infomsg("accepted connection from %s\n",inet_ntoa(caddr.sin_addr));
383391 (void) close(sock);
384 struct timeval timeo;
385 timeo.tv_sec = TCPTimeout/1000000;
386 timeo.tv_usec = TCPTimeout%1000000;
387 if (-1 == setsockopt(In, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)))
388 warningmsg("cannot set socket send timeout: %s\n",strerror(errno));
392 if (TCPTimeout) {
393 struct timeval timeo;
394 timeo.tv_sec = floor(TCPTimeout);
395 timeo.tv_usec = (TCPTimeout-timeo.tv_sec)*1000000;
396 if (-1 == setsockopt(In, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)))
397 warningmsg("cannot set socket send timeout: %s\n",strerror(errno));
398 else
399 infomsg("set TCP receive timeout to %usec, %uusec\n",timeo.tv_sec,timeo.tv_usec);
400 } else {
401 debugmsg("disabled TCP receive timeout\n");
402 }
389403 return;
390404 }
391405 for (p = h->h_addr_list; *p; ++p) {
489503 errormsg("could not connect to %s:%s: %s\n",dest->name,dest->port,dest->result);
490504 (void) close(out);
491505 out = -1;
492 } else {
506 } else if (TCPTimeout) {
493507 struct timeval timeo;
494 timeo.tv_sec = TCPTimeout/1000000;
495 timeo.tv_usec = TCPTimeout%1000000;
508 timeo.tv_sec = floor(TCPTimeout);
509 timeo.tv_usec = (TCPTimeout-timeo.tv_sec)*1000000;
496510 if (-1 == setsockopt(out, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)))
497511 warningmsg("cannot set socket send timeout: %s\n",strerror(errno));
512 else
513 infomsg("set TCP transmit timeout to %usec, %uusec\n",timeo.tv_sec,timeo.tv_usec);
514 } else {
515 debugmsg("disabled TCP transmint timeout\n");
516
498517 }
499518 dest->fd = out;
500519 }
9494 *Tmpfile = 0;
9595
9696 extern void *watchdogThread(void *ignored);
97
9798
9899 static const char *calcval(const char *arg, unsigned long long *res)
99100 {
154155 }
155156
156157
158 static double calctime(const char *str, double def)
159 {
160 char dim[8];
161 double d = (double)def;
162
163 dim[0] = 0;
164 int n = sscanf(str,"%lf%7s",&d,dim);
165 if ((n <= 0) || (n > 2)) {
166 errormsg("invalid time argument \"%s\"\n",str);
167 d = def;
168 }
169 if (0 == dim[0]) {
170 d *= 1E-3;
171 } else if (0 == strcmp(dim,"ms")) {
172 d *= 1E-3;
173 } else if (0 == strcmp(dim,"msec")) {
174 d *= 1E-3;
175 } else if (0 == strcmp(dim,"s")) {
176
177 } else if (0 == strcmp(dim,"m")) {
178 d *= 60;
179 } else if (0 == strcmp(dim,"min")) {
180 d *= 60;
181 } else if (0 == strcmp(dim,"h")) {
182 d *= 60 * 60;
183 } else {
184 errormsg("invalid time dimension in argument \"%s\"\n",str);
185 d = def;
186 }
187 return d;
188 }
189
190
157191 static int isEmpty(const char *l)
158192 {
159193 while (*l) {
408442 TCPBufSize = value;
409443 debugmsg("TCPBufSize = %lu\n",TCPBufSize);
410444 } else if (strcasecmp(key,"tcptimeout") == 0) {
411 TCPTimeout = value;
412 debugmsg("TCPTimeout = %lu\n",TCPTimeout);
445 TCPTimeout = calctime(valuestr,TCPTimeout);
446 debugmsg("TCPTimeout = %f\n",TCPTimeout);
413447 } else {
414448 warningmsg("unknown parameter: %s\n",key);
415449 }
640674 );
641675 exit(EXIT_SUCCESS);
642676 }
677
643678
644679
645680 static unsigned long long calcint(const char **argv, int c, unsigned long long def)
759794 TCPBufSize = calcint(argv,++c,TCPBufSize);
760795 debugmsg("TCPBufSize = %lu\n",TCPBufSize);
761796 } else if (!strcmp("--tcptimeo",argv[c])) {
762 TCPTimeout = calcint(argv,++c,TCPTimeout);
763 debugmsg("TCPTimeout = %lu\n",TCPTimeout);
797 TCPTimeout = calctime(argv[++c],TCPTimeout);
798 debugmsg("TCPTimeout = %lf\n",TCPTimeout);
764799 } else if (!strcmp("--tapeaware",argv[c])) {
765800 TapeAware = 1;
766801 debugmsg("sensing early end-of-tape warning\n");
00 /*
1 * Copyright (C) 2000-2020, Thomas Maier-Komor
1 * Copyright (C) 2000-2021, Thomas Maier-Komor
22 *
33 * This is the source code of mbuffer.
44 *
2222 #include <time.h>
2323 #include <sys/types.h>
2424
25 extern int32_t TCPBufSize, TCPTimeout;
25 extern int32_t TCPBufSize;
26 extern double TCPTimeout;
2627
2728 extern clockid_t
2829 ClockSrc;