1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "../config-host.h"
/* SPDX-License-Identifier: MIT */
/*
* Description: Test O_NONBLOCK reading from fifo, should result in proper
* retry and a positive read results. Buggy result would be
* -EAGAIN being returned to the user.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "liburing.h"
#include "helpers.h"
int main(int argc, char *argv[])
{
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
struct io_uring ring;
char buf[32];
int fds[2];
int flags;
int ret;
io_uring_queue_init(1, &ring, 0);
if (pipe(fds) < 0) {
perror("pipe");
return T_EXIT_FAIL;
}
flags = fcntl(fds[0], F_GETFL, 0);
if (flags < 0) {
perror("fcntl get");
return T_EXIT_FAIL;
}
flags |= O_NONBLOCK;
ret = fcntl(fds[0], F_SETFL, flags);
if (ret < 0) {
perror("fcntl set");
return T_EXIT_FAIL;
}
sqe = io_uring_get_sqe(&ring);
io_uring_prep_read(sqe, fds[0], buf, sizeof(buf), 0);
io_uring_submit(&ring);
usleep(10000);
ret = write(fds[1], "Hello\n", 6);
if (ret < 0) {
perror("pipe write");
return T_EXIT_FAIL;
}
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret < 0) {
fprintf(stderr, "wait=%d\n", ret);
return T_EXIT_FAIL;
}
if (cqe->res < 0) {
fprintf(stderr, "cqe res %d\n", cqe->res);
return T_EXIT_FAIL;
}
io_uring_cqe_seen(&ring, cqe);
io_uring_queue_exit(&ring);
return T_EXIT_PASS;
}
|