Skip to content

Commit

Permalink
Change socket fd checks against INVALID_SOCKET. Fix issue with allowi…
Browse files Browse the repository at this point in the history
…ng reconnects from client to a server.
  • Loading branch information
bowb committed Jun 7, 2022
1 parent 51fb023 commit 76543ea
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions virtualsmartcard/src/vpcd/vpcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static ssize_t recvFromVICC(struct vicc_ctx *ctx, unsigned char **buffer)
int vicc_eject(struct vicc_ctx *ctx)
{
int r = 0;
if (ctx && ctx->client_sock > 0) {
if (ctx && ctx->client_sock != INVALID_SOCKET) {
if (close(ctx->client_sock) < 0) {
r -= 1;
}
Expand Down Expand Up @@ -334,7 +334,7 @@ int vicc_exit(struct vicc_ctx *ctx)
if (ctx) {
free_lock(ctx->io_lock);
free(ctx->hostname);
if (ctx->server_sock > 0) {
if (ctx->server_sock != INVALID_SOCKET) {
ctx->server_sock = close(ctx->server_sock);
if (ctx->server_sock == INVALID_SOCKET) {
r -= 1;
Expand Down Expand Up @@ -380,12 +380,9 @@ int vicc_connect(struct vicc_ctx *ctx, long secs, long usecs)
return 0;

if (ctx->client_sock == INVALID_SOCKET) {
if (ctx->server_sock) {
if(!ctx->hostname) {
/* server mode, try to accept a client */
ctx->client_sock = waitforclient(ctx->server_sock, secs, usecs);
if (!ctx->client_sock) {
ctx->client_sock = INVALID_SOCKET;
}
} else {
/* client mode, try to connect (again) */
ctx->client_sock = connectsock(ctx->hostname, ctx->port);
Expand Down

0 comments on commit 76543ea

Please sign in to comment.