mirror of https://github.com/FreeRDP/FreeRDP
libfreerdp-core: replace rdpTcp by BufferedSocket BIO
This commit is contained in:
parent
e904195e49
commit
edfc5120b7
|
@ -512,10 +512,10 @@ void rpc_in_channel_free(RpcInChannel* inChannel)
|
|||
inChannel->tls = NULL;
|
||||
}
|
||||
|
||||
if (inChannel->tcp)
|
||||
if (inChannel->bio)
|
||||
{
|
||||
freerdp_tcp_free(inChannel->tcp);
|
||||
inChannel->tcp = NULL;
|
||||
BIO_free(inChannel->bio);
|
||||
inChannel->bio = NULL;
|
||||
}
|
||||
|
||||
free(inChannel);
|
||||
|
@ -663,10 +663,10 @@ void rpc_out_channel_free(RpcOutChannel* outChannel)
|
|||
outChannel->tls = NULL;
|
||||
}
|
||||
|
||||
if (outChannel->tcp)
|
||||
if (outChannel->bio)
|
||||
{
|
||||
freerdp_tcp_free(outChannel->tcp);
|
||||
outChannel->tcp = NULL;
|
||||
BIO_free(outChannel->bio);
|
||||
outChannel->bio = NULL;
|
||||
}
|
||||
|
||||
free(outChannel);
|
||||
|
@ -759,21 +759,39 @@ void rpc_virtual_connection_free(RpcVirtualConnection* connection)
|
|||
|
||||
int rpc_channel_tls_connect(RpcChannel* channel, int timeout)
|
||||
{
|
||||
rdpTcp* tcp;
|
||||
int sockfd;
|
||||
rdpTls* tls;
|
||||
int tlsStatus;
|
||||
BIO* socketBio;
|
||||
BIO* bufferedBio;
|
||||
rdpRpc* rpc = channel->rpc;
|
||||
rdpContext* context = rpc->context;
|
||||
rdpSettings* settings = context->settings;
|
||||
|
||||
tcp = channel->tcp = freerdp_tcp_new();
|
||||
sockfd = freerdp_tcp_connect(settings, settings->GatewayHostname, settings->GatewayPort, timeout);
|
||||
|
||||
if (!freerdp_tcp_connect(tcp, settings, settings->GatewayHostname, settings->GatewayPort, timeout))
|
||||
if (sockfd < 1)
|
||||
return -1;
|
||||
|
||||
if (!BIO_set_nonblock(tcp->bufferedBio, TRUE))
|
||||
socketBio = BIO_new(BIO_s_simple_socket());
|
||||
|
||||
if (!socketBio)
|
||||
return FALSE;
|
||||
|
||||
BIO_set_fd(socketBio, sockfd, BIO_CLOSE);
|
||||
|
||||
bufferedBio = BIO_new(BIO_s_buffered_socket());
|
||||
|
||||
if (!bufferedBio)
|
||||
return FALSE;
|
||||
|
||||
bufferedBio = BIO_push(bufferedBio, socketBio);
|
||||
|
||||
if (!BIO_set_nonblock(bufferedBio, TRUE))
|
||||
return -1;
|
||||
|
||||
channel->bio = bufferedBio;
|
||||
|
||||
tls = channel->tls = tls_new(settings);
|
||||
|
||||
if (!tls)
|
||||
|
@ -783,7 +801,7 @@ int rpc_channel_tls_connect(RpcChannel* channel, int timeout)
|
|||
tls->port = settings->GatewayPort;
|
||||
tls->isGatewayTransport = TRUE;
|
||||
|
||||
tlsStatus = tls_connect(tls, tcp->bufferedBio);
|
||||
tlsStatus = tls_connect(tls, bufferedBio);
|
||||
|
||||
if (tlsStatus < 1)
|
||||
{
|
||||
|
|
|
@ -586,7 +586,7 @@ typedef struct rpc_client_call RpcClientCall;
|
|||
|
||||
#define RPC_CHANNEL_COMMON() \
|
||||
rdpRpc* rpc; \
|
||||
rdpTcp* tcp; \
|
||||
BIO* bio; \
|
||||
rdpTls* tls; \
|
||||
rdpNtlm* ntlm; \
|
||||
HttpContext* http; \
|
||||
|
|
|
@ -1483,8 +1483,9 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, int timeout)
|
|||
|
||||
tsg->bio->ptr = (void*) tsg;
|
||||
|
||||
transport->TcpIn = inChannel->tcp;
|
||||
transport->TcpOut = outChannel->tcp;
|
||||
transport->bioIn = inChannel->bio;
|
||||
transport->bioOut = outChannel->bio;
|
||||
|
||||
transport->GatewayEvent = rpc->client->PipeEvent;
|
||||
|
||||
return TRUE;
|
||||
|
|
|
@ -231,7 +231,7 @@ static BOOL freerdp_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
|
|||
{
|
||||
rdpTransport* transport = client->context->rdp->transport;
|
||||
|
||||
rfds[*rcount] = (void*)(long)(BIO_get_fd(transport->TcpIn->bufferedBio, NULL));
|
||||
rfds[*rcount] = (void*)(long)(BIO_get_fd(transport->bioIn, NULL));
|
||||
(*rcount)++;
|
||||
|
||||
return TRUE;
|
||||
|
@ -242,7 +242,7 @@ static HANDLE freerdp_peer_get_event_handle(freerdp_peer* client)
|
|||
HANDLE hEvent = NULL;
|
||||
rdpTransport* transport = client->context->rdp->transport;
|
||||
|
||||
BIO_get_event(transport->TcpIn->bufferedBio, &hEvent);
|
||||
BIO_get_event(transport->bioIn, &hEvent);
|
||||
|
||||
return hEvent;
|
||||
}
|
||||
|
|
|
@ -476,6 +476,16 @@ BIO_METHOD* BIO_s_simple_socket(void)
|
|||
|
||||
/* Buffered Socket BIO */
|
||||
|
||||
struct _WINPR_BIO_BUFFERED_SOCKET
|
||||
{
|
||||
BIO* socketBio;
|
||||
BIO* bufferedBio;
|
||||
BOOL readBlocked;
|
||||
BOOL writeBlocked;
|
||||
RingBuffer xmitBuffer;
|
||||
};
|
||||
typedef struct _WINPR_BIO_BUFFERED_SOCKET WINPR_BIO_BUFFERED_SOCKET;
|
||||
|
||||
long transport_bio_buffered_callback(BIO* bio, int mode, const char* argp, int argi, long argl, long ret)
|
||||
{
|
||||
return 1;
|
||||
|
@ -483,26 +493,28 @@ long transport_bio_buffered_callback(BIO* bio, int mode, const char* argp, int a
|
|||
|
||||
static int transport_bio_buffered_write(BIO* bio, const char* buf, int num)
|
||||
{
|
||||
int status, ret;
|
||||
rdpTcp* tcp = (rdpTcp*) bio->ptr;
|
||||
int nchunks, committedBytes, i;
|
||||
int i, ret;
|
||||
int status;
|
||||
int nchunks;
|
||||
int committedBytes;
|
||||
DataChunk chunks[2];
|
||||
WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*) bio->ptr;
|
||||
|
||||
ret = num;
|
||||
tcp->writeBlocked = FALSE;
|
||||
ptr->writeBlocked = FALSE;
|
||||
BIO_clear_flags(bio, BIO_FLAGS_WRITE);
|
||||
|
||||
/* we directly append extra bytes in the xmit buffer, this could be prevented
|
||||
* but for now it makes the code more simple.
|
||||
*/
|
||||
if (buf && num && !ringbuffer_write(&tcp->xmitBuffer, (const BYTE*) buf, num))
|
||||
if (buf && num && !ringbuffer_write(&ptr->xmitBuffer, (const BYTE*) buf, num))
|
||||
{
|
||||
WLog_ERR(TAG, "an error occured when writing (num: %d)", num);
|
||||
return -1;
|
||||
}
|
||||
|
||||
committedBytes = 0;
|
||||
nchunks = ringbuffer_peek(&tcp->xmitBuffer, chunks, ringbuffer_used(&tcp->xmitBuffer));
|
||||
nchunks = ringbuffer_peek(&ptr->xmitBuffer, chunks, ringbuffer_used(&ptr->xmitBuffer));
|
||||
|
||||
for (i = 0; i < nchunks; i++)
|
||||
{
|
||||
|
@ -522,7 +534,7 @@ static int transport_bio_buffered_write(BIO* bio, const char* buf, int num)
|
|||
if (BIO_should_write(bio->next_bio))
|
||||
{
|
||||
BIO_set_flags(bio, BIO_FLAGS_WRITE);
|
||||
tcp->writeBlocked = TRUE;
|
||||
ptr->writeBlocked = TRUE;
|
||||
goto out; /* EWOULDBLOCK */
|
||||
}
|
||||
}
|
||||
|
@ -534,7 +546,7 @@ static int transport_bio_buffered_write(BIO* bio, const char* buf, int num)
|
|||
}
|
||||
|
||||
out:
|
||||
ringbuffer_commit_read_bytes(&tcp->xmitBuffer, committedBytes);
|
||||
ringbuffer_commit_read_bytes(&ptr->xmitBuffer, committedBytes);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -542,9 +554,9 @@ out:
|
|||
static int transport_bio_buffered_read(BIO* bio, char* buf, int size)
|
||||
{
|
||||
int status;
|
||||
rdpTcp* tcp = (rdpTcp*) bio->ptr;
|
||||
WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*) bio->ptr;
|
||||
|
||||
tcp->readBlocked = FALSE;
|
||||
ptr->readBlocked = FALSE;
|
||||
BIO_clear_flags(bio, BIO_FLAGS_READ);
|
||||
|
||||
status = BIO_read(bio->next_bio, buf, size);
|
||||
|
@ -562,7 +574,7 @@ static int transport_bio_buffered_read(BIO* bio, char* buf, int size)
|
|||
if (BIO_should_read(bio->next_bio))
|
||||
{
|
||||
BIO_set_flags(bio, BIO_FLAGS_READ);
|
||||
tcp->readBlocked = TRUE;
|
||||
ptr->readBlocked = TRUE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
@ -584,19 +596,19 @@ static int transport_bio_buffered_gets(BIO* bio, char* str, int size)
|
|||
static long transport_bio_buffered_ctrl(BIO* bio, int cmd, long arg1, void* arg2)
|
||||
{
|
||||
int status = -1;
|
||||
rdpTcp* tcp = (rdpTcp*) bio->ptr;
|
||||
WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*) bio->ptr;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case BIO_CTRL_FLUSH:
|
||||
if (!ringbuffer_used(&tcp->xmitBuffer))
|
||||
if (!ringbuffer_used(&ptr->xmitBuffer))
|
||||
status = 1;
|
||||
else
|
||||
status = (transport_bio_buffered_write(bio, NULL, 0) >= 0) ? 1 : -1;
|
||||
break;
|
||||
|
||||
case BIO_CTRL_WPENDING:
|
||||
status = ringbuffer_used(&tcp->xmitBuffer);
|
||||
status = ringbuffer_used(&ptr->xmitBuffer);
|
||||
break;
|
||||
|
||||
case BIO_CTRL_PENDING:
|
||||
|
@ -604,11 +616,11 @@ static long transport_bio_buffered_ctrl(BIO* bio, int cmd, long arg1, void* arg2
|
|||
break;
|
||||
|
||||
case BIO_C_READ_BLOCKED:
|
||||
status = (int) tcp->readBlocked;
|
||||
status = (int) ptr->readBlocked;
|
||||
break;
|
||||
|
||||
case BIO_C_WRITE_BLOCKED:
|
||||
status = (int) tcp->writeBlocked;
|
||||
status = (int) ptr->writeBlocked;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -621,15 +633,38 @@ static long transport_bio_buffered_ctrl(BIO* bio, int cmd, long arg1, void* arg2
|
|||
|
||||
static int transport_bio_buffered_new(BIO* bio)
|
||||
{
|
||||
WINPR_BIO_BUFFERED_SOCKET* ptr;
|
||||
|
||||
bio->init = 1;
|
||||
bio->num = 0;
|
||||
bio->ptr = NULL;
|
||||
bio->flags = BIO_FLAGS_SHOULD_RETRY;
|
||||
|
||||
ptr = (WINPR_BIO_BUFFERED_SOCKET*) calloc(1, sizeof(WINPR_BIO_BUFFERED_SOCKET));
|
||||
|
||||
if (!ptr)
|
||||
return -1;
|
||||
|
||||
bio->ptr = (void*) ptr;
|
||||
|
||||
if (!ringbuffer_init(&ptr->xmitBuffer, 0x10000))
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int transport_bio_buffered_free(BIO* bio)
|
||||
{
|
||||
WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*) bio->ptr;
|
||||
|
||||
if (ptr->socketBio)
|
||||
{
|
||||
BIO_free(ptr->socketBio);
|
||||
ptr->socketBio = NULL;
|
||||
}
|
||||
|
||||
ringbuffer_destroy(&ptr->xmitBuffer);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1032,7 +1067,7 @@ BOOL freerdp_tcp_set_keep_alive_mode(int sockfd)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostname, int port, int timeout)
|
||||
int freerdp_tcp_connect(rdpSettings* settings, const char* hostname, int port, int timeout)
|
||||
{
|
||||
int status;
|
||||
int sockfd;
|
||||
|
@ -1041,7 +1076,7 @@ BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostnam
|
|||
BOOL ipcSocket = FALSE;
|
||||
|
||||
if (!hostname)
|
||||
return FALSE;
|
||||
return -1;
|
||||
|
||||
if (hostname[0] == '/')
|
||||
ipcSocket = TRUE;
|
||||
|
@ -1051,14 +1086,7 @@ BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostnam
|
|||
sockfd = freerdp_uds_connect(hostname);
|
||||
|
||||
if (sockfd < 0)
|
||||
return FALSE;
|
||||
|
||||
tcp->socketBio = BIO_new(BIO_s_simple_socket());
|
||||
|
||||
if (!tcp->socketBio)
|
||||
return FALSE;
|
||||
|
||||
BIO_set_fd(tcp->socketBio, sockfd, BIO_CLOSE);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1095,9 +1123,10 @@ BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostnam
|
|||
|
||||
status = getaddrinfo(hostname, port_str, &hints, &result);
|
||||
|
||||
if (status) {
|
||||
if (status)
|
||||
{
|
||||
WLog_ERR(TAG, "getaddrinfo: %s", gai_strerror(status));
|
||||
return FALSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
addr = result;
|
||||
|
@ -1119,25 +1148,18 @@ BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostnam
|
|||
if (sockfd < 0)
|
||||
{
|
||||
freeaddrinfo(result);
|
||||
return FALSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!freerdp_tcp_connect_timeout(sockfd, addr->ai_addr, addr->ai_addrlen, timeout))
|
||||
{
|
||||
fprintf(stderr, "failed to connect to %s\n", hostname);
|
||||
freeaddrinfo(result);
|
||||
return FALSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
freeaddrinfo(result);
|
||||
}
|
||||
|
||||
tcp->socketBio = BIO_new(BIO_s_simple_socket());
|
||||
|
||||
if (!tcp->socketBio)
|
||||
return FALSE;
|
||||
|
||||
BIO_set_fd(tcp->socketBio, sockfd, BIO_CLOSE);
|
||||
}
|
||||
|
||||
settings->IPv6Enabled = FALSE;
|
||||
|
@ -1165,7 +1187,7 @@ BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostnam
|
|||
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (void*) &optval, optlen) < 0)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to set receive buffer len");
|
||||
return FALSE;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1173,86 +1195,8 @@ BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostnam
|
|||
if (!ipcSocket)
|
||||
{
|
||||
if (!freerdp_tcp_set_keep_alive_mode(sockfd))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
tcp->bufferedBio = BIO_new(BIO_s_buffered_socket());
|
||||
|
||||
if (!tcp->bufferedBio)
|
||||
return FALSE;
|
||||
|
||||
tcp->bufferedBio->ptr = tcp;
|
||||
tcp->bufferedBio = BIO_push(tcp->bufferedBio, tcp->socketBio);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int freerdp_tcp_attach(rdpTcp* tcp, int sockfd)
|
||||
{
|
||||
if (tcp->socketBio)
|
||||
{
|
||||
tcp->socketBio = BIO_new(BIO_s_simple_socket());
|
||||
|
||||
if (!tcp->socketBio)
|
||||
return -1;
|
||||
|
||||
BIO_set_fd(tcp->socketBio, sockfd, BIO_CLOSE);
|
||||
}
|
||||
|
||||
if (!tcp->bufferedBio)
|
||||
{
|
||||
tcp->bufferedBio = BIO_new(BIO_s_buffered_socket());
|
||||
|
||||
if (!tcp->bufferedBio)
|
||||
return FALSE;
|
||||
|
||||
tcp->bufferedBio->ptr = tcp;
|
||||
|
||||
tcp->bufferedBio = BIO_push(tcp->bufferedBio, tcp->socketBio);
|
||||
}
|
||||
|
||||
ringbuffer_commit_read_bytes(&tcp->xmitBuffer, ringbuffer_used(&tcp->xmitBuffer));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
rdpTcp* freerdp_tcp_new()
|
||||
{
|
||||
rdpTcp* tcp;
|
||||
|
||||
tcp = (rdpTcp*) calloc(1, sizeof(rdpTcp));
|
||||
|
||||
if (!tcp)
|
||||
return NULL;
|
||||
|
||||
if (!ringbuffer_init(&tcp->xmitBuffer, 0x10000))
|
||||
goto out_free;
|
||||
|
||||
return tcp;
|
||||
|
||||
out_free:
|
||||
free(tcp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void freerdp_tcp_free(rdpTcp* tcp)
|
||||
{
|
||||
if (!tcp)
|
||||
return;
|
||||
|
||||
ringbuffer_destroy(&tcp->xmitBuffer);
|
||||
|
||||
if (tcp->socketBio)
|
||||
{
|
||||
BIO_free(tcp->socketBio);
|
||||
tcp->socketBio = NULL;
|
||||
}
|
||||
|
||||
if (tcp->bufferedBio)
|
||||
{
|
||||
BIO_free(tcp->bufferedBio);
|
||||
tcp->bufferedBio = NULL;
|
||||
}
|
||||
|
||||
free(tcp);
|
||||
return sockfd;
|
||||
}
|
||||
|
|
|
@ -31,12 +31,9 @@
|
|||
#include <winpr/stream.h>
|
||||
#include <winpr/winsock.h>
|
||||
|
||||
#include <freerdp/utils/ringbuffer.h>
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
#include <freerdp/utils/ringbuffer.h>
|
||||
|
||||
#define BIO_TYPE_TSG 65
|
||||
#define BIO_TYPE_SIMPLE 66
|
||||
|
@ -60,21 +57,9 @@
|
|||
#define BIO_wait_read(b, c) BIO_ctrl(b, BIO_C_WAIT_READ, c, NULL)
|
||||
#define BIO_wait_write(b, c) BIO_ctrl(b, BIO_C_WAIT_WRITE, c, NULL)
|
||||
|
||||
typedef struct rdp_tcp rdpTcp;
|
||||
BIO_METHOD* BIO_s_simple_socket(void);
|
||||
BIO_METHOD* BIO_s_buffered_socket(void);
|
||||
|
||||
struct rdp_tcp
|
||||
{
|
||||
BIO* socketBio;
|
||||
BIO* bufferedBio;
|
||||
BOOL readBlocked;
|
||||
BOOL writeBlocked;
|
||||
RingBuffer xmitBuffer;
|
||||
};
|
||||
|
||||
int freerdp_tcp_attach(rdpTcp* tcp, int sockfd);
|
||||
BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostname, int port, int timeout);
|
||||
|
||||
rdpTcp* freerdp_tcp_new();
|
||||
void freerdp_tcp_free(rdpTcp* tcp);
|
||||
int freerdp_tcp_connect(rdpSettings* settings, const char* hostname, int port, int timeout);
|
||||
|
||||
#endif /* __TCP_H */
|
||||
|
|
|
@ -67,15 +67,30 @@ wStream* transport_send_stream_init(rdpTransport* transport, int size)
|
|||
return s;
|
||||
}
|
||||
|
||||
void transport_attach(rdpTransport* transport, int sockfd)
|
||||
BOOL transport_attach(rdpTransport* transport, int sockfd)
|
||||
{
|
||||
if (!transport->TcpIn)
|
||||
transport->TcpIn = freerdp_tcp_new();
|
||||
BIO* socketBio;
|
||||
BIO* bufferedBio;
|
||||
|
||||
freerdp_tcp_attach(transport->TcpIn, sockfd);
|
||||
socketBio = BIO_new(BIO_s_simple_socket());
|
||||
|
||||
if (!socketBio)
|
||||
return FALSE;
|
||||
|
||||
BIO_set_fd(socketBio, sockfd, BIO_CLOSE);
|
||||
|
||||
bufferedBio = BIO_new(BIO_s_buffered_socket());
|
||||
|
||||
if (!bufferedBio)
|
||||
return FALSE;
|
||||
|
||||
bufferedBio = BIO_push(bufferedBio, socketBio);
|
||||
|
||||
transport->bioIn = bufferedBio;
|
||||
transport->frontBio = transport->bioIn;
|
||||
transport->SplitInputOutput = FALSE;
|
||||
transport->frontBio = transport->TcpIn->bufferedBio;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL transport_connect_rdp(rdpTransport* transport)
|
||||
|
@ -102,7 +117,7 @@ BOOL transport_connect_tls(rdpTransport* transport)
|
|||
{
|
||||
tls = transport->tls = tls_new(settings);
|
||||
transport->layer = TRANSPORT_LAYER_TLS;
|
||||
bio = transport->TcpIn->bufferedBio;
|
||||
bio = transport->bioIn;
|
||||
}
|
||||
|
||||
transport->tls = tls;
|
||||
|
@ -209,6 +224,7 @@ BOOL transport_connect_nla(rdpTransport* transport)
|
|||
|
||||
BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port, int timeout)
|
||||
{
|
||||
int sockfd;
|
||||
BOOL status = FALSE;
|
||||
rdpSettings* settings = transport->settings;
|
||||
|
||||
|
@ -232,16 +248,12 @@ BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 por
|
|||
}
|
||||
else
|
||||
{
|
||||
transport->TcpIn = freerdp_tcp_new();
|
||||
sockfd = freerdp_tcp_connect(settings, hostname, port, timeout);
|
||||
|
||||
if (!transport->TcpIn)
|
||||
if (sockfd < 1)
|
||||
return FALSE;
|
||||
|
||||
if (!freerdp_tcp_connect(transport->TcpIn, settings, hostname, port, timeout))
|
||||
return FALSE;
|
||||
|
||||
transport->frontBio = transport->TcpIn->bufferedBio;
|
||||
transport->SplitInputOutput = FALSE;
|
||||
transport_attach(transport, sockfd);
|
||||
|
||||
status = TRUE;
|
||||
}
|
||||
|
@ -274,7 +286,7 @@ BOOL transport_accept_tls(rdpTransport* transport)
|
|||
|
||||
transport->layer = TRANSPORT_LAYER_TLS;
|
||||
|
||||
if (!tls_accept(transport->tls, transport->TcpIn->bufferedBio, settings->CertificateFile, settings->PrivateKeyFile))
|
||||
if (!tls_accept(transport->tls, transport->bioIn, settings->CertificateFile, settings->PrivateKeyFile))
|
||||
return FALSE;
|
||||
|
||||
transport->frontBio = transport->tls->bio;
|
||||
|
@ -292,7 +304,7 @@ BOOL transport_accept_nla(rdpTransport* transport)
|
|||
|
||||
transport->layer = TRANSPORT_LAYER_TLS;
|
||||
|
||||
if (!tls_accept(transport->tls, transport->TcpIn->bufferedBio, settings->CertificateFile, settings->PrivateKeyFile))
|
||||
if (!tls_accept(transport->tls, transport->bioIn, settings->CertificateFile, settings->PrivateKeyFile))
|
||||
return FALSE;
|
||||
|
||||
transport->frontBio = transport->tls->bio;
|
||||
|
@ -325,18 +337,13 @@ BOOL transport_accept_nla(rdpTransport* transport)
|
|||
|
||||
static int transport_wait_for_read(rdpTransport* transport)
|
||||
{
|
||||
BIO* bio;
|
||||
rdpTcp* tcpIn = transport->TcpIn;
|
||||
|
||||
bio = tcpIn->bufferedBio;
|
||||
|
||||
if (BIO_read_blocked(bio))
|
||||
if (BIO_read_blocked(transport->bioIn))
|
||||
{
|
||||
return BIO_wait_read(bio, 10);
|
||||
return BIO_wait_read(transport->bioIn, 10);
|
||||
}
|
||||
else if (BIO_write_blocked(bio))
|
||||
else if (BIO_write_blocked(transport->bioIn))
|
||||
{
|
||||
return BIO_wait_write(bio, 10);
|
||||
return BIO_wait_write(transport->bioIn, 10);
|
||||
}
|
||||
|
||||
USleep(1000);
|
||||
|
@ -346,10 +353,8 @@ static int transport_wait_for_read(rdpTransport* transport)
|
|||
static int transport_wait_for_write(rdpTransport* transport)
|
||||
{
|
||||
BIO* bio;
|
||||
rdpTcp* tcpOut;
|
||||
|
||||
tcpOut = transport->SplitInputOutput ? transport->TcpOut : transport->TcpIn;
|
||||
bio = tcpOut->bufferedBio;
|
||||
bio = transport->SplitInputOutput ? transport->bioOut : transport->bioIn;
|
||||
|
||||
if (BIO_write_blocked(bio))
|
||||
{
|
||||
|
@ -640,9 +645,9 @@ int transport_write(rdpTransport* transport, wStream* s)
|
|||
if (transport->blocking || transport->settings->WaitForOutputBufferFlush)
|
||||
{
|
||||
/* blocking transport, we must ensure the write buffer is really empty */
|
||||
rdpTcp* out = transport->SplitInputOutput ? transport->TcpOut : transport->TcpIn;
|
||||
BIO* bio = transport->SplitInputOutput ? transport->bioOut : transport->bioIn;
|
||||
|
||||
while (BIO_write_blocked(out->bufferedBio))
|
||||
while (BIO_write_blocked(bio))
|
||||
{
|
||||
if (transport_wait_for_write(transport) < 0)
|
||||
{
|
||||
|
@ -650,7 +655,7 @@ int transport_write(rdpTransport* transport, wStream* s)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (BIO_flush(out->bufferedBio) < 1)
|
||||
if (BIO_flush(bio) < 1)
|
||||
{
|
||||
WLog_ERR(TAG, "error when flushing outputBuffer");
|
||||
return -1;
|
||||
|
@ -680,10 +685,10 @@ void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount)
|
|||
void* pfd;
|
||||
|
||||
#ifdef _WIN32
|
||||
BIO_get_event(transport->TcpIn->bufferedBio, &rfds[*rcount]);
|
||||
BIO_get_event(transport->bioIn, &rfds[*rcount]);
|
||||
(*rcount)++;
|
||||
#else
|
||||
rfds[*rcount] = (void*)(long)(BIO_get_fd(transport->TcpIn->bufferedBio, NULL));
|
||||
rfds[*rcount] = (void*)(long)(BIO_get_fd(transport->bioIn, NULL));
|
||||
(*rcount)++;
|
||||
#endif
|
||||
|
||||
|
@ -712,7 +717,7 @@ DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events)
|
|||
DWORD nCount = 0;
|
||||
|
||||
if (events)
|
||||
BIO_get_event(transport->TcpIn->bufferedBio, &events[nCount]);
|
||||
BIO_get_event(transport->bioIn, &events[nCount]);
|
||||
nCount++;
|
||||
|
||||
if (transport->ReceiveEvent)
|
||||
|
@ -734,11 +739,10 @@ DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events)
|
|||
|
||||
BOOL tranport_is_write_blocked(rdpTransport* transport)
|
||||
{
|
||||
if (BIO_write_blocked(transport->TcpIn->bufferedBio))
|
||||
if (BIO_write_blocked(transport->bioIn))
|
||||
return TRUE;
|
||||
|
||||
return transport->SplitInputOutput &&
|
||||
transport->TcpOut && BIO_write_blocked(transport->TcpOut->bufferedBio);
|
||||
return transport->SplitInputOutput && BIO_write_blocked(transport->bioOut);
|
||||
}
|
||||
|
||||
int tranport_drain_output_buffer(rdpTransport* transport)
|
||||
|
@ -746,20 +750,20 @@ int tranport_drain_output_buffer(rdpTransport* transport)
|
|||
BOOL status = FALSE;
|
||||
|
||||
/* First try to send some accumulated bytes in the send buffer */
|
||||
if (BIO_write_blocked(transport->TcpIn->bufferedBio))
|
||||
if (BIO_write_blocked(transport->bioIn))
|
||||
{
|
||||
if (BIO_flush(transport->TcpIn->bufferedBio) < 1)
|
||||
if (BIO_flush(transport->bioIn) < 1)
|
||||
return -1;
|
||||
|
||||
status |= BIO_write_blocked(transport->TcpIn->bufferedBio);
|
||||
status |= BIO_write_blocked(transport->bioIn);
|
||||
}
|
||||
|
||||
if (transport->SplitInputOutput && transport->TcpOut && BIO_write_blocked(transport->TcpOut->bufferedBio))
|
||||
if (transport->SplitInputOutput && BIO_write_blocked(transport->bioOut))
|
||||
{
|
||||
if (BIO_flush(transport->TcpOut->bufferedBio) < 1)
|
||||
if (BIO_flush(transport->bioOut) < 1)
|
||||
return -1;
|
||||
|
||||
status |= BIO_write_blocked(transport->TcpOut->bufferedBio);
|
||||
status |= BIO_write_blocked(transport->bioOut);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -829,7 +833,7 @@ BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking)
|
|||
|
||||
if (!transport->SplitInputOutput)
|
||||
{
|
||||
if (!BIO_set_nonblock(transport->TcpIn->bufferedBio, blocking ? FALSE : TRUE))
|
||||
if (!BIO_set_nonblock(transport->bioIn, blocking ? FALSE : TRUE))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -890,15 +894,15 @@ BOOL transport_disconnect(rdpTransport* transport)
|
|||
transport->tls = NULL;
|
||||
}
|
||||
|
||||
if (transport->TcpIn)
|
||||
if (transport->bioIn)
|
||||
{
|
||||
freerdp_tcp_free(transport->TcpIn);
|
||||
transport->TcpIn = NULL;
|
||||
BIO_free(transport->bioIn);
|
||||
transport->bioIn = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
transport->TcpIn = NULL;
|
||||
transport->TcpOut = NULL;
|
||||
transport->bioIn = NULL;
|
||||
transport->bioOut = NULL;
|
||||
|
||||
transport->layer = TRANSPORT_LAYER_TCP;
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@ struct rdp_transport
|
|||
BIO* frontBio;
|
||||
rdpTsg* tsg;
|
||||
rdpTls* tls;
|
||||
rdpTcp* TcpIn;
|
||||
rdpTcp* TcpOut;
|
||||
BIO* bioIn;
|
||||
BIO* bioOut;
|
||||
rdpContext* context;
|
||||
rdpCredssp* credssp;
|
||||
rdpSettings* settings;
|
||||
|
@ -84,7 +84,7 @@ struct rdp_transport
|
|||
|
||||
wStream* transport_send_stream_init(rdpTransport* transport, int size);
|
||||
BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port, int timeout);
|
||||
void transport_attach(rdpTransport* transport, int sockfd);
|
||||
BOOL transport_attach(rdpTransport* transport, int sockfd);
|
||||
BOOL transport_disconnect(rdpTransport* transport);
|
||||
BOOL transport_connect_rdp(rdpTransport* transport);
|
||||
BOOL transport_connect_tls(rdpTransport* transport);
|
||||
|
|
Loading…
Reference in New Issue