Fix EINTR handling
This commit is contained in:
@@ -85,11 +85,19 @@ int getConnectFd(const char *node, const char *service) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (connect(sfd, rp->ai_addr, rp->ai_addrlen) == 0) {
|
||||
int conn_result;
|
||||
do {
|
||||
conn_result = connect(sfd, rp->ai_addr, rp->ai_addrlen);
|
||||
} while (conn_result == -1 && errno == EINTR);
|
||||
|
||||
if (conn_result == 0) {
|
||||
break; /* Success */
|
||||
}
|
||||
|
||||
close(sfd);
|
||||
int e;
|
||||
do {
|
||||
e = close(sfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
}
|
||||
|
||||
freeaddrinfo(result); /* No longer needed */
|
||||
@@ -113,7 +121,10 @@ int getConnectFdUnix(const char *socket_name) {
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, socket_name, sizeof(addr.sun_path) - 1);
|
||||
int e = connect(sfd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
int e;
|
||||
do {
|
||||
e = connect(sfd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
} while (e == -1 && errno == EINTR);
|
||||
if (e == -1) {
|
||||
perror("connect");
|
||||
abort();
|
||||
@@ -241,7 +252,10 @@ struct Connection {
|
||||
bool error = false;
|
||||
|
||||
~Connection() {
|
||||
int e = close(fd);
|
||||
int e;
|
||||
do {
|
||||
e = close(fd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
if (e == -1) {
|
||||
perror("close");
|
||||
abort();
|
||||
@@ -711,7 +725,9 @@ int main(int argc, char *argv[]) {
|
||||
while (!g_shutdown.load(std::memory_order_relaxed)) {
|
||||
int e;
|
||||
{
|
||||
e = sem_wait(&connectionLimit);
|
||||
do {
|
||||
e = sem_wait(&connectionLimit);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
if (e == -1) {
|
||||
perror("sem_wait");
|
||||
abort();
|
||||
@@ -814,6 +830,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Clean up epoll file descriptors
|
||||
for (int epollfd : g_epoll_fds) {
|
||||
close(epollfd);
|
||||
int e;
|
||||
do {
|
||||
e = close(epollfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user