Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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)