Skip to content

Commit

Permalink
Try support larger number of connections
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Feb 6, 2020
1 parent d2ec7e6 commit 779ce10
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions io_uring_echo_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef struct conn_info

conn_info conns[MAX_CONNECTIONS];
struct iovec iovecs[MAX_CONNECTIONS];
struct msghdr msgs[MAX_CONNECTIONS];
char bufs[MAX_CONNECTIONS][MAX_MESSAGE_LEN];

int main(int argc, char *argv[])
Expand All @@ -55,6 +56,8 @@ int main(int argc, char *argv[])
{
// global variables are initialized to zero by default
iovecs[i].iov_base = bufs[i];
msgs[i].msg_iov = &iovecs[i];
msgs[i].msg_iovlen = 1;
}


Expand Down Expand Up @@ -85,7 +88,7 @@ int main(int argc, char *argv[])

// initialize io_uring
struct io_uring ring;
io_uring_queue_init(32, &ring, 0);
io_uring_queue_init(MAX_CONNECTIONS, &ring, 0);


// add first io_uring poll sqe, to check when there will be data available on sock_listen_fd
Expand Down Expand Up @@ -183,7 +186,7 @@ void add_socket_read(struct io_uring* ring, int fd, size_t size, int type) {

struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
iovecs[fd].iov_len = size;
io_uring_prep_readv(sqe, fd, &iovecs[fd], 1, 0);
io_uring_prep_recvmsg(sqe, fd, &msgs[fd], MSG_NOSIGNAL);

conn_info *conn_i = &conns[fd];
conn_i->fd = fd;
Expand All @@ -196,7 +199,7 @@ void add_socket_write(struct io_uring* ring, int fd, size_t size, int type) {

struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
iovecs[fd].iov_len = size;
io_uring_prep_writev(sqe, fd, &iovecs[fd], 1, 0);
io_uring_prep_sendmsg(sqe, fd, &msgs[fd], MSG_NOSIGNAL);

conn_info *conn_i = &conns[fd];
conn_i->fd = fd;
Expand Down

1 comment on commit 779ce10

@frevib
Copy link
Owner

@frevib frevib commented on 779ce10 Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you getter better performance with sendmsg/recvmsg? We might have to wait until Linux 5.6, will support send/recv.

Please sign in to comment.