Skip to content

Commit

Permalink
handle eintr
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Jan 10, 2025
1 parent 5bb86f8 commit 09a5d56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
12 changes: 12 additions & 0 deletions msgq/visionipc/handle_eintr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

// keep trying if x gets interrupted by a signal
#define HANDLE_EINTR(x) \
({ \
decltype(x) ret; \
int try_cnt = 0; \
do { \
ret = (x); \
} while (ret == -1 && errno == EINTR && try_cnt++ < 100); \
ret; \
})
12 changes: 1 addition & 11 deletions msgq/visionipc/visionbuf_ion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@
#include <msm_ion.h>

#include "msgq/visionipc/visionbuf.h"

// keep trying if x gets interrupted by a signal
#define HANDLE_EINTR(x) \
({ \
decltype(x) ret; \
int try_cnt = 0; \
do { \
ret = (x); \
} while (ret == -1 && errno == EINTR && try_cnt++ < 100); \
ret; \
})
#include "msgq/visionipc/handle_eintr.h"

// just hard-code these for convenience
// size_t device_page_size = 0;
Expand Down
7 changes: 4 additions & 3 deletions msgq/visionipc/visionipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define getsocket() socket(AF_UNIX, SOCK_SEQPACKET, 0)
#endif

#include "msgq/visionipc/handle_eintr.h"
#include "msgq/visionipc/visionipc.h"

int ipc_connect(const char* socket_path) {
Expand All @@ -27,7 +28,7 @@ int ipc_connect(const char* socket_path) {
.sun_family = AF_UNIX,
};
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path);
err = connect(sock, (struct sockaddr*)&addr, sizeof(addr));
err = HANDLE_EINTR(connect(sock, (struct sockaddr*)&addr, sizeof(addr)));
if (err != 0) {
close(sock);
return -1;
Expand Down Expand Up @@ -87,9 +88,9 @@ int ipc_sendrecv_with_fds(bool send, int fd, void *buf, size_t buf_size, int* fd
cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds);
memcpy(CMSG_DATA(cmsg), fds, sizeof(int) * num_fds);
}
return sendmsg(fd, &msg, 0);
return HANDLE_EINTR(sendmsg(fd, &msg, 0));
} else {
int r = recvmsg(fd, &msg, 0);
int r = HANDLE_EINTR(recvmsg(fd, &msg, 0));
if (r < 0) return r;

int recv_fds = 0;
Expand Down

0 comments on commit 09a5d56

Please sign in to comment.