Merge pull request #1769 from nfedera/fix-2014-04-03-01

libfreerdp-core: fix transport_check_fds
This commit is contained in:
Marc-André Moreau 2014-04-03 15:58:45 -04:00
commit 5aa64a08b0

View File

@ -970,13 +970,23 @@ int transport_check_fds(rdpTransport* transport)
*/
for (;;)
{
status = transport_read_nonblocking(transport);
/**
* Note: transport_read_nonblocking() reads max 1 additional PDU from
* the layer. Also note that transport_read_nonblocking() is also called
* outside of this function in transport_write()! This means that when
* entering transport_check_fds it is possible that the stream position
* of transport->ReceiveBuffer position is > 0. We must process this data
* even if transport_read_nonblocking() returns 0.
* Note that transport->ReceiveBuffer is replaced after each iteration
* of this loop with a fresh stream instance from a pool.
*/
if ((status <= 0) || (Stream_GetPosition(transport->ReceiveBuffer) < 2))
if ((status = transport_read_nonblocking(transport)) < 0)
return status;
if ((pos = Stream_GetPosition(transport->ReceiveBuffer)) < 2)
return status;
while ((pos = Stream_GetPosition(transport->ReceiveBuffer)) > 0)
{
Stream_SetPosition(transport->ReceiveBuffer, 0);
if (transport->NlaMode)
@ -1081,11 +1091,7 @@ int transport_check_fds(rdpTransport* transport)
Stream_Release(received);
if (recv_status < 0)
status = -1;
if (status < 0)
return status;
}
return -1;
}
return 0;