libfreerdp-core/transport: fix a bug in nonblocking mode that would break connection sequence.

This commit is contained in:
Vic Lee 2011-08-20 20:30:18 +08:00
parent a921ab1824
commit 11f10b2bb8
3 changed files with 22 additions and 8 deletions

View File

@ -45,8 +45,7 @@ boolean freerdp_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds
rdpRdp* rdp;
rdp = (rdpRdp*) instance->rdp;
rfds[*rcount] = (void*)(long)(rdp->transport->tcp->sockfd);
(*rcount)++;
transport_get_fds(rdp->transport, rfds, rcount);
return True;
}

View File

@ -200,7 +200,7 @@ int transport_read(rdpTransport* transport, STREAM* s)
#ifdef WITH_DEBUG_TRANSPORT
if (status > 0)
{
printf("Server > Client\n");
printf("Local < Remote\n");
freerdp_hexdump(s->data, status);
}
#endif
@ -235,7 +235,7 @@ int transport_write(rdpTransport* transport, STREAM* s)
#ifdef WITH_DEBUG_TRANSPORT
if (length > 0)
{
printf("Client > Server\n");
printf("Local > Remote\n");
freerdp_hexdump(s->data, length);
}
#endif
@ -257,19 +257,27 @@ int transport_write(rdpTransport* transport, STREAM* s)
/* when sending is blocked in nonblocking mode, the receiving buffer should be checked */
if (!transport->blocking)
transport_read_nonblocking(transport);
{
/* and in case we do have buffered some data, we set the event so next loop will get it */
if (transport_read_nonblocking(transport) > 0)
wait_obj_set(transport->recv_event);
}
}
sent += status;
stream_seek(s, status);
}
if (!transport->blocking)
transport_check_fds(transport);
return status;
}
void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount)
{
rfds[*rcount] = (void*)(long)(transport->tcp->sockfd);
(*rcount)++;
wait_obj_get_fds(transport->recv_event, rfds, rcount);
}
int transport_check_fds(rdpTransport* transport)
{
int pos;
@ -277,6 +285,8 @@ int transport_check_fds(rdpTransport* transport)
uint16 length;
STREAM* received;
wait_obj_clear(transport->recv_event);
status = transport_read_nonblocking(transport);
if (status < 0)
return status;
@ -361,6 +371,7 @@ rdpTransport* transport_new(rdpSettings* settings)
/* receive buffer for non-blocking read. */
transport->recv_buffer = stream_new(BUFFER_SIZE);
transport->recv_event = wait_obj_new();
/* buffers for blocking read/write */
transport->recv_stream = stream_new(BUFFER_SIZE);
@ -379,6 +390,7 @@ void transport_free(rdpTransport* transport)
stream_free(transport->recv_buffer);
stream_free(transport->recv_stream);
stream_free(transport->send_stream);
wait_obj_free(transport->recv_event);
tcp_free(transport->tcp);
xfree(transport);
}

View File

@ -46,6 +46,7 @@ typedef struct rdp_transport rdpTransport;
#include <freerdp/types.h>
#include <freerdp/settings.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/wait_obj.h>
typedef int (*TransportRecv) (rdpTransport* transport, STREAM* stream, void* extra);
@ -63,6 +64,7 @@ struct rdp_transport
void* recv_extra;
STREAM* recv_buffer;
TransportRecv recv_callback;
struct wait_obj* recv_event;
boolean blocking;
};
@ -79,6 +81,7 @@ boolean transport_accept_tls(rdpTransport* transport);
boolean transport_accept_nla(rdpTransport* transport);
int transport_read(rdpTransport* transport, STREAM* s);
int transport_write(rdpTransport* transport, STREAM* s);
void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount);
int transport_check_fds(rdpTransport* transport);
boolean transport_set_blocking_mode(rdpTransport* transport, boolean blocking);
rdpTransport* transport_new(rdpSettings* settings);