libfreerdp-core/transport: enable receiving more PDU in receiving buffer.

This commit is contained in:
Vic Lee 2011-07-04 09:07:34 +08:00
parent 27bca27636
commit fb687f2f9e

View File

@ -190,43 +190,50 @@ transport_check_fds(rdpTransport * transport)
if (bytes <= 0)
return bytes;
pos = stream_get_pos(transport->recv_buffer);
/* Ensure the TPKT header is available. */
if (pos <= 4)
return 0;
stream_set_pos(transport->recv_buffer, 0);
length = tpkt_read_header(transport->recv_buffer);
if (length == 0)
while ((pos = stream_get_pos(transport->recv_buffer)) > 0)
{
printf("transport_check_fds: protocol error, not a TPKT header.\n");
return -1;
/* Ensure the TPKT header is available. */
if (pos <= 4)
return 0;
stream_set_pos(transport->recv_buffer, 0);
length = tpkt_read_header(transport->recv_buffer);
if (length == 0)
{
printf("transport_check_fds: protocol error, not a TPKT header.\n");
return -1;
}
if (pos < length)
{
stream_set_pos(transport->recv_buffer, pos);
return 0; /* Packet is not yet completely received. */
}
/*
* A complete packet has been received. In case there are trailing data
* for the next packet, we copy it to the new receive buffer.
*/
received = transport->recv_buffer;
transport->recv_buffer = stream_new(BUFFER_SIZE);
if (pos > length)
{
stream_set_pos(received, length);
stream_check_capacity(transport->recv_buffer, pos - length);
stream_copy(transport->recv_buffer, received, pos - length);
}
stream_set_pos(received, 0);
bytes = transport->recv_callback(transport, received, transport->recv_extra);
stream_free(received);
if (bytes < 0)
return bytes;
}
if (pos < length)
return 0; /* Packet is not yet completely received. */
/*
* A complete packet has been received. In case there are trailing data
* for the next packet, we copy it to the new receive buffer.
*/
received = transport->recv_buffer;
transport->recv_buffer = stream_new(BUFFER_SIZE);
if (pos > length)
{
stream_set_pos(received, length);
stream_check_capacity(transport->recv_buffer, pos - length);
stream_copy(transport->recv_buffer, received, pos - length);
}
stream_set_pos(received, 0);
bytes = transport->recv_callback(transport, received, transport->recv_extra);
stream_free(received);
return bytes;
return 0;
}
void