Skip to content

Commit

Permalink
examples/kdigest: reuse I/O buffer for hash result
Browse files Browse the repository at this point in the history
Signed-off-by: David Disseldorp <ddiss@suse.de>
  • Loading branch information
ddiss committed Oct 3, 2024
1 parent 6f310e3 commit 68b45a4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/kdigest.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,16 @@ static int digest_file(struct kdigest *kdigest, size_t insize)
return 0;
}

static int get_result(struct io_uring *ring, const char *alg, const char *file)
static int get_result(struct kdigest *kdigest, const char *alg, const char *file)
{
struct io_uring *ring = &kdigest->ring;
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
int i, ret;
/* buffer must be large enough to carry longest hash result */
uint8_t buf[128];
/* reuse I/O buf block to stash hash result */

sqe = io_uring_get_sqe(ring);
io_uring_prep_recv(sqe, outfd, buf, sizeof(buf), 0);
io_uring_prep_recv(sqe, outfd, kdigest->bufs, BS, 0);

if (io_uring_submit_and_wait(ring, 1) < 0)
return 1;
Expand All @@ -280,7 +280,7 @@ static int get_result(struct io_uring *ring, const char *alg, const char *file)

fprintf(stdout, "uring %s(%s) returned(len=%u): ", alg, file, cqe->res);
for (i = 0; i < cqe->res; i++)
fprintf(stdout, "%02x", buf[i]);
fprintf(stdout, "%02x", kdigest->bufs[i]);
putc('\n', stdout);
ret = 0;
err:
Expand Down Expand Up @@ -384,7 +384,7 @@ int main(int argc, char *argv[])
return 1;
}

ret = get_result(&kdigest.ring, alg, infile);
ret = get_result(&kdigest, alg, infile);
if (ret) {
fprintf(stderr, "failed to retrieve %s digest result\n", alg);
return 1;
Expand Down

0 comments on commit 68b45a4

Please sign in to comment.