mirror of
https://github.com/lxsang/antd-wvnc-plugin.git
synced 2024-12-27 12:28:22 +01:00
improve: ping to see if idle client still alive
All checks were successful
gitea-sync/antd-wvnc-plugin/pipeline/head This commit looks good
All checks were successful
gitea-sync/antd-wvnc-plugin/pipeline/head This commit looks good
This commit is contained in:
parent
bff0fb40c6
commit
604aab8f0b
21
wvnc.c
21
wvnc.c
@ -10,6 +10,8 @@
|
|||||||
#include <antd/ws.h>
|
#include <antd/ws.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#define PING_INTERVAL 10u // 10s
|
||||||
|
|
||||||
#define get_user_data(x) ((wvnc_user_data_t *)x)
|
#define get_user_data(x) ((wvnc_user_data_t *)x)
|
||||||
/*
|
/*
|
||||||
Vnc to web socket using the
|
Vnc to web socket using the
|
||||||
@ -241,6 +243,16 @@ void *process(void *data, int wait)
|
|||||||
}
|
}
|
||||||
//buff = NULL;
|
//buff = NULL;
|
||||||
}
|
}
|
||||||
|
else if (h->opcode == WS_PONG)
|
||||||
|
{
|
||||||
|
buff = (uint8_t *)malloc(h->plen + 1);
|
||||||
|
if (buff)
|
||||||
|
{
|
||||||
|
ws_read_data(user_data->wscl->client, h, h->plen, buff);
|
||||||
|
LOG("Receive pong message from client: %s. Client Alive", buff);
|
||||||
|
free(buff);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vnc_fatal(user_data, "Unknow opcode");
|
vnc_fatal(user_data, "Unknow opcode");
|
||||||
@ -537,6 +549,15 @@ void waitfor(void *data)
|
|||||||
timeout.tv_usec = 500;
|
timeout.tv_usec = 500;
|
||||||
while (user_data->status != DISCONNECTED)
|
while (user_data->status != DISCONNECTED)
|
||||||
{
|
{
|
||||||
|
// check whether we need to send ping message to client
|
||||||
|
if (difftime(time(NULL), user_data->wscl->client->last_io) > (double)PING_INTERVAL)
|
||||||
|
{
|
||||||
|
if (ws_ping(user_data->wscl->client, "WVNC", 0) != 0)
|
||||||
|
{
|
||||||
|
ERROR("Unable to ping client, close the connection: %d", user_data->wscl->client->sock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
FD_ZERO(&fd_in);
|
FD_ZERO(&fd_in);
|
||||||
FD_SET(user_data->wscl->client->sock, &fd_in);
|
FD_SET(user_data->wscl->client->sock, &fd_in);
|
||||||
int rc = select(user_data->wscl->client->sock + 1, &fd_in, NULL, NULL, &timeout);
|
int rc = select(user_data->wscl->client->sock + 1, &fd_in, NULL, NULL, &timeout);
|
||||||
|
Loading…
Reference in New Issue
Block a user