Use StreamPool in rdpdr
This commit is contained in:
parent
3d07eee3ac
commit
76661f6019
@ -45,8 +45,10 @@ static UINT irp_free(IRP* irp)
|
||||
if (!irp)
|
||||
return CHANNEL_RC_OK;
|
||||
|
||||
Stream_Free(irp->input, TRUE);
|
||||
Stream_Free(irp->output, TRUE);
|
||||
if (irp->input)
|
||||
Stream_Release(irp->input);
|
||||
if (irp->output)
|
||||
Stream_Release(irp->output);
|
||||
|
||||
winpr_aligned_free(irp);
|
||||
return CHANNEL_RC_OK;
|
||||
@ -77,12 +79,16 @@ static UINT irp_complete(IRP* irp)
|
||||
return error;
|
||||
}
|
||||
|
||||
IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error)
|
||||
IRP* irp_new(DEVMAN* devman, wStreamPool* pool, wStream* s, UINT* error)
|
||||
{
|
||||
IRP* irp;
|
||||
DEVICE* device;
|
||||
UINT32 DeviceId;
|
||||
|
||||
WINPR_ASSERT(devman);
|
||||
WINPR_ASSERT(pool);
|
||||
WINPR_ASSERT(s);
|
||||
|
||||
if (!Stream_CheckAndLogRequiredLength(TAG, s, 20))
|
||||
{
|
||||
if (error)
|
||||
@ -114,16 +120,17 @@ IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error)
|
||||
|
||||
ZeroMemory(irp, sizeof(IRP));
|
||||
|
||||
irp->input = s;
|
||||
irp->device = device;
|
||||
irp->devman = devman;
|
||||
|
||||
Stream_Read_UINT32(s, irp->FileId); /* FileId (4 bytes) */
|
||||
Stream_Read_UINT32(s, irp->CompletionId); /* CompletionId (4 bytes) */
|
||||
Stream_Read_UINT32(s, irp->MajorFunction); /* MajorFunction (4 bytes) */
|
||||
Stream_Read_UINT32(s, irp->MinorFunction); /* MinorFunction (4 bytes) */
|
||||
|
||||
irp->output = Stream_New(NULL, 256);
|
||||
Stream_AddRef(s);
|
||||
irp->input = s;
|
||||
irp->device = device;
|
||||
irp->devman = devman;
|
||||
|
||||
irp->output = StreamPool_Take(pool, 256);
|
||||
if (!irp->output)
|
||||
{
|
||||
WLog_ERR(TAG, "Stream_New failed!");
|
||||
@ -135,7 +142,8 @@ IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error)
|
||||
|
||||
if (!rdpdr_write_iocompletion_header(irp->output, DeviceId, irp->CompletionId, 0))
|
||||
{
|
||||
Stream_Free(irp->output, TRUE);
|
||||
if (irp->output)
|
||||
Stream_Release(irp->output);
|
||||
winpr_aligned_free(irp);
|
||||
if (error)
|
||||
*error = CHANNEL_RC_NO_MEMORY;
|
||||
|
@ -23,6 +23,6 @@
|
||||
|
||||
#include "rdpdr_main.h"
|
||||
|
||||
IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error);
|
||||
IRP* irp_new(DEVMAN* devman, wStreamPool* pool, wStream* s, UINT* error);
|
||||
|
||||
#endif /* FREERDP_CHANNEL_RDPDR_CLIENT_IRP_H */
|
||||
|
@ -1260,7 +1260,7 @@ static BOOL device_announce(ULONG_PTR key, void* element, void* data)
|
||||
|
||||
if (!Stream_EnsureRemainingCapacity(arg->s, 20 + data_len))
|
||||
{
|
||||
Stream_Free(arg->s, TRUE);
|
||||
Stream_Release(arg->s);
|
||||
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
||||
return FALSE;
|
||||
}
|
||||
@ -1305,7 +1305,7 @@ static UINT rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use
|
||||
WINPR_ASSERT(rdpdr);
|
||||
WINPR_ASSERT(rdpdr->devman);
|
||||
|
||||
s = Stream_New(NULL, 256);
|
||||
s = StreamPool_Take(rdpdr->pool, 256);
|
||||
|
||||
if (!s)
|
||||
{
|
||||
@ -1375,7 +1375,7 @@ static UINT rdpdr_process_irp(rdpdrPlugin* rdpdr, wStream* s)
|
||||
WINPR_ASSERT(rdpdr);
|
||||
WINPR_ASSERT(s);
|
||||
|
||||
irp = irp_new(rdpdr->devman, s, &error);
|
||||
irp = irp_new(rdpdr->devman, rdpdr->pool, s, &error);
|
||||
|
||||
if (!irp)
|
||||
{
|
||||
@ -1605,13 +1605,13 @@ UINT rdpdr_send(rdpdrPlugin* rdpdr, wStream* s)
|
||||
|
||||
if (!rdpdr || !s)
|
||||
{
|
||||
Stream_Free(s, TRUE);
|
||||
Stream_Release(s);
|
||||
return CHANNEL_RC_NULL_DATA;
|
||||
}
|
||||
|
||||
if (!plugin)
|
||||
{
|
||||
Stream_Free(s, TRUE);
|
||||
Stream_Release(s);
|
||||
status = CHANNEL_RC_BAD_INIT_HANDLE;
|
||||
}
|
||||
else
|
||||
@ -1624,7 +1624,7 @@ UINT rdpdr_send(rdpdrPlugin* rdpdr, wStream* s)
|
||||
|
||||
if (status != CHANNEL_RC_OK)
|
||||
{
|
||||
Stream_Free(s, TRUE);
|
||||
Stream_Release(s);
|
||||
WLog_ERR(TAG, "pVirtualChannelWriteEx failed with %s [%08" PRIX32 "]",
|
||||
WTSErrorToString(status), status);
|
||||
}
|
||||
@ -1660,9 +1660,9 @@ static UINT rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr, void*
|
||||
if (dataFlags & CHANNEL_FLAG_FIRST)
|
||||
{
|
||||
if (rdpdr->data_in != NULL)
|
||||
Stream_Free(rdpdr->data_in, TRUE);
|
||||
Stream_Release(rdpdr->data_in);
|
||||
|
||||
rdpdr->data_in = Stream_New(NULL, totalLength);
|
||||
rdpdr->data_in = StreamPool_Take(rdpdr->pool, totalLength);
|
||||
|
||||
if (!rdpdr->data_in)
|
||||
{
|
||||
@ -1683,7 +1683,9 @@ static UINT rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr, void*
|
||||
|
||||
if (dataFlags & CHANNEL_FLAG_LAST)
|
||||
{
|
||||
if (Stream_Capacity(data_in) != Stream_GetPosition(data_in))
|
||||
const size_t pos = Stream_GetPosition(data_in);
|
||||
const size_t cap = Stream_Capacity(data_in);
|
||||
if (cap < pos)
|
||||
{
|
||||
WLog_ERR(TAG, "rdpdr_virtual_channel_event_data_received: read error");
|
||||
return ERROR_INTERNAL_ERROR;
|
||||
@ -1732,7 +1734,7 @@ static VOID VCAPITYPE rdpdr_virtual_channel_open_event_ex(LPVOID lpUserParam, DW
|
||||
case CHANNEL_EVENT_WRITE_COMPLETE:
|
||||
{
|
||||
wStream* s = (wStream*)pData;
|
||||
Stream_Free(s, TRUE);
|
||||
Stream_Release(s);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1789,7 +1791,7 @@ static DWORD WINAPI rdpdr_virtual_channel_client_thread(LPVOID arg)
|
||||
|
||||
error = rdpdr_process_receive(rdpdr, data);
|
||||
|
||||
Stream_Free(data, TRUE);
|
||||
Stream_Release(data);
|
||||
if (error)
|
||||
{
|
||||
WLog_ERR(TAG, "rdpdr_process_receive failed with error %" PRIu32 "!", error);
|
||||
@ -1822,7 +1824,7 @@ static void queue_free(void* obj)
|
||||
|
||||
s = (wStream*)msg->wParam;
|
||||
WINPR_ASSERT(s);
|
||||
Stream_Free(s, TRUE);
|
||||
Stream_Release(s);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1906,7 +1908,7 @@ static UINT rdpdr_virtual_channel_event_disconnected(rdpdrPlugin* rdpdr)
|
||||
|
||||
if (rdpdr->data_in)
|
||||
{
|
||||
Stream_Free(rdpdr->data_in, TRUE);
|
||||
Stream_Release(rdpdr->data_in);
|
||||
rdpdr->data_in = NULL;
|
||||
}
|
||||
|
||||
@ -1923,6 +1925,7 @@ static void rdpdr_virtual_channel_event_terminated(rdpdrPlugin* rdpdr)
|
||||
{
|
||||
WINPR_ASSERT(rdpdr);
|
||||
rdpdr->InitHandle = 0;
|
||||
StreamPool_Free(rdpdr->pool);
|
||||
free(rdpdr);
|
||||
}
|
||||
|
||||
@ -1998,6 +2001,13 @@ BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, PVOID p
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
rdpdr->pool = StreamPool_New(TRUE, 1024);
|
||||
if (!rdpdr->pool)
|
||||
{
|
||||
free(rdpdr);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
rdpdr->channelDef.options =
|
||||
CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP;
|
||||
sprintf_s(rdpdr->channelDef.name, ARRAYSIZE(rdpdr->channelDef.name), RDPDR_SVC_CHANNEL_NAME);
|
||||
|
@ -76,6 +76,7 @@ typedef struct
|
||||
HANDLE stopEvent;
|
||||
#endif
|
||||
rdpContext* rdpcontext;
|
||||
wStreamPool* pool;
|
||||
} rdpdrPlugin;
|
||||
|
||||
UINT rdpdr_send(rdpdrPlugin* rdpdr, wStream* s);
|
||||
|
Loading…
Reference in New Issue
Block a user