01:
02:
03: #ifndef _LocalReadCheck_HH
04: #define _LocalReadCheck_HH 1
05:
06: #include <unistd.h>
07: #include <sys/uio.h>
08:
09: #include "RZError.hh"
10: #include "RZMagic.hh"
11:
12: namespace RZ {
13: inline void readv_check(
14: struct Sums const * const sums, unsigned int &chkc, int &l,
15: int const givenfd, struct iovec *vbase, unsigned int vlen)
16: {
17: if (l >= 0) return;
18: while (vlen) {
19: int r;
20: do r = readv(givenfd, vbase, vlen);
21: while (r == -1 && errno == EINTR);
22: IOError::what_if("Can't read given for scan!");
23: if (!r) return;
24: for (; vlen; ++vbase, --vlen) {
25: unsigned int a = std::min(vbase->iov_len, (unsigned int)r);
26: unsigned int b = std::min<unsigned int>(a, -l);
27: sums->c.accumulate((char *)(vbase->iov_base), b, chkc);
28: l += a;
29: if (l >= 0) return;
30:
31: if (vbase->iov_len <= (unsigned int)r)
32: r -= vbase->iov_len;
33: else {
34: vbase->iov_base = (char *)(vbase->iov_base) + r;
35: vbase->iov_len -= r;
36: break;
37: }
38: }
39: }
40: }
41:
42: inline void read_check(
43: struct Sums const * const sums, unsigned int &chkc, int &l,
44: int const givenfd, char *buffer, unsigned int size)
45: {
46: if (l >= 0) return;
47: while (size) {
48: int r;
49: do r = read(givenfd, buffer, size);
50: while (r == -1 && errno == EINTR);
51: IOError::what_if("Can't read given for scan!");
52: if (!r) return;
53: sums->c.accumulate(buffer, std::min<unsigned int>(r, -l), chkc);
54: l += (unsigned int)r;
55: if (l >= 0) return;
56: buffer += (unsigned int)r;
57: size -= (unsigned int)r;
58: }
59: }
60: }
61:
62:
63:
64: #endif