Example #1
0
int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
{
	int CopyLength;
    rdpRpc* rpc;

    if (tsg == NULL)
        return -1;

    rpc = tsg->rpc;

	if (tsg->PendingPdu)
	{
		CopyLength = (length < tsg->BytesAvailable) ? length : tsg->BytesAvailable;

		CopyMemory(data, &tsg->pdu->s->buffer[tsg->BytesRead], CopyLength);
		tsg->BytesAvailable -= CopyLength;
		tsg->BytesRead += CopyLength;

		if (tsg->BytesAvailable < 1)
		{
			tsg->PendingPdu = FALSE;
			rpc_recv_dequeue_pdu(rpc);
			rpc_client_receive_pool_return(rpc, tsg->pdu);
		}

		return CopyLength;
	}
	else
	{
		tsg->pdu = rpc_recv_peek_pdu(rpc);

		if (!tsg->pdu)
		{
			if (tsg->rpc->client->SynchronousReceive)
				return tsg_read(tsg, data, length);
			else
				return 0;
		}

		tsg->PendingPdu = TRUE;
		tsg->BytesAvailable = Stream_Length(tsg->pdu->s);
		tsg->BytesRead = 0;

		CopyLength = (length < tsg->BytesAvailable) ? length : tsg->BytesAvailable;

		CopyMemory(data, &tsg->pdu->s->buffer[tsg->BytesRead], CopyLength);
		tsg->BytesAvailable -= CopyLength;
		tsg->BytesRead += CopyLength;

		if (tsg->BytesAvailable < 1)
		{
			tsg->PendingPdu = FALSE;
			rpc_recv_dequeue_pdu(rpc);
			rpc_client_receive_pool_return(rpc, tsg->pdu);
		}

		return CopyLength;
	}
}
Example #2
0
int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
{
	int CopyLength;
	rdpRpc* rpc;

	if (tsg == NULL)
		return -1;

	rpc = tsg->rpc;

	if (rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
	{
		DEBUG_WARN( "tsg_read error: connection lost\n");
		return -1;
	}

	if (tsg->PendingPdu)
	{
		CopyLength = (length < tsg->BytesAvailable) ? length : tsg->BytesAvailable;

		CopyMemory(data, &tsg->pdu->s->buffer[tsg->BytesRead], CopyLength);
		tsg->BytesAvailable -= CopyLength;
		tsg->BytesRead += CopyLength;

		if (tsg->BytesAvailable < 1)
		{
			tsg->PendingPdu = FALSE;
			rpc_recv_dequeue_pdu(rpc);
			rpc_client_receive_pool_return(rpc, tsg->pdu);
		}

		return CopyLength;
	}


	tsg->pdu = rpc_recv_peek_pdu(rpc);
	if (!tsg->pdu)
	{
		if (!tsg->rpc->client->SynchronousReceive)
			return 0;

		// weird !!!!
		return tsg_read(tsg, data, length);
	}

	tsg->PendingPdu = TRUE;
	tsg->BytesAvailable = Stream_Length(tsg->pdu->s);
	tsg->BytesRead = 0;

	CopyLength = (length < tsg->BytesAvailable) ? length : tsg->BytesAvailable;

	CopyMemory(data, &tsg->pdu->s->buffer[tsg->BytesRead], CopyLength);
	tsg->BytesAvailable -= CopyLength;
	tsg->BytesRead += CopyLength;

	if (tsg->BytesAvailable < 1)
	{
		tsg->PendingPdu = FALSE;
		rpc_recv_dequeue_pdu(rpc);
		rpc_client_receive_pool_return(rpc, tsg->pdu);
	}

	return CopyLength;

}