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

Function connect_socket

test/connect.c:136–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136static int connect_socket(struct io_uring *ring, int fd, int *code, int async)
137{
138 struct sockaddr_in addr;
139 int ret, res;
140 socklen_t code_len = sizeof(*code);
141 struct io_uring_sqe *sqe;
142
143 if (configure_connect(fd, &addr) == -1)
144 return -1;
145
146 sqe = io_uring_get_sqe(ring);
147 if (!sqe) {
148 fprintf(stderr, "unable to get sqe\n");
149 return -1;
150 }
151
152 io_uring_prep_connect(sqe, fd, (struct sockaddr*)&addr, sizeof(addr));
153 if (async)
154 sqe->flags |= IOSQE_ASYNC;
155 sqe->user_data = 1;
156
157 ret = submit_and_wait(ring, &res);
158 if (ret)
159 return -1;
160
161 if (res == -EINPROGRESS) {
162 ret = wait_for(ring, fd, POLLOUT | POLLHUP | POLLERR);
163 if (ret == -1)
164 return -1;
165
166 int ev = (ret & POLLOUT) || (ret & POLLHUP) || (ret & POLLERR);
167 if (!ev) {
168 fprintf(stderr, "poll(): returned invalid value %#x\n", ret);
169 return -1;
170 }
171
172 ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, code, &code_len);
173 if (ret == -1) {
174 perror("getsockopt()");
175 return -1;
176 }
177 } else
178 *code = res;
179 return 0;
180}
181
182static int test_connect_with_no_peer(struct io_uring *ring)
183{

Callers 3

test_connectFunction · 0.85
test_connect_timeoutFunction · 0.85

Calls 4

configure_connectFunction · 0.85
submit_and_waitFunction · 0.85
wait_forFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by 3

test_connectFunction · 0.68
test_connect_timeoutFunction · 0.68