#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)
{
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;
#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)
#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;
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);
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);
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);
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);
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;
}