Minor refactoring
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 2m1s
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 2m1s
Accept connections until there are no more connections to accept in a single iteration.
This commit is contained in:
parent
9ff991d907
commit
a27930de85
1 changed files with 37 additions and 31 deletions
|
@ -560,11 +560,14 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
socket_len = sizeof(struct sockaddr_in6);
|
||||
while (1) {
|
||||
ret = accept(tcp_socket, (struct sockaddr *)&peer_info, &socket_len);
|
||||
if (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
|
||||
// No connecting peers, do nothing.
|
||||
break;
|
||||
} else if (ret == -1) {
|
||||
printf("WARNING: accept: errno %d\n", errno);
|
||||
break;
|
||||
} else if (ret >= 0) {
|
||||
// Received connection, handle it.
|
||||
if ((args.flags & 1) == 0) {
|
||||
|
@ -579,7 +582,8 @@ int main(int argc, char **argv) {
|
|||
// Set non-blocking.
|
||||
ret = fcntl(connection_fd, F_SETFL, O_NONBLOCK);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ERROR Failed to set non-blocking on connection fd!\n");
|
||||
fprintf(
|
||||
stderr, "ERROR Failed to set non-blocking on connection fd!\n");
|
||||
close(connection_fd);
|
||||
continue;
|
||||
}
|
||||
|
@ -593,6 +597,8 @@ int main(int argc, char **argv) {
|
|||
c_simple_http_cleanup_connection_item);
|
||||
} else {
|
||||
printf("WARNING: accept: Unknown invalid state!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &connection_context.current_time);
|
||||
|
|
Loading…
Reference in a new issue