server: Defer cleaning up client resources on close
When the event is received, the client object may still be processing some things, so let's allow it to finish.pull/96/head
parent
f8f49196e8
commit
dc1d93cadf
17
src/server.c
17
src/server.c
|
@ -159,7 +159,7 @@ static inline void client_ref(struct nvnc_client* client)
|
|||
++client->ref;
|
||||
}
|
||||
|
||||
static void deferred_client_close(void *obj)
|
||||
static void do_deferred_client_close(void *obj)
|
||||
{
|
||||
client_unref(obj);
|
||||
}
|
||||
|
@ -169,6 +169,14 @@ static void stop_self(void* obj)
|
|||
aml_stop(aml_get_default(), obj);
|
||||
}
|
||||
|
||||
static void defer_client_close(struct nvnc_client* client)
|
||||
{
|
||||
struct aml_idle* idle = aml_idle_new(stop_self, client,
|
||||
do_deferred_client_close);
|
||||
aml_start(aml_get_default(), idle);
|
||||
aml_unref(idle);
|
||||
}
|
||||
|
||||
static void close_after_write(void* userdata, enum stream_req_status status)
|
||||
{
|
||||
struct nvnc_client* client = userdata;
|
||||
|
@ -180,10 +188,7 @@ static void close_after_write(void* userdata, enum stream_req_status status)
|
|||
* stays alive while the stream is processing its queue.
|
||||
* TODO: Figure out some better resource management for clients
|
||||
*/
|
||||
struct aml_idle* idle = aml_idle_new(stop_self, client,
|
||||
deferred_client_close);
|
||||
aml_start(aml_get_default(), idle);
|
||||
aml_unref(idle);
|
||||
defer_client_close(client);
|
||||
}
|
||||
|
||||
static int handle_unsupported_version(struct nvnc_client* client)
|
||||
|
@ -1621,7 +1626,7 @@ static void on_client_event(struct stream* stream, enum stream_event event)
|
|||
|
||||
if (event == STREAM_EVENT_REMOTE_CLOSED) {
|
||||
nvnc_log(NVNC_LOG_INFO, "Client %p (%d) hung up", client, client->ref);
|
||||
nvnc_client_close(client);
|
||||
defer_client_close(client);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue