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

Function handle_sock

examples/proxy.c:1036–1079  ·  view source on GitHub ↗

* Our socket request completed, issue a connect request to the other end. */

Source from the content-addressed store, hash-verified

1034 * Our socket request completed, issue a connect request to the other end.
1035 */
1036static int handle_sock(struct io_uring *ring, struct io_uring_cqe *cqe)
1037{
1038 struct conn *c = cqe_to_conn(cqe);
1039 struct io_uring_sqe *sqe;
1040 int ret;
1041
1042 vlog("%d: sock: res=%d\n", c->tid, cqe->res);
1043
1044 c->out_fd = cqe->res;
1045
1046 if (ipv6) {
1047 memset(&c->addr6, 0, sizeof(c->addr6));
1048 c->addr6.sin6_family = AF_INET6;
1049 c->addr6.sin6_port = htons(send_port);
1050 ret = inet_pton(AF_INET6, host, &c->addr6.sin6_addr);
1051 } else {
1052 memset(&c->addr, 0, sizeof(c->addr));
1053 c->addr.sin_family = AF_INET;
1054 c->addr.sin_port = htons(send_port);
1055 ret = inet_pton(AF_INET, host, &c->addr.sin_addr);
1056 }
1057 if (ret <= 0) {
1058 if (!ret)
1059 fprintf(stderr, "host not in right format\n");
1060 else
1061 perror("inet_pton");
1062 return 1;
1063 }
1064
1065 sqe = get_sqe(ring);
1066 if (ipv6) {
1067 io_uring_prep_connect(sqe, c->out_fd,
1068 (struct sockaddr *) &c->addr6,
1069 sizeof(c->addr6));
1070 } else {
1071 io_uring_prep_connect(sqe, c->out_fd,
1072 (struct sockaddr *) &c->addr,
1073 sizeof(c->addr));
1074 }
1075 encode_userdata(sqe, c, __CONNECT, 0, c->out_fd);
1076 if (fixed_files)
1077 sqe->flags |= IOSQE_FIXED_FILE;
1078 return 0;
1079}
1080
1081/*
1082 * Connection to the other end is done, submit a receive to start receiving

Callers 1

handle_cqeFunction · 0.85

Calls 3

cqe_to_connFunction · 0.85
get_sqeFunction · 0.70
encode_userdataFunction · 0.70

Tested by

no test coverage detected