diff --git a/hw/dv/dpi/common/tcp_server/tcp_server.c b/hw/dv/dpi/common/tcp_server/tcp_server.c index f9944a58f562e..3a26835902baf 100644 --- a/hw/dv/dpi/common/tcp_server/tcp_server.c +++ b/hw/dv/dpi/common/tcp_server/tcp_server.c @@ -178,7 +178,6 @@ static int client_tryaccept(struct tcp_server_ctx *ctx) { int rv; assert(ctx->sfd > 0); - assert(ctx->cfd == 0); int cfd = accept(ctx->sfd, NULL, NULL); @@ -192,6 +191,14 @@ static int client_tryaccept(struct tcp_server_ctx *ctx) { return -1; } + if (ctx->cfd > 0) { + // Enforce a single concurrent connection. Accept and close any + // new connection attempt when there's already a client. + fprintf(stderr, "%s: Rejecting additional connection\n", ctx->display_name); + close(cfd); + return -1; + } + rv = fcntl(cfd, F_SETFL, O_NONBLOCK); if (rv != 0) { fprintf(stderr, "%s: Unable to make client socket non-blocking: %s (%d)\n",