45 static const int pgCsumSize =
sizeof(uint32_t);
47 static const int pgMaxBSize = INT_MAX & ~pgPageMask;
57 int pgOff = offs & pgPageMask;
63 {
size_t chkLen = pgPageSize - pgOff;
64 if (chkLen >= count) {chkLen = count; count = 0;}
78 std::vector<uint32_t> &csvec)
80 int pgOff = offs & pgPageMask;
87 uint32_t *csval = csvec.data();
93 {
size_t chkLen = pgPageSize - pgOff;
94 if (chkLen >= count) {chkLen = count; count = 0;}
111 int k, pgOff = offs & pgPageMask;
116 else {
int chkLen = pgPageSize - pgOff;
117 if (chkLen >= count)
return 1;
124 return k + count/pgPageSize + ((count & pgPageMask) != 0);
131 int pgOff = offs & pgPageMask;
142 if (!pgOff) fLen = (pgPageSize <= (int)count ? pgPageSize : count);
143 else {fLen = pgPageSize - pgOff;
144 if (fLen >= count) fLen = count;
151 {pgOff = count & pgPageMask;
152 lLen = (pgOff ? pgOff : pgPageSize);
153 return 1 + count/pgPageSize + (pgOff != 0);
168 int pgOff = dInfo.
offs & pgPageMask;
172 if (dInfo.
count <= 0)
return true;
179 int chkLen = pgPageSize - pgOff;
181 else dInfo.
count -= chkLen;
185 dInfo.
data += chkLen;
186 tempsave = dInfo.
offs;
187 dInfo.
offs += chkLen;
204 {bado = dInfo.
offs + (pgPageSize * pgNum);
205 int xlen = (bado - dInfo.
offs);
209 badc = (dInfo.
count <= pgPageSize ? dInfo.
count : pgPageSize);
213 dInfo.
csval += (pgNum+1);
229 int csNum, dataLen, maxLen;
233 if (dlen <= pgCsumSize)
234 {layout.
eWhy =
"invalid length";
240 if (bsz <= 0) bsz = pgMaxBSize;
241 else if (bsz & pgPageMask)
242 {layout.
eWhy =
"invalid buffer size (logic error)";
251 if ((layout.
bOffset = offs & pgPageMask))
252 {dataLen = pgPageSize - layout.
bOffset;
259 maxLen = bsz - pgPageSize;
261 layout.
fLen = dataLen;
264 if (dlen <= pgPageSize)
265 {dataLen = layout.
fLen = dlen;
274 layout.
fLen = pgPageSize;
282 {
int bytes = dlen / pgUnitSize * pgPageSize;
283 int bfrag = dlen % pgUnitSize;
285 {
if (bfrag <= pgCsumSize)
286 {layout.
eWhy =
"last page too short";
289 bytes += bfrag - pgCsumSize;
291 if (bytes > maxLen) bytes = maxLen;
293 layout.
lLen = bytes & pgPageMask;
294 csNum += bytes/pgPageSize + (layout.
lLen != 0);
295 if (layout.
lLen == 0) layout.
lLen = pgPageSize;
312 int csNum, pgOff = offs & pgPageMask;
317 {layout.
eWhy =
"invalid length";
323 if (bsz <= 0) bsz = pgMaxBSize;
324 else if (bsz & pgPageMask)
325 {layout.
eWhy =
"invalid buffer size (logic error)";
332 if (!pgOff) layout.
fLen = (pgPageSize <= dlen ? pgPageSize : dlen);
333 else {layout.
fLen = pgPageSize - pgOff;
334 if (layout.
fLen > dlen) layout.
fLen = dlen;
347 {
if (dlen > bsz) dlen = bsz;
348 if ((pgOff = dlen & pgPageMask)) layout.
lLen = pgOff;
349 else layout.
lLen = (pgPageSize <= dlen ? pgPageSize : dlen);
350 csNum = 1 + dlen/pgPageSize + (pgOff != 0);
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
static bool Ver32C(const void *data, size_t count, const uint32_t csval, uint32_t *csbad=0)
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)
off_t bOffset
Buffer offset to apply iov[1].iov_base.
int dataLen
Total number of filesys bytes the iovec will handle.
static int sendLayout(Layout &layout, off_t offs, int dlen, int bsz=0)
int fLen
Length to use for iov[1].iov_len.
static bool csVer(dataInfo &dInfo, off_t &bado, int &badc)
int sockLen
Total number of network bytes the iovec will handle.
const char * eWhy
Reason for failure when zero is returned.
static int csNum(off_t offs, int count)
Compute the required size of a checksum vector based on offset & length.
int lLen
Length to use for iov[csnum*2-1].iov_len)
static int recvLayout(Layout &layout, off_t offs, int dlen, int bsz=0)
Compute the layout for an iovec that receives network bytes applying.
static const int kXR_pgPageSZ
const char * data
Pointer to data buffer.
int count
Number of bytes to check.
const uint32_t * csval
Pointer to vector of checksums.
off_t offs
Offset associated with data.