Skip to content

Commit 23159e1

Browse files
committed
Let raft_recv_message restart quietly in case of EINTR.
1 parent ab1865e commit 23159e1

File tree

1 file changed

+13
-12
lines changed
  • contrib/raftable/raft/src

1 file changed

+13
-12
lines changed

contrib/raftable/raft/src/raft.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,9 @@ static char buf[UDP_SAFE_SIZE];
11281128

11291129
raft_msg_t raft_recv_message(raft_t r) {
11301130
struct sockaddr_in addr;
1131-
unsigned int addrlen = sizeof(addr);
1131+
unsigned int addrlen;
1132+
tryagain:
1133+
addrlen = sizeof(addr);
11321134

11331135
//try to receive some data
11341136
raft_msg_t m = (raft_msg_t)buf;
@@ -1137,17 +1139,16 @@ raft_msg_t raft_recv_message(raft_t r) {
11371139
(struct sockaddr*)&addr, &addrlen
11381140
);
11391141

1140-
if (recved <= 0) {
1141-
if (
1142-
(errno == EAGAIN) ||
1143-
(errno == EWOULDBLOCK) ||
1144-
(errno == EINTR)
1145-
) {
1146-
return NULL;
1147-
} else {
1148-
shout("failed to recv: %s\n", strerror(errno));
1149-
return NULL;
1150-
}
1142+
if (recved < 0) {
1143+
if (errno == EINTR) goto tryagain;
1144+
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) return NULL;
1145+
shout("failed to recv: %s\n", strerror(errno));
1146+
return NULL;
1147+
}
1148+
1149+
if (recved == 0) {
1150+
shout("failed to recv: recved 0 bytes\n");
1151+
return NULL;
11511152
}
11521153

11531154
if (!msg_size_is(m, recved)) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy