mirror of https://github.com/FreeRDP/FreeRDP
wfreerdp: fix tcp non-blocking read
This commit is contained in:
parent
5de4cdbedc
commit
347f626a61
|
@ -172,7 +172,7 @@ int wfreerdp_run(freerdp* instance)
|
|||
memset(rfds, 0, sizeof(rfds));
|
||||
memset(wfds, 0, sizeof(wfds));
|
||||
|
||||
if (!instance->Connect(instance))
|
||||
if (instance->Connect(instance) != True)
|
||||
return 0;
|
||||
|
||||
chanman = GET_CHANMAN(instance);
|
||||
|
@ -349,7 +349,7 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||
wnd_cls.cbWndExtra = 0;
|
||||
wnd_cls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wnd_cls.hCursor = g_default_cursor;
|
||||
wnd_cls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
||||
wnd_cls.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
|
||||
wnd_cls.lpszMenuName = NULL;
|
||||
wnd_cls.lpszClassName = g_wnd_class_name;
|
||||
wnd_cls.hInstance = hInstance;
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
|
||||
boolean rdp_client_connect(rdpRdp* rdp)
|
||||
{
|
||||
boolean ret;
|
||||
boolean status;
|
||||
|
||||
rdp->settings->autologon = 1;
|
||||
|
||||
|
@ -76,21 +76,21 @@ boolean rdp_client_connect(rdpRdp* rdp)
|
|||
return False;
|
||||
}
|
||||
|
||||
ret = False;
|
||||
status = False;
|
||||
if (rdp->nego->selected_protocol & PROTOCOL_NLA)
|
||||
ret = transport_connect_nla(rdp->transport);
|
||||
status = transport_connect_nla(rdp->transport);
|
||||
else if (rdp->nego->selected_protocol & PROTOCOL_TLS)
|
||||
ret = transport_connect_tls(rdp->transport);
|
||||
status = transport_connect_tls(rdp->transport);
|
||||
else if (rdp->nego->selected_protocol == PROTOCOL_RDP) /* 0 */
|
||||
ret = transport_connect_rdp(rdp->transport);
|
||||
status = transport_connect_rdp(rdp->transport);
|
||||
|
||||
if (!ret)
|
||||
if (status != True)
|
||||
return False;
|
||||
|
||||
rdp_set_blocking_mode(rdp, False);
|
||||
rdp->state = CONNECTION_STATE_NEGO;
|
||||
|
||||
if (!mcs_send_connect_initial(rdp->mcs))
|
||||
if (mcs_send_connect_initial(rdp->mcs) != True)
|
||||
{
|
||||
printf("Error: unable to send MCS Connect Initial\n");
|
||||
return False;
|
||||
|
|
|
@ -269,6 +269,7 @@ boolean nego_recv(rdpTransport* transport, STREAM* s, void* extra)
|
|||
|
||||
if (tpkt_read_header(s) == 0)
|
||||
return False;
|
||||
|
||||
li = tpdu_read_connection_confirm(s);
|
||||
|
||||
if (li > 6)
|
||||
|
|
|
@ -183,63 +183,63 @@ static boolean peer_recv_pdu(rdpPeer* peer, STREAM* s)
|
|||
return peer_recv_fastpath_pdu(peer, s);
|
||||
}
|
||||
|
||||
static int peer_recv_callback(rdpTransport* transport, STREAM* s, void* extra)
|
||||
static boolean peer_recv_callback(rdpTransport* transport, STREAM* s, void* extra)
|
||||
{
|
||||
rdpPeer* peer = (rdpPeer*)extra;
|
||||
rdpPeer* peer = (rdpPeer*) extra;
|
||||
|
||||
switch (peer->rdp->state)
|
||||
{
|
||||
case CONNECTION_STATE_INITIAL:
|
||||
if (!rdp_server_accept_nego(peer->rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_NEGO:
|
||||
if (!rdp_server_accept_mcs_connect_initial(peer->rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_MCS_CONNECT:
|
||||
if (!rdp_server_accept_mcs_erect_domain_request(peer->rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_MCS_ERECT_DOMAIN:
|
||||
if (!rdp_server_accept_mcs_attach_user_request(peer->rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_MCS_ATTACH_USER:
|
||||
if (!rdp_server_accept_mcs_channel_join_request(peer->rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_MCS_CHANNEL_JOIN:
|
||||
if (!rdp_server_accept_client_info(peer->rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_LICENSE:
|
||||
if (!rdp_server_accept_confirm_active(peer->rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_ACTIVE:
|
||||
if (!peer_recv_pdu(peer, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Invalid state %d\n", peer->rdp->state);
|
||||
return -1;
|
||||
return False;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return True;
|
||||
}
|
||||
|
||||
static void freerdp_peer_disconnect(freerdp_peer* client)
|
||||
{
|
||||
rdpPeer* peer = (rdpPeer*)client->peer;
|
||||
rdpPeer* peer = (rdpPeer*) client->peer;
|
||||
|
||||
transport_disconnect(peer->rdp->transport);
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ freerdp_peer* freerdp_peer_new(int sockfd)
|
|||
peer->client = client;
|
||||
peer->rdp = rdp_new(NULL);
|
||||
|
||||
client->peer = (void*)peer;
|
||||
client->peer = (void*) peer;
|
||||
client->settings = peer->rdp->settings;
|
||||
client->input = peer->rdp->input;
|
||||
client->update = peer->rdp->update;
|
||||
|
|
|
@ -729,7 +729,7 @@ void rdp_recv(rdpRdp* rdp)
|
|||
rdp_recv_pdu(rdp, s);
|
||||
}
|
||||
|
||||
static int rdp_recv_callback(rdpTransport* transport, STREAM* s, void* extra)
|
||||
static boolean rdp_recv_callback(rdpTransport* transport, STREAM* s, void* extra)
|
||||
{
|
||||
rdpRdp* rdp = (rdpRdp*) extra;
|
||||
|
||||
|
@ -737,43 +737,43 @@ static int rdp_recv_callback(rdpTransport* transport, STREAM* s, void* extra)
|
|||
{
|
||||
case CONNECTION_STATE_NEGO:
|
||||
if (!rdp_client_connect_mcs_connect_response(rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_MCS_ATTACH_USER:
|
||||
if (!rdp_client_connect_mcs_attach_user_confirm(rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_MCS_CHANNEL_JOIN:
|
||||
if (!rdp_client_connect_mcs_channel_join_confirm(rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_LICENSE:
|
||||
if (!rdp_client_connect_license(rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_CAPABILITY:
|
||||
if (!rdp_client_connect_demand_active(rdp, s))
|
||||
{
|
||||
printf("rdp_client_connect_demand_active failed\n");
|
||||
return -1;
|
||||
return False;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONNECTION_STATE_ACTIVE:
|
||||
if (!rdp_recv_pdu(rdp, s))
|
||||
return -1;
|
||||
return False;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Invalid state %d\n", rdp->state);
|
||||
return -1;
|
||||
return False;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return True;
|
||||
}
|
||||
|
||||
int rdp_send_channel_data(rdpRdp* rdp, int channel_id, uint8* data, int size)
|
||||
|
|
|
@ -160,12 +160,25 @@ int tcp_read(rdpTcp* tcp, uint8* data, int length)
|
|||
|
||||
if (status <= 0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int wsa_error = WSAGetLastError();
|
||||
|
||||
/* No data available */
|
||||
if (wsa_error == WSAEWOULDBLOCK)
|
||||
return 0;
|
||||
|
||||
/* When peer disconnects we get status 0 with no error. */
|
||||
if (status < 0)
|
||||
printf("recv() error: %d\n", wsa_error);
|
||||
#else
|
||||
/* No data available */
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
return 0;
|
||||
|
||||
/* When peer disconnects we get status 0 with no error. */
|
||||
if (status < 0)
|
||||
perror("recv");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
|
@ -239,12 +252,6 @@ rdpTcp* tcp_new(rdpSettings* settings)
|
|||
{
|
||||
rdpTcp* tcp;
|
||||
|
||||
#ifdef _WIN32
|
||||
int wsaStatus;
|
||||
WSADATA wsaData;
|
||||
WORD wVersionRequested;
|
||||
#endif
|
||||
|
||||
tcp = (rdpTcp*) xzalloc(sizeof(rdpTcp));
|
||||
|
||||
if (tcp != NULL)
|
||||
|
@ -253,14 +260,6 @@ rdpTcp* tcp_new(rdpSettings* settings)
|
|||
tcp->settings = settings;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
wVersionRequested = MAKEWORD(2, 2);
|
||||
wsaStatus = WSAStartup(wVersionRequested, &wsaData);
|
||||
|
||||
if (wsaStatus != 0)
|
||||
printf("WSAStartup failed with error: %d\n", wsaStatus);
|
||||
#endif
|
||||
|
||||
return tcp;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ typedef struct rdp_transport rdpTransport;
|
|||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/wait_obj.h>
|
||||
|
||||
typedef int (*TransportRecv) (rdpTransport* transport, STREAM* stream, void* extra);
|
||||
typedef boolean (*TransportRecv) (rdpTransport* transport, STREAM* stream, void* extra);
|
||||
|
||||
struct rdp_transport
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue