libfreerdp-core: move wait_read/wait_write operations under BIO layer
This commit is contained in:
parent
b7a619ff8a
commit
c001a69d50
@ -249,6 +249,78 @@ static long transport_bio_simple_ctrl(BIO* bio, int cmd, long arg1, void* arg2)
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
else if (cmd == BIO_C_WAIT_READ)
|
||||
{
|
||||
int timeout = (int) arg1;
|
||||
int sockfd = (int) ptr->socket;
|
||||
#ifdef HAVE_POLL_H
|
||||
struct pollfd pollset;
|
||||
|
||||
pollset.fd = sockfd;
|
||||
pollset.events = POLLIN;
|
||||
pollset.revents = 0;
|
||||
|
||||
do
|
||||
{
|
||||
status = poll(&pollset, 1, timeout);
|
||||
}
|
||||
while ((status < 0) && (errno == EINTR));
|
||||
#else
|
||||
fd_set rset;
|
||||
struct timeval tv;
|
||||
|
||||
FD_ZERO(&rset);
|
||||
FD_SET(sockfd, &rset);
|
||||
|
||||
if (timeout)
|
||||
{
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = (timeout % 1000) * 1000;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
status = select(sockfd + 1, &rset, NULL, NULL, timeout ? &tv : NULL);
|
||||
}
|
||||
while ((status < 0) && (errno == EINTR));
|
||||
#endif
|
||||
}
|
||||
else if (cmd == BIO_C_WAIT_WRITE)
|
||||
{
|
||||
int timeout = (int) arg1;
|
||||
int sockfd = (int) ptr->socket;
|
||||
#ifdef HAVE_POLL_H
|
||||
struct pollfd pollset;
|
||||
|
||||
pollset.fd = sockfd;
|
||||
pollset.events = POLLOUT;
|
||||
pollset.revents = 0;
|
||||
|
||||
do
|
||||
{
|
||||
status = poll(&pollset, 1, timeout);
|
||||
}
|
||||
while ((status < 0) && (errno == EINTR));
|
||||
#else
|
||||
fd_set rset;
|
||||
struct timeval tv;
|
||||
|
||||
FD_ZERO(&rset);
|
||||
FD_SET(sockfd, &rset);
|
||||
|
||||
if (timeout)
|
||||
{
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = (timeout % 1000) * 1000;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
status = select(sockfd + 1, NULL, &rset, NULL, timeout ? &tv : NULL);
|
||||
}
|
||||
while ((status < 0) && (errno == EINTR));
|
||||
#endif
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@ -1185,82 +1257,6 @@ int freerdp_tcp_attach(rdpTcp* tcp, int sockfd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int freerdp_tcp_wait_read(rdpTcp* tcp, DWORD dwMilliSeconds)
|
||||
{
|
||||
int status;
|
||||
|
||||
#ifdef HAVE_POLL_H
|
||||
struct pollfd pollset;
|
||||
|
||||
pollset.fd = tcp->sockfd;
|
||||
pollset.events = POLLIN;
|
||||
pollset.revents = 0;
|
||||
|
||||
do
|
||||
{
|
||||
status = poll(&pollset, 1, dwMilliSeconds);
|
||||
}
|
||||
while ((status < 0) && (errno == EINTR));
|
||||
#else
|
||||
struct timeval tv;
|
||||
fd_set rset;
|
||||
|
||||
FD_ZERO(&rset);
|
||||
FD_SET(tcp->sockfd, &rset);
|
||||
|
||||
if (dwMilliSeconds)
|
||||
{
|
||||
tv.tv_sec = dwMilliSeconds / 1000;
|
||||
tv.tv_usec = (dwMilliSeconds % 1000) * 1000;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
status = select(tcp->sockfd + 1, &rset, NULL, NULL, dwMilliSeconds ? &tv : NULL);
|
||||
}
|
||||
while ((status < 0) && (errno == EINTR));
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
int freerdp_tcp_wait_write(rdpTcp* tcp, DWORD dwMilliSeconds)
|
||||
{
|
||||
int status;
|
||||
|
||||
#ifdef HAVE_POLL_H
|
||||
struct pollfd pollset;
|
||||
|
||||
pollset.fd = tcp->sockfd;
|
||||
pollset.events = POLLOUT;
|
||||
pollset.revents = 0;
|
||||
|
||||
do
|
||||
{
|
||||
status = poll(&pollset, 1, dwMilliSeconds);
|
||||
}
|
||||
while ((status < 0) && (errno == EINTR));
|
||||
#else
|
||||
struct timeval tv;
|
||||
fd_set rset;
|
||||
|
||||
FD_ZERO(&rset);
|
||||
FD_SET(tcp->sockfd, &rset);
|
||||
|
||||
if (dwMilliSeconds)
|
||||
{
|
||||
tv.tv_sec = dwMilliSeconds / 1000;
|
||||
tv.tv_usec = (dwMilliSeconds % 1000) * 1000;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
status = select(tcp->sockfd + 1, NULL, &rset, NULL, dwMilliSeconds ? &tv : NULL);
|
||||
}
|
||||
while ((status < 0) && (errno == EINTR));
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
rdpTcp* freerdp_tcp_new()
|
||||
{
|
||||
rdpTcp* tcp;
|
||||
|
@ -48,6 +48,8 @@
|
||||
#define BIO_C_SET_NONBLOCK 1104
|
||||
#define BIO_C_READ_BLOCKED 1105
|
||||
#define BIO_C_WRITE_BLOCKED 1106
|
||||
#define BIO_C_WAIT_READ 1107
|
||||
#define BIO_C_WAIT_WRITE 1108
|
||||
|
||||
#define BIO_set_socket(b, s, c) BIO_ctrl(b, BIO_C_SET_SOCKET, c, s);
|
||||
#define BIO_get_socket(b, c) BIO_ctrl(b, BIO_C_GET_SOCKET, 0, (char*) c)
|
||||
@ -55,6 +57,8 @@
|
||||
#define BIO_set_nonblock(b, c) BIO_ctrl(b, BIO_C_SET_NONBLOCK, c, NULL)
|
||||
#define BIO_read_blocked(b) BIO_ctrl(b, BIO_C_READ_BLOCKED, 0, NULL)
|
||||
#define BIO_write_blocked(b) BIO_ctrl(b, BIO_C_WRITE_BLOCKED, 0, NULL)
|
||||
#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;
|
||||
|
||||
@ -73,9 +77,6 @@ struct rdp_tcp
|
||||
int freerdp_tcp_attach(rdpTcp* tcp, int sockfd);
|
||||
BOOL freerdp_tcp_connect(rdpTcp* tcp, rdpSettings* settings, const char* hostname, int port, int timeout);
|
||||
|
||||
int freerdp_tcp_wait_read(rdpTcp* tcp, DWORD dwMilliSeconds);
|
||||
int freerdp_tcp_wait_write(rdpTcp* tcp, DWORD dwMilliSeconds);
|
||||
|
||||
rdpTcp* freerdp_tcp_new();
|
||||
void freerdp_tcp_free(rdpTcp* tcp);
|
||||
|
||||
|
@ -332,11 +332,11 @@ static int transport_wait_for_read(rdpTransport* transport)
|
||||
|
||||
if (BIO_read_blocked(bio))
|
||||
{
|
||||
return freerdp_tcp_wait_read(tcpIn, 10);
|
||||
return BIO_wait_read(bio, 10);
|
||||
}
|
||||
else if (BIO_write_blocked(bio))
|
||||
{
|
||||
return freerdp_tcp_wait_write(tcpIn, 10);
|
||||
return BIO_wait_write(bio, 10);
|
||||
}
|
||||
|
||||
USleep(1000);
|
||||
@ -353,11 +353,11 @@ static int transport_wait_for_write(rdpTransport* transport)
|
||||
|
||||
if (BIO_write_blocked(bio))
|
||||
{
|
||||
return freerdp_tcp_wait_write(tcpOut, 10);
|
||||
return BIO_wait_write(bio, 10);
|
||||
}
|
||||
else if (BIO_read_blocked(bio))
|
||||
{
|
||||
return freerdp_tcp_wait_read(tcpOut, 10);
|
||||
return BIO_wait_read(bio, 10);
|
||||
}
|
||||
|
||||
USleep(1000);
|
||||
@ -980,7 +980,7 @@ rdpTransport* transport_new(rdpContext* context)
|
||||
transport->ReceivePool = StreamPool_New(TRUE, BUFFER_SIZE);
|
||||
|
||||
if (!transport->ReceivePool)
|
||||
goto out_free_tcpin;
|
||||
goto out_free_transport;
|
||||
|
||||
/* receive buffer for non-blocking read. */
|
||||
transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0);
|
||||
@ -1019,8 +1019,7 @@ out_free_receivebuffer:
|
||||
StreamPool_Return(transport->ReceivePool, transport->ReceiveBuffer);
|
||||
out_free_receivepool:
|
||||
StreamPool_Free(transport->ReceivePool);
|
||||
out_free_tcpin:
|
||||
freerdp_tcp_free(transport->TcpIn);
|
||||
out_free_transport:
|
||||
free(transport);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user