Add nvnc_client_close API
This allows the user or application to terminate any given nvnc_client connection at any time. Signed-off-by: Jim Ramsay <i.am@jimramsay.com>pull/84/head
parent
8f979c9928
commit
332be4d471
|
@ -137,7 +137,7 @@ const char* nvnc_client_get_auth_username(const struct nvnc_client* client);
|
||||||
|
|
||||||
struct nvnc_client* nvnc_client_first(struct nvnc* self);
|
struct nvnc_client* nvnc_client_first(struct nvnc* self);
|
||||||
struct nvnc_client* nvnc_client_next(struct nvnc_client* client);
|
struct nvnc_client* nvnc_client_next(struct nvnc_client* client);
|
||||||
|
void nvnc_client_close(struct nvnc_client* client);
|
||||||
|
|
||||||
void nvnc_set_name(struct nvnc* self, const char* name);
|
void nvnc_set_name(struct nvnc* self, const char* name);
|
||||||
|
|
||||||
|
|
46
src/server.c
46
src/server.c
|
@ -147,8 +147,7 @@ static void close_after_write(void* userdata, enum stream_req_status status)
|
||||||
struct nvnc_client* client = userdata;
|
struct nvnc_client* client = userdata;
|
||||||
nvnc_log(NVNC_LOG_DEBUG, "close_after_write(%p): ref %d", client,
|
nvnc_log(NVNC_LOG_DEBUG, "close_after_write(%p): ref %d", client,
|
||||||
client->ref);
|
client->ref);
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_unsupported_version(struct nvnc_client* client)
|
static int handle_unsupported_version(struct nvnc_client* client)
|
||||||
|
@ -296,8 +295,7 @@ static int on_vencrypt_subtype_message(struct nvnc_client* client)
|
||||||
|
|
||||||
if (stream_upgrade_to_tls(client->net_stream, client->server->tls_creds) < 0) {
|
if (stream_upgrade_to_tls(client->net_stream, client->server->tls_creds) < 0) {
|
||||||
client->state = VNC_CLIENT_STATE_ERROR;
|
client->state = VNC_CLIENT_STATE_ERROR;
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
return sizeof(*msg);
|
return sizeof(*msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,8 +381,7 @@ static void disconnect_all_other_clients(struct nvnc_client* client)
|
||||||
nvnc_log(NVNC_LOG_DEBUG,
|
nvnc_log(NVNC_LOG_DEBUG,
|
||||||
"disconnect other client %p (ref %d)",
|
"disconnect other client %p (ref %d)",
|
||||||
node, node->ref);
|
node, node->ref);
|
||||||
stream_close(node->net_stream);
|
nvnc_client_close(node);
|
||||||
client_unref(node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -438,8 +435,7 @@ static void send_server_init_message(struct nvnc_client* client)
|
||||||
pixfmt_failure:
|
pixfmt_failure:
|
||||||
free(msg);
|
free(msg);
|
||||||
close:
|
close:
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int on_init_message(struct nvnc_client* client)
|
static int on_init_message(struct nvnc_client* client)
|
||||||
|
@ -473,8 +469,7 @@ static int on_client_set_pixel_format(struct nvnc_client* client)
|
||||||
|
|
||||||
if (!fmt->true_colour_flag) {
|
if (!fmt->true_colour_flag) {
|
||||||
/* We don't really know what to do with color maps right now */
|
/* We don't really know what to do with color maps right now */
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -808,8 +803,7 @@ static int on_client_qemu_event(struct nvnc_client* client)
|
||||||
|
|
||||||
nvnc_log(NVNC_LOG_WARNING, "Got uninterpretable qemu message from client: %p (ref %d)",
|
nvnc_log(NVNC_LOG_WARNING, "Got uninterpretable qemu message from client: %p (ref %d)",
|
||||||
client, client->ref);
|
client, client->ref);
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,8 +862,7 @@ static int on_client_cut_text(struct nvnc_client* client)
|
||||||
if (length > max_length) {
|
if (length > max_length) {
|
||||||
nvnc_log(NVNC_LOG_ERROR, "Copied text length (%d) is greater than max supported length (%d)",
|
nvnc_log(NVNC_LOG_ERROR, "Copied text length (%d) is greater than max supported length (%d)",
|
||||||
length, max_length);
|
length, max_length);
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,8 +881,7 @@ static int on_client_cut_text(struct nvnc_client* client)
|
||||||
client->cut_text.buffer = malloc(length);
|
client->cut_text.buffer = malloc(length);
|
||||||
if (!client->cut_text.buffer) {
|
if (!client->cut_text.buffer) {
|
||||||
nvnc_log(NVNC_LOG_ERROR, "OOM: %m");
|
nvnc_log(NVNC_LOG_ERROR, "OOM: %m");
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -921,8 +913,7 @@ static void process_big_cut_text(struct nvnc_client* client)
|
||||||
if (errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
nvnc_log(NVNC_LOG_INFO, "Client connection error: %p (ref %d)",
|
nvnc_log(NVNC_LOG_INFO, "Client connection error: %p (ref %d)",
|
||||||
client, client->ref);
|
client, client->ref);
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -968,8 +959,7 @@ static int on_client_message(struct nvnc_client* client)
|
||||||
|
|
||||||
nvnc_log(NVNC_LOG_WARNING, "Got uninterpretable message from client: %p (ref %d)",
|
nvnc_log(NVNC_LOG_WARNING, "Got uninterpretable message from client: %p (ref %d)",
|
||||||
client, client->ref);
|
client, client->ref);
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1008,8 +998,7 @@ static void on_client_event(struct stream* stream, enum stream_event event)
|
||||||
|
|
||||||
if (event == STREAM_EVENT_REMOTE_CLOSED) {
|
if (event == STREAM_EVENT_REMOTE_CLOSED) {
|
||||||
nvnc_log(NVNC_LOG_INFO, "Client %p (%d) hung up", client, client->ref);
|
nvnc_log(NVNC_LOG_INFO, "Client %p (%d) hung up", client, client->ref);
|
||||||
stream_close(stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1031,8 +1020,7 @@ static void on_client_event(struct stream* stream, enum stream_event event)
|
||||||
if (errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
nvnc_log(NVNC_LOG_INFO, "Client connection error: %p (ref %d)",
|
nvnc_log(NVNC_LOG_INFO, "Client connection error: %p (ref %d)",
|
||||||
client, client->ref);
|
client, client->ref);
|
||||||
stream_close(stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -1442,8 +1430,7 @@ static int send_desktop_resize(struct nvnc_client* client, struct nvnc_fb* fb)
|
||||||
{
|
{
|
||||||
if (!client_has_encoding(client, RFB_ENCODING_DESKTOPSIZE)) {
|
if (!client_has_encoding(client, RFB_ENCODING_DESKTOPSIZE)) {
|
||||||
nvnc_log(NVNC_LOG_ERROR, "Client does not support desktop resizing. Closing connection...");
|
nvnc_log(NVNC_LOG_ERROR, "Client does not support desktop resizing. Closing connection...");
|
||||||
stream_close(client->net_stream);
|
nvnc_client_close(client);
|
||||||
client_unref(client);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1613,6 +1600,13 @@ struct nvnc_client* nvnc_client_next(struct nvnc_client* client)
|
||||||
return LIST_NEXT(client, link);
|
return LIST_NEXT(client, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXPORT
|
||||||
|
void nvnc_client_close(struct nvnc_client* client)
|
||||||
|
{
|
||||||
|
stream_close(client->net_stream);
|
||||||
|
client_unref(client);
|
||||||
|
}
|
||||||
|
|
||||||
EXPORT
|
EXPORT
|
||||||
bool nvnc_client_supports_cursor(const struct nvnc_client* client)
|
bool nvnc_client_supports_cursor(const struct nvnc_client* client)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue