Merge pull request #3 from llyzs/transport

Two fixes for transport module.
This commit is contained in:
Marc-André Moreau 2011-07-03 18:25:28 -07:00
commit 107b0f1b32

View File

@ -93,6 +93,7 @@ transport_connect_nla(rdpTransport * transport)
static int
transport_delay(rdpTransport * transport)
{
transport_check_fds(transport);
nanosleep(&transport->ts, NULL);
return 0;
}
@ -190,43 +191,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