From 60b0d075e29d4bf48c89be6881ba1825fdf7aad8 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 11 Jun 2014 14:40:38 +0200 Subject: [PATCH] svc_plugin now uses reference counted StreamPool. Added termination function to clean up allocated resources. --- include/freerdp/utils/svc_plugin.h | 3 +++ libfreerdp/utils/svc_plugin.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/freerdp/utils/svc_plugin.h b/include/freerdp/utils/svc_plugin.h index e4fff81be..6100c2cd7 100644 --- a/include/freerdp/utils/svc_plugin.h +++ b/include/freerdp/utils/svc_plugin.h @@ -55,6 +55,7 @@ struct rdp_svc_plugin void* InitHandle; DWORD OpenHandle; wMessagePipe* MsgPipe; + wStreamPool *pool; }; #ifdef __cplusplus @@ -62,6 +63,8 @@ extern "C" { #endif FREERDP_API void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints); +FREERDP_API void svc_plugin_terminate(rdpSvcPlugin* plugin); + FREERDP_API int svc_plugin_send(rdpSvcPlugin* plugin, wStream* data_out); FREERDP_API int svc_plugin_send_event(rdpSvcPlugin* plugin, wMessage* event); diff --git a/libfreerdp/utils/svc_plugin.c b/libfreerdp/utils/svc_plugin.c index 052e8957d..cb6018218 100644 --- a/libfreerdp/utils/svc_plugin.c +++ b/libfreerdp/utils/svc_plugin.c @@ -103,9 +103,9 @@ static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, UINT3 if (dataFlags & CHANNEL_FLAG_FIRST) { if (plugin->data_in != NULL) - Stream_Free(plugin->data_in, TRUE); + Stream_Release(plugin->data_in); - plugin->data_in = Stream_New(NULL, totalLength); + plugin->data_in = StreamPool_Take(plugin->pool, totalLength); } s = plugin->data_in; @@ -122,6 +122,7 @@ static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, UINT3 plugin->data_in = NULL; Stream_SealLength(s); Stream_SetPosition(s, 0); + Stream_AddRef(s); MessageQueue_Post(plugin->MsgPipe->In, NULL, 0, (void*) s, NULL); } @@ -192,6 +193,7 @@ static void* svc_plugin_thread_func(void* arg) { data = (wStream*) message.wParam; IFCALL(plugin->receive_callback, plugin, data); + Stream_Release(data); } else if (message.id == 1) { @@ -296,10 +298,17 @@ void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints) plugin->channel_entry_points.pInterface = *(plugin->channel_entry_points.ppInterface); plugin->channel_entry_points.ppInterface = &(plugin->channel_entry_points.pInterface); plugin->started = CreateEvent(NULL,TRUE,FALSE,NULL); + plugin->pool = StreamPool_New(FALSE, 10); svc_plugin_add_init_handle_data(plugin->InitHandle, plugin); } +void svc_plugin_terminate(rdpSvcPlugin* plugin) +{ + StreamPool_Free(plugin->pool); + CloseHandle(plugin->started); +} + int svc_plugin_send(rdpSvcPlugin* plugin, wStream* data_out) { UINT32 status = 0;