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

Function sender

test/napi-test.c:40–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40static int sender(int queue_flags)
41{
42 unsigned long long written = 0;
43 struct sockaddr_in addr;
44 struct io_uring ring;
45 int i, ret, fd;
46
47 /*
48 * Sender doesn't use the ring, but try and set one up with the same
49 * flags that the receiver will use. If that fails, we know the
50 * receiver will have failed too - just skip the test in that case.
51 */
52 ret = io_uring_queue_init(1, &ring, queue_flags);
53 if (ret)
54 return T_EXIT_SKIP;
55 io_uring_queue_exit(&ring);
56
57 memset(&addr, 0, sizeof(addr));
58 addr.sin_family = AF_INET;
59 addr.sin_port = htons(port);
60 ret = inet_pton(AF_INET, receiver_address, &addr.sin_addr);
61 assert(ret == 1);
62
63 fd = socket(PF_INET, SOCK_STREAM, 0);
64 assert(fd >= 0);
65
66 /* don't race with receiver, give it 1 second to connect */
67 i = 0;
68 do {
69 ret = connect(fd, (void *)&addr, sizeof(addr));
70 if (!ret)
71 break;
72 if (ret == -1 && errno == ECONNREFUSED) {
73 if (i >= 10000) {
74 fprintf(stderr, "Gave up trying to connect\n");
75 return 1;
76 }
77 usleep(100);
78 continue;
79 }
80 i++;
81 } while (1);
82
83 while (written < 8 * 1024 * 1024) {
84 for (i = 0; i < BUF_SIZE; i++)
85 buffer[i] = current_byte + i;
86
87 ret = write(fd, buffer, BUF_SIZE);
88 if (ret <= 0) {
89 if (!ret || errno == ECONNRESET)
90 break;
91 fprintf(stderr, "write failed %i %i\n", ret, errno);
92 return 1;
93 }
94 written += ret;
95 current_byte += ret;
96 }
97

Callers 1

mainFunction · 0.85

Calls 2

io_uring_queue_initFunction · 0.85
io_uring_queue_exitFunction · 0.85

Tested by

no test coverage detected