Skip to content

Commit

Permalink
[dv/dpi] Retry select on EINTR
Browse files Browse the repository at this point in the history
When select returns -1 and errno is EINTR, the select should just be
retried instead of treating it as an error and disconnecting the
client.

Signed-off-by: Kip Walker <kip@rivosinc.com>
  • Loading branch information
kwalker27 committed Sep 3, 2024
1 parent 833a712 commit 26454af
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hw/dv/dpi/common/tcp_server/tcp_server.c
Original file line number Diff line number Diff line change
@@ -344,13 +344,20 @@ static void *server_create(void *ctx_void) {
// max fd num
int mfd = (ctx->cfd > ctx->sfd) ? ctx->cfd : ctx->sfd;

// Set timeout - 50us gives good performance
// Set timeout - 50us gives good performance; do it every time
// since select can trash it.
timeout.tv_sec = 0;
timeout.tv_usec = 50;

// Wait for socket activity or timeout
rv = select(mfd + 1, &read_fds, NULL, NULL, &timeout);

if (rv < 0) {
if (errno == EINTR) {
// On interrupt we want to retry
continue;
}

printf("%s: Socket read failed, port: %d\n", ctx->display_name,
ctx->listen_port);
tcp_server_client_close(ctx);

0 comments on commit 26454af

Please sign in to comment.