libfreerdp-core: use stream pool

This commit is contained in:
Marc-André Moreau 2013-04-12 13:44:23 -04:00
parent 0fded8c2d0
commit d04b76d005
7 changed files with 36 additions and 39 deletions

View File

@ -49,8 +49,7 @@ int main(int argc, char* argv[])
GetExitCodeThread(xfi->thread, &dwExitCode);
freerdp_context_free(instance);
freerdp_free(instance);
freerdp_client_free(xfi);
freerdp_client_global_uninit();

View File

@ -1382,9 +1382,6 @@ void* xf_thread(void* param)
freerdp_channels_free(channels);
freerdp_disconnect(instance);
gdi_free(instance);
freerdp_client_free(xfi);
exit_code = 123;
ExitThread(exit_code);
}
@ -1475,8 +1472,6 @@ xfInfo* freerdp_client_new(int argc, char** argv)
freerdp_context_new(instance);
instance->context->argc = argc;
instance->context->argv = argv;
instance->context->argv = (char**) malloc(sizeof(char*) * argc);
for (index = 0; index < argc; index++)
@ -1544,12 +1539,25 @@ void freerdp_client_free(xfInfo* xfi)
{
if (xfi)
{
int index;
rdpContext* context;
xf_window_free(xfi);
free(xfi->bmp_codec_none);
XCloseDisplay(xfi->display);
context = (rdpContext*) xfi->context;
for (index = 0; index < context->argc; index++)
free(context->argv[index]);
free(context->argv);
freerdp_context_free(xfi->instance);
freerdp_free(xfi->instance);
free(xfi);
}
}

View File

@ -340,7 +340,7 @@ void freerdp_context_new(freerdp* instance)
*/
void freerdp_context_free(freerdp* instance)
{
if (instance->context == NULL)
if (!instance->context)
return;
IFCALL(instance->ContextFree, instance, instance->context);
@ -348,6 +348,8 @@ void freerdp_context_free(freerdp* instance)
rdp_free(instance->context->rdp);
graphics_free(instance->context->graphics);
free(instance->context->client);
free(instance->context);
instance->context = NULL;
}

View File

@ -703,7 +703,7 @@ int transport_check_fds(rdpTransport** ptransport)
}
received = transport->ReceiveBuffer;
transport->ReceiveBuffer = ObjectPool_Take(transport->ReceivePool);
transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0);
transport->ReceiveBuffer->pointer = transport->ReceiveBuffer->buffer;
stream_set_pos(received, length);
@ -720,7 +720,7 @@ int transport_check_fds(rdpTransport** ptransport)
recv_status = transport->ReceiveCallback(transport, received, transport->ReceiveExtra);
ObjectPool_Return(transport->ReceivePool, received);
StreamPool_Return(transport->ReceivePool, received);
if (recv_status < 0)
status = -1;
@ -799,16 +799,6 @@ static void* transport_client_thread(void* arg)
return NULL;
}
wStream* transport_receive_buffer_pool_new()
{
wStream* pdu = NULL;
pdu = stream_new(BUFFER_SIZE);
pdu->pointer = pdu->buffer;
return pdu;
}
rdpTransport* transport_new(rdpSettings* settings)
{
rdpTransport* transport;
@ -826,12 +816,10 @@ rdpTransport* transport_new(rdpSettings* settings)
/* a small 0.1ms delay when transport is blocking. */
transport->SleepInterval = 100;
transport->ReceivePool = ObjectPool_New(TRUE);
ObjectPool_Object(transport->ReceivePool)->fnObjectFree = (OBJECT_FREE_FN) stream_free;
ObjectPool_Object(transport->ReceivePool)->fnObjectNew = (OBJECT_NEW_FN) transport_receive_buffer_pool_new;
transport->ReceivePool = StreamPool_New(TRUE, BUFFER_SIZE);
/* receive buffer for non-blocking read. */
transport->ReceiveBuffer = ObjectPool_Take(transport->ReceivePool);
transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0);
transport->ReceiveEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
/* buffers for blocking read/write */
@ -851,9 +839,9 @@ void transport_free(rdpTransport* transport)
if (transport != NULL)
{
if (transport->ReceiveBuffer)
ObjectPool_Return(transport->ReceivePool, transport->ReceiveBuffer);
StreamPool_Return(transport->ReceivePool, transport->ReceiveBuffer);
ObjectPool_Free(transport->ReceivePool);
StreamPool_Free(transport->ReceivePool);
stream_free(transport->ReceiveStream);
stream_free(transport->SendStream);

View File

@ -69,7 +69,7 @@ struct rdp_transport
HANDLE GatewayEvent;
BOOL blocking;
BOOL SplitInputOutput;
wObjectPool* ReceivePool;
wStreamPool* ReceivePool;
HANDLE stopEvent;
HANDLE thread;
BOOL async;

View File

@ -102,7 +102,7 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size)
if (pool->aSize > 0)
s = pool->aArray[--(pool->aSize)];
if (size < 0)
if (size == 0)
size = pool->defaultSize;
if (!s)

View File

@ -12,9 +12,9 @@ int TestStreamPool(int argc, char* argv[])
pool = StreamPool_New(TRUE, BUFFER_SIZE);
s[0] = StreamPool_Take(pool, -1);
s[1] = StreamPool_Take(pool, -1);
s[2] = StreamPool_Take(pool, -1);
s[0] = StreamPool_Take(pool, 0);
s[1] = StreamPool_Take(pool, 0);
s[2] = StreamPool_Take(pool, 0);
printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize);
@ -24,8 +24,8 @@ int TestStreamPool(int argc, char* argv[])
printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize);
s[3] = StreamPool_Take(pool, -1);
s[4] = StreamPool_Take(pool, -1);
s[3] = StreamPool_Take(pool, 0);
s[4] = StreamPool_Take(pool, 0);
printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize);
@ -34,9 +34,9 @@ int TestStreamPool(int argc, char* argv[])
printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize);
s[2] = StreamPool_Take(pool, -1);
s[3] = StreamPool_Take(pool, -1);
s[4] = StreamPool_Take(pool, -1);
s[2] = StreamPool_Take(pool, 0);
s[3] = StreamPool_Take(pool, 0);
s[4] = StreamPool_Take(pool, 0);
printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize);
@ -63,9 +63,9 @@ int TestStreamPool(int argc, char* argv[])
printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize);
s[2] = StreamPool_Take(pool, -1);
s[3] = StreamPool_Take(pool, -1);
s[4] = StreamPool_Take(pool, -1);
s[2] = StreamPool_Take(pool, 0);
s[3] = StreamPool_Take(pool, 0);
s[4] = StreamPool_Take(pool, 0);
printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize);