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

Function handle_accept

examples/proxy.c:973–1031  ·  view source on GitHub ↗

* Multishot accept completion triggered. If we're acting as a sink, we're * good to go. Just issue a receive for that case. If we're acting as a proxy, * then start opening a socket that we can use to connect to the other end. */

Source from the content-addressed store, hash-verified

971 * then start opening a socket that we can use to connect to the other end.
972 */
973static int handle_accept(struct io_uring *ring, struct io_uring_cqe *cqe)
974{
975 struct conn *c;
976 int i;
977
978 if (nr_conns == MAX_CONNS) {
979 fprintf(stderr, "max clients reached %d\n", nr_conns);
980 return 1;
981 }
982
983 /* main thread handles this, which is obviously serialized */
984 c = &conns[nr_conns];
985 c->tid = nr_conns++;
986 c->in_fd = -1;
987 c->out_fd = -1;
988
989 for (i = 0; i < 2; i++) {
990 struct conn_dir *cd = &c->cd[i];
991
992 cd->index = i;
993 cd->snd_next_bid = -1;
994 cd->rcv_next_bid = -1;
995 if (ext_stat) {
996 cd->rcv_bucket = calloc(nr_bufs + 1, sizeof(int));
997 cd->snd_bucket = calloc(nr_bufs + 1, sizeof(int));
998 }
999 init_msgs(cd);
1000 }
1001
1002 printf("New client: id=%d, in=%d\n", c->tid, c->in_fd);
1003 gettimeofday(&c->start_time, NULL);
1004
1005 pthread_barrier_init(&c->startup_barrier, NULL, 2);
1006 pthread_create(&c->thread, NULL, thread_main, c);
1007
1008 /*
1009 * Wait for thread to have its ring setup, then either assign the fd
1010 * if it's non-fixed, or pass the fixed one
1011 */
1012 pthread_barrier_wait(&c->startup_barrier);
1013 if (!fixed_files) {
1014 c->in_fd = cqe->res;
1015 } else {
1016 struct io_uring_sqe *sqe;
1017 uint64_t user_data;
1018
1019 /*
1020 * Ring has just been setup, we'll use index 0 as the descriptor
1021 * value.
1022 */
1023 user_data = __raw_encode(c->tid, __FD_PASS, 0, 0);
1024 sqe = io_uring_get_sqe(ring);
1025 io_uring_prep_msg_ring_fd(sqe, c->ring.ring_fd, cqe->res, 0,
1026 user_data, 0);
1027 encode_userdata(sqe, c, __NOP, 0, cqe->res);
1028 }
1029
1030 return 0;

Callers 1

handle_cqeFunction · 0.70

Calls 4

init_msgsFunction · 0.85
__raw_encodeFunction · 0.85
encode_userdataFunction · 0.70
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected