version 1.4, 2019/02/11 21:41:22 |
version 1.5, 2019/02/11 22:22:52 |
|
|
blk_match(struct sess *sess, int fd, |
blk_match(struct sess *sess, int fd, |
const struct blkset *blks, const char *path) |
const struct blkset *blks, const char *path) |
{ |
{ |
int nfd, rc = 0, c; |
int nfd = -1, rc = 0, c; |
struct stat st; |
struct stat st; |
void *map = MAP_FAILED; |
void *map = MAP_FAILED; |
size_t mapsz; |
size_t mapsz; |
|
|
|
|
if ((nfd = open(path, O_RDONLY, 0)) == -1) { |
if ((nfd = open(path, O_RDONLY, 0)) == -1) { |
ERR(sess, "%s: open", path); |
ERR(sess, "%s: open", path); |
return 0; |
goto out; |
} else if (fstat(nfd, &st) == -1) { |
} else if (fstat(nfd, &st) == -1) { |
ERR(sess, "%s: fstat", path); |
ERR(sess, "%s: fstat", path); |
close(nfd); |
goto out; |
return 0; |
|
} |
} |
|
|
/* |
/* |
|
|
map = mmap(NULL, mapsz, PROT_READ, MAP_SHARED, nfd, 0); |
map = mmap(NULL, mapsz, PROT_READ, MAP_SHARED, nfd, 0); |
if (map == MAP_FAILED) { |
if (map == MAP_FAILED) { |
ERR(sess, "%s: mmap", path); |
ERR(sess, "%s: mmap", path); |
close(nfd); |
goto out; |
return 0; |
|
} |
} |
} |
} |
|
|
|
|
*/ |
*/ |
|
|
if (st.st_size && blks->blksz) { |
if (st.st_size && blks->blksz) { |
|
c = blk_match_send(sess, path, fd, map, st.st_size, blks); |
c = blk_match_send(sess, path, |
|
fd, map, st.st_size, blks); |
|
if (!c) { |
if (!c) { |
ERRX1(sess, "blk_match_send"); |
ERRX1(sess, "blk_match_send"); |
goto out; |
goto out; |
|
|
} else { |
} else { |
if (!blk_flush(sess, fd, map, st.st_size, 0)) { |
if (!blk_flush(sess, fd, map, st.st_size, 0)) { |
ERRX1(sess, "blk_flush"); |
ERRX1(sess, "blk_flush"); |
return 0; |
goto out; |
} |
} |
LOG3(sess, "%s: flushed (un-chunked) %jd B, 100%% " |
LOG3(sess, "%s: flushed (un-chunked) %jd B, 100%% upload ratio", |
"upload ratio", path, (intmax_t)st.st_size); |
path, (intmax_t)st.st_size); |
} |
} |
|
|
/* |
/* |
|
|
out: |
out: |
if (map != MAP_FAILED) |
if (map != MAP_FAILED) |
munmap(map, mapsz); |
munmap(map, mapsz); |
close(nfd); |
if (-1 != nfd) |
|
close(nfd); |
return rc; |
return rc; |
} |
} |
|
|