MCPcopy Create free account
hub / github.com/axboe/liburing / test

Function test

test/socket-nb.c:24–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22#include "helpers.h"
23
24static int test(int o_nonblock, int msg_dontwait)
25{
26 int p_fd[2], ret, flags, recv_s0, val;
27 struct io_uring_sqe *sqe;
28 struct io_uring_cqe *cqe;
29 struct sockaddr_in addr;
30 struct io_uring ring;
31 char recv_buff[128];
32
33 recv_s0 = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
34
35 val = 1;
36 ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val));
37 assert(ret != -1);
38 ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
39 assert(ret != -1);
40
41 addr.sin_family = AF_INET;
42 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
43 ret = t_bind_ephemeral_port(recv_s0, &addr);
44 assert(!ret);
45 ret = listen(recv_s0, 128);
46 assert(ret != -1);
47
48 p_fd[1] = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
49
50 val = 1;
51 ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
52 assert(ret != -1);
53
54 t_set_nonblock(p_fd[1]);
55
56 ret = connect(p_fd[1], (struct sockaddr *) &addr, sizeof(addr));
57 assert(ret == -1);
58
59 p_fd[0] = accept(recv_s0, NULL, NULL);
60 assert(p_fd[0] != -1);
61
62 if (o_nonblock)
63 t_set_nonblock(p_fd[0]);
64
65 while (1) {
66 int32_t code;
67 socklen_t code_len = sizeof(code);
68
69 ret = getsockopt(p_fd[1], SOL_SOCKET, SO_ERROR, &code, &code_len);
70 assert(ret != -1);
71
72 if (!code)
73 break;
74 }
75
76 ret = io_uring_queue_init(32, &ring, 0);
77 assert(ret >= 0);
78
79 flags = msg_dontwait ? MSG_DONTWAIT : 0;
80 sqe = io_uring_get_sqe(&ring);
81 io_uring_prep_recv(sqe, p_fd[0], recv_buff, sizeof(recv_buff), flags);

Callers 1

mainFunction · 0.70

Calls 6

t_bind_ephemeral_portFunction · 0.85
t_set_nonblockFunction · 0.85
io_uring_queue_initFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_queue_exitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected