Skip to content

Commit

Permalink
examples/reg-wait: cleanup and comments
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Nov 2, 2024
1 parent abe992c commit d32b261
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/reg-wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <assert.h>
#include <liburing.h>

static unsigned long long mtime_since(const struct timeval *s, const struct timeval *e)
static unsigned long long mtime_since(const struct timeval *s,
const struct timeval *e)
{
long long sec, usec;

Expand Down Expand Up @@ -123,17 +124,26 @@ int main(int argc, char *argv[])
/* trigger one read */
write(fds[1], "Hello", 5);

/*
* This should will wait for 2 entries, where 1 is already available.
* Since we're using min_wait_usec == 10 msec here with an overall
* wait of 100 msec, we expect the wait to abort after 10 msec since
* one or more events are available.
*/
gettimeofday(&tv, NULL);
ret = io_uring_submit_and_wait_reg(&ring, cqe, 2, 1);
msec = mtime_since_now(&tv);
if (ret != 2) {
fprintf(stderr, "Should have submitted 2: %d\n", ret);
return 1;
}
if (msec < 8 || msec > 12) {
if (msec < 8 || msec > 12)
fprintf(stderr, "min_wait_usec should take ~10 msec: %lu\n", msec);
return 1;
}

/*
* Cleanup after ourselves
*/
io_uring_queue_exit(&ring);
io_uring_free_reg_wait(reg, 32);
return 0;
}

0 comments on commit d32b261

Please sign in to comment.