mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2024-11-27 11:54:44 +08:00
Merge pull request #3 from llyzs/transport
Two fixes for transport module.
This commit is contained in:
commit
107b0f1b32
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user