Skip to content

Commit

Permalink
remove global_pong_id
Browse files Browse the repository at this point in the history
  • Loading branch information
gloveboxes authored and Theldus committed Apr 29, 2022
1 parent 9ce8352 commit ed3c45c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ typedef int socklen_t;
#include <utf8.h>
#include <ws.h>

static long int global_last_pong_id = -1;

/**
* @dir src/
* @brief wsServer source code
Expand Down Expand Up @@ -545,15 +543,17 @@ long int ws_ping(ws_cli_conn_t *cli, long int ws_ping_id)
/* long enough to hold long int */
char ping_token[22];

if (!cli){
return -1;
}

/* reset global_last_pong_id if cli is NULL and ws_ping_id is zero
client last_pong_id is reset on new connection */
global_last_pong_id = ws_ping_id == 0 && !cli ? -1 : global_last_pong_id;

snprintf(ping_token, sizeof(ping_token), "%ld", ws_ping_id);
ws_sendframe(NULL, ping_token, strlen(ping_token), WS_FR_OP_PING);

/* if cli is NULL return global_last_pong_id else return cli ws_last_pong_id */
return cli ? cli->last_pong_id : global_last_pong_id;
return cli->last_pong_id;
}

/**
Expand Down Expand Up @@ -1226,8 +1226,7 @@ static int next_frame(struct ws_frame_data *wfd)
break;

char *ptr;
global_last_pong_id = strtol((const char *)msg_ctrl, &ptr, 10);
wfd->client->last_pong_id = global_last_pong_id;
wfd->client->last_pong_id = strtol((const char *)msg_ctrl, &ptr, 10);

is_fin = 0;
continue;
Expand Down

0 comments on commit ed3c45c

Please sign in to comment.