libfreerdp-core: pool receive buffers

This commit is contained in:
Marc-André Moreau 2012-12-21 15:36:10 -05:00
parent 06f76ee0fe
commit 87451b38c2
2 changed files with 40 additions and 2 deletions

View File

@ -678,7 +678,7 @@ int transport_check_fds(rdpTransport** ptransport)
* for the next packet, we copy it to the new receive buffer.
*/
received = transport->recv_buffer;
transport->recv_buffer = stream_new(BUFFER_SIZE);
transport->recv_buffer = transport_receive_pool_take(transport);
if (pos > length)
{
@ -694,7 +694,7 @@ int transport_check_fds(rdpTransport** ptransport)
if (transport->recv_callback(transport, received, transport->recv_extra) == FALSE)
status = -1;
stream_free(received);
transport_receive_pool_return(transport, received);
if (status < 0)
return status;
@ -741,6 +741,27 @@ BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking)
return status;
}
STREAM* transport_receive_pool_take(rdpTransport* transport)
{
STREAM* pdu = NULL;
if (WaitForSingleObject(Queue_Event(transport->ReceivePool), 0) == WAIT_OBJECT_0)
pdu = Queue_Dequeue(transport->ReceivePool);
if (!pdu)
pdu = stream_new(BUFFER_SIZE);
pdu->p = pdu->data;
return pdu;
}
int transport_receive_pool_return(rdpTransport* transport, STREAM* pdu)
{
Queue_Enqueue(transport->ReceivePool, pdu);
return 0;
}
rdpTransport* transport_new(rdpSettings* settings)
{
rdpTransport* transport;
@ -768,6 +789,11 @@ rdpTransport* transport_new(rdpSettings* settings)
transport->blocking = TRUE;
transport->layer = TRANSPORT_LAYER_TCP;
transport->ReceivePool = Queue_New(TRUE, -1, -1);
transport->ReceiveQueue = Queue_New(TRUE, -1, -1);
Queue_Object(transport->ReceivePool)->fnObjectFree = (OBJECT_FREE_FN) stream_free;
Queue_Object(transport->ReceiveQueue)->fnObjectFree = (OBJECT_FREE_FN) stream_free;
}
return transport;
@ -795,6 +821,9 @@ void transport_free(rdpTransport* transport)
tsg_free(transport->tsg);
Queue_Free(transport->ReceivePool);
Queue_Free(transport->ReceiveQueue);
free(transport);
}
}

View File

@ -36,6 +36,8 @@ typedef struct rdp_transport rdpTransport;
#include "gateway/tsg.h"
#include <winpr/sspi.h>
#include <winpr/collections.h>
#include <freerdp/crypto/tls.h>
#include <time.h>
@ -65,6 +67,9 @@ struct rdp_transport
BOOL blocking;
BOOL ProcessSinglePdu;
BOOL SplitInputOutput;
wQueue* ReceivePool;
wQueue* ReceiveQueue;
};
STREAM* transport_recv_stream_init(rdpTransport* transport, int size);
@ -84,6 +89,10 @@ int transport_write(rdpTransport* transport, STREAM* s);
void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount);
int transport_check_fds(rdpTransport** ptransport);
BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking);
STREAM* transport_receive_pool_take(rdpTransport* transport);
int transport_receive_pool_return(rdpTransport* transport, STREAM* pdu);
rdpTransport* transport_new(rdpSettings* settings);
void transport_free(rdpTransport* transport);