Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to offload io operations to external implementation #6324

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 0 additions & 13 deletions client/common/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -3015,19 +3015,6 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,

settings->MultifragMaxRequestSize = (UINT32)val;
}
CommandLineSwitchCase(arg, "max-loop-time")
{
LONGLONG val;

if (!value_to_int(arg->Value, &val, -1, UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;

if (val < 0)
settings->MaxTimeInCheckLoop =
10 * 60 * 60 * 1000; /* 10 hours can be considered as infinite */
else
settings->MaxTimeInCheckLoop = (UINT32)val;
}
CommandLineSwitchCase(arg, "auto-request-control")
{
if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteAssistanceRequestControl,
Expand Down
2 changes: 0 additions & 2 deletions client/common/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ static const COMMAND_LINE_ARGUMENT_A args[] = {
NULL, -1, NULL, "Set the default log level, see wLog(7) for details" },
{ "max-fast-path-size", COMMAND_LINE_VALUE_REQUIRED, "<size>", NULL, NULL, -1, NULL,
"Specify maximum fast-path update size" },
{ "max-loop-time", COMMAND_LINE_VALUE_REQUIRED, "<time>", NULL, NULL, -1, NULL,
"Specify maximum time in milliseconds spend treating packets" },
{ "menu-anims", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL,
"menu animations" },
{ "microphone", COMMAND_LINE_VALUE_OPTIONAL,
Expand Down
1 change: 1 addition & 0 deletions include/freerdp/freerdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ extern "C"
FREERDP_API const char* freerdp_get_logon_error_info_data(UINT32 data);

FREERDP_API ULONG freerdp_get_transport_sent(rdpContext* context, BOOL resetCount);
FREERDP_API void freerdp_set_transport_callbacks(rdpContext* context, void* io_callbacks);
sss123next marked this conversation as resolved.
Show resolved Hide resolved

FREERDP_API BOOL freerdp_nla_impersonate(rdpContext* context);
FREERDP_API BOOL freerdp_nla_revert_to_self(rdpContext* context);
Expand Down
89 changes: 89 additions & 0 deletions include/freerdp/io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* IO Update Interface API
*
* Copyright 2020 Gluzskiy Alexandr <sss at sss dot chaoslab dot ru>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FREERDP_UPDATE_IO_H
#define FREERDP_UPDATE_IO_H
/* TODO:
* RDG
* RPC
*/

#include <freerdp/types.h>

typedef struct rdp_transport rdpTransport;
typedef struct bio_st BIO;

typedef int (*pTCPConnect)(rdpContext* context, rdpSettings* settings, const char* hostname,
int port, DWORD timeout);
typedef BOOL (*pTLSConnect)(rdpTransport* transport);
typedef BOOL (*pProxyConnect)(rdpSettings* settings, BIO* bufferedBio, const char* proxyUsername,
const char* proxyPassword, const char* hostname, UINT16 port);
typedef BOOL (*pTransportAttach)(rdpTransport* transport, int sockfd);
typedef BOOL (*pTransportDisconnect)(rdpTransport* transport);

typedef int (*pRead)(rdpContext* context, const uint8_t* buf, size_t buf_size);
sss123next marked this conversation as resolved.
Show resolved Hide resolved
typedef int (*pWrite)(rdpContext* context, const uint8_t* buf, size_t buf_size);
sss123next marked this conversation as resolved.
Show resolved Hide resolved
typedef int (*pDataHandler)(rdpContext* context, const uint8_t* buf, size_t buf_size);
sss123next marked this conversation as resolved.
Show resolved Hide resolved

struct rdp_io_update
{
rdpContext* context; /* 0 */
UINT32 paddingA[16 - 1]; /* 1 */

/* switchable connect
* used to create tcp connection */
pTCPConnect TCPConnect; /* 17 */

/* switchable TLSConnect
* used to setup tls on already established TCP connection */
pTLSConnect TLSConnect;

/* switchable proxy_connect
* used to initialize proxy connection,
* can be implemented inside TcpConnect and just return TRUE,
* used to maintain compatibility with old design. */
pProxyConnect ProxyConnect; /* 18 */

/* should noop and return TRUE, used to mimic
* current freerdp design */
pTransportAttach TransportAttach; /* 19 */

/* callback used to shutdown whole io operations */
pTransportDisconnect TransportDisconnect; /* 20 */

UINT32 paddingB[32 - 21]; /* 21 */

/* switchable read
* used to read bytes from IO backend */
pWrite Read; /* 33 */

/* switchable write
* used to write bytes to IO backend */
pWrite Write; /* 34 */

/* switchable data handler
* used if IO backed doing internal polling and reading
* and just passing recieved data to freerdp */
pDataHandler DataHandler; /* 35 */

UINT32 paddingC[48 - 36]; /* 36 */
};
typedef struct rdp_io_update rdpIoUpdate;

#endif /* FREERDP_UPDATE_IO_H */
1 change: 0 additions & 1 deletion include/freerdp/peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ struct rdp_freerdp_peer

psPeerIsWriteBlocked IsWriteBlocked;
psPeerDrainOutputBuffer DrainOutputBuffer;
psPeerHasMoreToRead HasMoreToRead;
psPeerGetEventHandles GetEventHandles;
psPeerAdjustMonitorsLayout AdjustMonitorsLayout;
psPeerClientCapabilities ClientCapabilities;
Expand Down
3 changes: 1 addition & 2 deletions include/freerdp/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ typedef struct _RDPDR_PARALLEL RDPDR_PARALLEL;
#define FreeRDP_Domain (23)
#define FreeRDP_PasswordHash (24)
#define FreeRDP_WaitForOutputBufferFlush (25)
#define FreeRDP_MaxTimeInCheckLoop (26)
#define FreeRDP_AcceptedCert (27)
#define FreeRDP_AcceptedCertLength (28)
#define FreeRDP_RdpVersion (128)
Expand Down Expand Up @@ -919,7 +918,7 @@ struct rdp_settings
ALIGN64 char* Domain; /* 23 */
ALIGN64 char* PasswordHash; /* 24 */
ALIGN64 BOOL WaitForOutputBufferFlush; /* 25 */
ALIGN64 UINT32 MaxTimeInCheckLoop; /* 26 */
UINT64 padding0026[1];
ALIGN64 char* AcceptedCert; /* 27 */
ALIGN64 UINT32 AcceptedCertLength; /* 28 */
UINT64 padding0064[64 - 29]; /* 29 */
Expand Down
4 changes: 3 additions & 1 deletion include/freerdp/update.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct rdp_update rdpUpdate;
#include <freerdp/altsec.h>
#include <freerdp/window.h>
#include <freerdp/pointer.h>
#include <freerdp/io.h>

/* Bitmap Updates */
#define EX_COMPRESSED_BITMAP_HEADER_PRESENT 0x01
Expand Down Expand Up @@ -223,7 +224,8 @@ struct rdp_update
rdpSecondaryUpdate* secondary; /* 34 */
rdpAltSecUpdate* altsec; /* 35 */
rdpWindowUpdate* window; /* 36 */
UINT32 paddingC[48 - 37]; /* 37 */
rdpIoUpdate* io; /* 37 */
UINT32 paddingC[48 - 38]; /* 38 */

pRefreshRect RefreshRect; /* 48 */
pSuppressOutput SuppressOutput; /* 49 */
Expand Down
7 changes: 0 additions & 7 deletions libfreerdp/common/settings_getters.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,9 +1404,6 @@ UINT32 freerdp_settings_get_uint32(const rdpSettings* settings, size_t id)
case FreeRDP_LoadBalanceInfoLength:
return settings->LoadBalanceInfoLength;

case FreeRDP_MaxTimeInCheckLoop:
return settings->MaxTimeInCheckLoop;

case FreeRDP_MonitorCount:
return settings->MonitorCount;

Expand Down Expand Up @@ -1802,10 +1799,6 @@ BOOL freerdp_settings_set_uint32(rdpSettings* settings, size_t id, UINT32 val)
settings->LoadBalanceInfoLength = val;
break;

case FreeRDP_MaxTimeInCheckLoop:
settings->MaxTimeInCheckLoop = val;
break;

case FreeRDP_MonitorCount:
settings->MonitorCount = val;
break;
Expand Down
1 change: 0 additions & 1 deletion libfreerdp/common/settings_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ static const struct settings_str_entry settings_map[] = {
{ FreeRDP_KeyboardType, 3, "FreeRDP_KeyboardType" },
{ FreeRDP_LargePointerFlag, 3, "FreeRDP_LargePointerFlag" },
{ FreeRDP_LoadBalanceInfoLength, 3, "FreeRDP_LoadBalanceInfoLength" },
{ FreeRDP_MaxTimeInCheckLoop, 3, "FreeRDP_MaxTimeInCheckLoop" },
{ FreeRDP_MonitorCount, 3, "FreeRDP_MonitorCount" },
{ FreeRDP_MonitorDefArraySize, 3, "FreeRDP_MonitorDefArraySize" },
{ FreeRDP_MonitorLocalShiftX, 3, "FreeRDP_MonitorLocalShiftX" },
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp/core/activation.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s)

rdp_client_transition_to_state(rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE);

for (timeout = 0; timeout < rdp->settings->TcpAckTimeout; timeout += 100)
for (timeout = 0; timeout < rdp->settings->TcpAckTimeout; timeout += 10)
{
if (rdp_check_fds(rdp) < 0)
return FALSE;
Expand All @@ -304,7 +304,7 @@ BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s)
if (rdp->state == CONNECTION_STATE_ACTIVE)
return TRUE;

Sleep(100);
Sleep(10);
}

WLog_ERR(TAG, "Timeout waiting for activation");
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ BOOL rdp_client_connect(rdpRdp* rdp)
return FALSE;
}

for (timeout = 0; timeout < settings->TcpAckTimeout; timeout += 100)
for (timeout = 0; timeout < settings->TcpAckTimeout; timeout += 10)
{
if (rdp_check_fds(rdp) < 0)
{
Expand All @@ -373,7 +373,7 @@ BOOL rdp_client_connect(rdpRdp* rdp)
if (rdp->state == CONNECTION_STATE_ACTIVE)
return TRUE;

Sleep(100);
Sleep(10);
}

WLog_ERR(TAG, "Timeout waiting for activation");
Expand Down
1 change: 0 additions & 1 deletion libfreerdp/core/freerdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ BOOL freerdp_context_new(freerdp* instance)
goto fail;
}

update_register_client_callbacks(rdp->update);
instance->context->abortEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

if (!instance->context->abortEvent)
Expand Down
1 change: 0 additions & 1 deletion libfreerdp/core/gateway/rdg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,6 @@ static BOOL rdg_tls_connect(rdpRdg* rdg, rdpTls* tls, const char* peerAddress, i

if (settings->GatewayPort > UINT16_MAX)
return FALSE;

sockfd = freerdp_tcp_connect(rdg->context, settings, peerAddress ? peerAddress : peerHostname,
peerPort, timeout);

Expand Down
7 changes: 0 additions & 7 deletions libfreerdp/core/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,11 +756,6 @@ static int freerdp_peer_drain_output_buffer(freerdp_peer* peer)
return transport_drain_output_buffer(transport);
}

static BOOL freerdp_peer_has_more_to_read(freerdp_peer* peer)
{
return peer->context->rdp->transport->haveMoreBytesToRead;
}

static LicenseCallbackResult freerdp_peer_nolicense(freerdp_peer* peer, wStream* s)
{
rdpRdp* rdp = peer->context->rdp;
Expand Down Expand Up @@ -826,7 +821,6 @@ BOOL freerdp_peer_context_new(freerdp_peer* client)
transport_set_blocking_mode(rdp->transport, FALSE);
client->IsWriteBlocked = freerdp_peer_is_write_blocked;
client->DrainOutputBuffer = freerdp_peer_drain_output_buffer;
client->HasMoreToRead = freerdp_peer_has_more_to_read;
client->LicenseCallback = freerdp_peer_nolicense;
IFCALLRET(client->ContextNew, ret, client, client->context);

Expand Down Expand Up @@ -893,7 +887,6 @@ freerdp_peer* freerdp_peer_new(int sockfd)
client->SendChannelData = freerdp_peer_send_channel_data;
client->IsWriteBlocked = freerdp_peer_is_write_blocked;
client->DrainOutputBuffer = freerdp_peer_drain_output_buffer;
client->HasMoreToRead = freerdp_peer_has_more_to_read;
client->VirtualChannelOpen = freerdp_peer_virtual_channel_open;
client->VirtualChannelClose = freerdp_peer_virtual_channel_close;
client->VirtualChannelWrite = freerdp_peer_virtual_channel_write;
Expand Down
13 changes: 11 additions & 2 deletions libfreerdp/core/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,10 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri_in)
return rc;
}

BOOL proxy_connect(rdpSettings* settings, BIO* bufferedBio, const char* proxyUsername,
const char* proxyPassword, const char* hostname, UINT16 port)
BOOL proxy_connect_impl(rdpSettings* settings, BIO* _bio, const char* proxyUsername,
const char* proxyPassword, const char* hostname, UINT16 port)
{
BIO* bufferedBio = _bio;
switch (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType))
{
case PROXY_TYPE_NONE:
Expand All @@ -392,6 +393,14 @@ BOOL proxy_connect(rdpSettings* settings, BIO* bufferedBio, const char* proxyUse
}
}

BOOL proxy_connect(rdpSettings* settings, BIO* bio, const char* proxyUsername,
const char* proxyPassword, const char* hostname, UINT16 port)
{
freerdp* instance = settings->instance;
return instance->context->update->io->ProxyConnect(settings, bio, proxyUsername, proxyPassword,
hostname, port);
}

static const char* get_response_header(char* response)
{
char* current_pos = strchr(response, '\r');
Expand Down
3 changes: 3 additions & 0 deletions libfreerdp/core/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
BOOL proxy_prepare(rdpSettings* settings, const char** lpPeerHostname, UINT16* lpPeerPort,
const char** lpProxyUsername, const char** lpProxyPassword);

BOOL proxy_connect_impl(rdpSettings* settings, BIO* bio, const char* proxyUsername,
const char* proxyPassword, const char* hostname, UINT16 port);

BOOL proxy_connect(rdpSettings* settings, BIO* bio, const char* proxyUsername,
const char* proxyPassword, const char* hostname, UINT16 port);

Expand Down
1 change: 0 additions & 1 deletion libfreerdp/core/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ rdpSettings* freerdp_settings_new(DWORD flags)
settings->SupportHeartbeatPdu = TRUE;
settings->ServerMode = (flags & FREERDP_SETTINGS_SERVER_MODE) ? TRUE : FALSE;
settings->WaitForOutputBufferFlush = TRUE;
settings->MaxTimeInCheckLoop = 100;
settings->DesktopWidth = 1024;
settings->DesktopHeight = 768;
settings->Workarea = FALSE;
Expand Down
10 changes: 8 additions & 2 deletions libfreerdp/core/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,8 @@ static BOOL freerdp_tcp_set_keep_alive_mode(const rdpSettings* settings, int soc
return TRUE;
}

int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, const char* hostname, int port,
DWORD timeout)
int freerdp_tcp_connect_impl(rdpContext* context, rdpSettings* settings, const char* hostname,
int port, DWORD timeout)
{
int sockfd;
UINT32 optval;
Expand Down Expand Up @@ -1243,3 +1243,9 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, const char*

return sockfd;
}

int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, const char* hostname, int port,
DWORD timeout)
{
return context->update->io->TCPConnect(context, settings, hostname, port, timeout);
}
3 changes: 3 additions & 0 deletions libfreerdp/core/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
FREERDP_LOCAL BIO_METHOD* BIO_s_simple_socket(void);
FREERDP_LOCAL BIO_METHOD* BIO_s_buffered_socket(void);

FREERDP_LOCAL int freerdp_tcp_connect_impl(rdpContext* context, rdpSettings* settings,
const char* hostname, int port, DWORD timeout);

FREERDP_LOCAL int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings,
const char* hostname, int port, DWORD timeout);

Expand Down
1 change: 0 additions & 1 deletion libfreerdp/core/test/settings_property_lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ static const size_t uint32_list_indices[] = {
FreeRDP_KeyboardType,
FreeRDP_LargePointerFlag,
FreeRDP_LoadBalanceInfoLength,
FreeRDP_MaxTimeInCheckLoop,
FreeRDP_MonitorCount,
FreeRDP_MonitorDefArraySize,
FreeRDP_MonitorLocalShiftX,
Expand Down