Merge pull request #2234 from bmiklautz/fix/tls

Transport and tsg fixes
This commit is contained in:
Marc-André Moreau 2014-11-28 11:00:27 -05:00
commit 2c76ac0ef9
5 changed files with 44 additions and 15 deletions

View File

@ -379,6 +379,7 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
WLog_ERR(TAG, "QueryContextAttributes SECPKG_ATTR_SIZES failure");
return -1;
}
ZeroMemory(&Buffers, sizeof(Buffers));
request_pdu = (rpcconn_request_hdr_t*) calloc(1, sizeof(rpcconn_request_hdr_t));
@ -459,18 +460,14 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
if (rpc_send_enqueue_pdu(rpc, buffer, request_pdu->frag_length) < 0)
length = -1;
free (buffer);
free(request_pdu);
return length;
out_free_clientCall:
rpc_client_call_free(clientCall);
out_free_pdu:
if (buffer)
free (buffer);
if (Buffers[1].pvBuffer)
free (Buffers[1].pvBuffer);
if (request_pdu)
free(request_pdu);
return -1;
}

View File

@ -354,7 +354,10 @@ int rpc_send_enqueue_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));
if (!pdu)
{
free(buffer);
return -1;
}
pdu->s = Stream_New(buffer, length);

View File

@ -1401,6 +1401,16 @@ BOOL tsg_disconnect(rdpTsg* tsg)
return TRUE;
}
/**
* @brief
*
* @param[in] tsg
* @param[in] data
* @param[in] length
* @return < 0 on error; 0 if not enough data is available (non blocking mode); > 0 bytes to read
*/
int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
{
int CopyLength;
@ -1434,17 +1444,33 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
return CopyLength;
}
do
{
tsg->pdu = rpc_recv_peek_pdu(rpc);
if (!tsg->pdu)
{
/* there is a pdu to process - move on*/
if (tsg->pdu)
break;
/*
* no pdu available and synchronous is not required
* return 0 to indicate that there is no data
* available at the moment
*/
if (!tsg->rpc->client->SynchronousReceive)
return 0;
// weird !!!!
return tsg_read(tsg, data, length);
/* ensure that the transport wasn't already closed - in case of a retry */
if (rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
{
WLog_ERR(TAG, "tsg_read error: connection lost");
return -1;
}
/* retry in case synchronous receive is required */
} while (tsg->rpc->client->SynchronousReceive);
tsg->PendingPdu = TRUE;
tsg->BytesAvailable = Stream_Length(tsg->pdu->s);
tsg->BytesRead = 0;

View File

@ -149,12 +149,16 @@ static int transport_bio_tsg_read(BIO* bio, char* buf, int size)
{
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
}
else if (status == 0)
{
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
}
else
{
BIO_set_flags(bio, BIO_FLAGS_READ);
}
return status >= 0 ? status : -1;
return status > 0 ? status : -1;
}
static int transport_bio_tsg_puts(BIO* bio, const char* str)

View File

@ -167,8 +167,7 @@ static int bio_rdp_tls_read(BIO* bio, char* buf, int size)
case SSL_ERROR_SYSCALL:
error = WSAGetLastError();
if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) ||
(error == WSAEINPROGRESS) || (error == WSAEALREADY) ||
(error == 0))
(error == WSAEINPROGRESS) || (error == WSAEALREADY))
{
BIO_set_flags(bio, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY));
}