Skip to content

Commit 3f0f6bf

Browse files
committed
hm2_eth posix: Back to polling recv
ppoll has issues with barely realtime capable systems, most probably if the CPU is not kept busy constantly, it clocks down or goes to a sleep state.
1 parent 062dc7c commit 3f0f6bf

1 file changed

Lines changed: 10 additions & 24 deletions

File tree

‎src/hal/drivers/mesa-hostmot2/hm2_eth_net_posix.c‎

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -161,30 +161,16 @@ int hm2_posix_eth_socket_send(hm2_eth_t *board, const void *buffer, int len) {
161161
}
162162

163163
int hm2_posix_eth_socket_recv(hm2_eth_t *board, void *buffer, int len, int recv_timeout_ns) {
164-
struct pollfd pfd;
165-
struct timespec ts;
166164
int ret;
167-
168-
//SO_RCVTIMEO only delivers a timeout down to ~10ms
169-
//while ppoll() works down to 100us
170-
pfd.fd=board->sockfd;
171-
pfd.events = POLLIN;
172-
ts.tv_sec = 0;
173-
ts.tv_nsec = recv_timeout_ns;
174-
while (ts.tv_nsec >= 1e9) {
175-
ts.tv_nsec -= 1e9;
176-
ts.tv_sec ++;
177-
}
178-
ret = ppoll(&pfd, 1, &ts, NULL);
179-
180-
if (ret < 0) {
181-
LL_PRINT("ERROR: ppoll() failed: %m\n");
182-
} else if(ret) {
183-
ret = recv(board->sockfd, buffer, len, 0);
184-
} else {
185-
errno = EAGAIN;
186-
ret = -1;
187-
}
188-
165+
//Note: Do not use ppoll here. It increases the read time on
166+
//badly tuned PC's. Most probably due to the CPU goes to sleep
167+
//states or clocks down.
168+
const long poll_time_ns = 10000;
169+
long long read_deadline = rtapi_get_time() + recv_timeout_ns;
170+
do {
171+
errno = 0;
172+
ret = recv(board->sockfd, buffer, len, MSG_DONTWAIT);
173+
if(ret < 0) rtapi_delay(poll_time_ns);
174+
} while (ret < 0 && rtapi_get_time() < read_deadline);
189175
return ret;
190176
}

0 commit comments

Comments
 (0)