Re: io_uring process termination/killing is not working

Josef
2020-08-16T00:37:06Z

[-- Attachment #1: Type: text/plain, Size: 375 bytes --]

> Please try:
>
> https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-5.9&id=41d3344604e80db0e466f9deca5262b0914e4827
>
> There was a bug with the -EAGAIN doing repeated retries on sockets that
> are marked non-blocking.
>

no it's not working, however I received the read event after
the second request (instead of the third request before) via Telnet

--
Josef Grieb

[-- Attachment #2: io_uring_read_issue.c --]
[-- Type: text/x-c-code, Size: 2619 bytes --]

#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/socket.h>
#include <unistd.h>
#include <poll.h>
#include "liburing.h"

#define BACKLOG 512

#define PORT 9700

struct io_uring ring;

char buf[100];

void add_poll(int fd, unsigned int poll_mask) {
struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
io_uring_prep_poll_add(sqe, fd, poll_mask);
sqe->user_data = 1;
sqe->flags |= IOSQE_IO_LINK;
}

void add_accept(int fd) {
struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
io_uring_prep_accept(sqe, fd, 0, 0, SOCK_NONBLOCK | SOCK_CLOEXEC);
sqe->user_data = 2;
}

void add_read(int fd) {
struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
io_uring_prep_read(sqe, fd, &buf, 100, 0);
sqe->user_data = 3;
}

int setup_io_uring() {
int ret = io_uring_queue_init(16, &ring, 0);
if (ret) {
fprintf(stderr, "Unable to setup io_uring: %s\n", strerror(-ret));
return 1;
}
return 0;
}

int main(int argc, char *argv[]) {

struct sockaddr_in serv_addr;

setup_io_uring();

int sock_listen_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
const int val = 1;
setsockopt(sock_listen_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));

memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
serv_addr.sin_addr.s_addr = INADDR_ANY;

if (bind(sock_listen_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("Error binding socket\n");
exit(1);
}
if (listen(sock_listen_fd, BACKLOG) < 0) {
perror("Error listening on socket\n");
exit(1);
}

setup_io_uring();

add_poll(sock_listen_fd, POLLIN);
add_accept(sock_listen_fd);
io_uring_submit(&ring);

while (1) {
struct io_uring_cqe *cqe;
io_uring_wait_cqe(&ring, &cqe);

printf("Res: res: %d\n", cqe->res);

if (cqe->user_data == 1) {
printf("Poll Event\n");
}

if (cqe->user_data == 2 && cqe->res > 0) {
printf("Accept Event\n");

add_poll(sock_listen_fd, POLLIN);
add_accept(sock_listen_fd);

add_poll(cqe->res, POLLIN);
add_read(cqe->res);
}

if (cqe->user_data == 3) {
printf("Read Buf: %s \n", buf);
}
io_uring_submit(&ring);

io_uring_cqe_seen(&ring, cqe);
}

io_uring_queue_exit(&ring);

return 0;
}