5#include <winpr/synch.h>
7#include <freerdp/freerdp.h>
8#include <freerdp/client.h>
9#include <freerdp/input.h>
10#include <freerdp/transport_io.h>
12#include "../connection.h"
15#include "../transport.h"
20static HANDLE s_layerEvent =
nullptr;
23static int layer_read(WINPR_ATTR_UNUSED
void* userContext, WINPR_ATTR_UNUSED
void* data,
24 WINPR_ATTR_UNUSED
int bytes)
31static int layer_write(WINPR_ATTR_UNUSED
void* userContext, WINPR_ATTR_UNUSED
const void* data,
32 WINPR_ATTR_UNUSED
int bytes)
39static BOOL layer_wait(WINPR_ATTR_UNUSED
void* userContext, WINPR_ATTR_UNUSED BOOL waitWrite,
40 WINPR_ATTR_UNUSED DWORD timeout)
46static HANDLE layer_get_event(WINPR_ATTR_UNUSED
void* userContext)
51int TestInputWriteFail(
int argc,
char* argv[])
58 RDP_CLIENT_ENTRY_POINTS clientEntryPoints = WINPR_C_ARRAY_INIT;
59 clientEntryPoints.Size =
sizeof(RDP_CLIENT_ENTRY_POINTS);
60 clientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION;
61 clientEntryPoints.ContextSize =
sizeof(rdpClientContext);
63 rdpContext* context = freerdp_client_context_new(&clientEntryPoints);
67 s_layerEvent = CreateEvent(
nullptr, TRUE, FALSE,
nullptr);
72 rdpTransport* transport = freerdp_get_transport(context);
75 layer = transport_layer_new(transport, 0);
78 layer->Read = layer_read;
79 layer->Write = layer_write;
80 layer->Wait = layer_wait;
81 layer->GetEvent = layer_get_event;
82 if (!transport_attach_layer(transport, layer))
87 if (!input_register_client_callbacks(context->input) ||
88 !rdp_client_transition_to_state(context->rdp, CONNECTION_STATE_ACTIVE))
92 const BOOL first = freerdp_input_send_mouse_event(context->input, PTR_FLAGS_MOVE, 10, 10);
93 const UINT32 error = freerdp_get_last_error(context);
94 const BOOL active = freerdp_is_active_state(context);
96 const BOOL second = freerdp_input_send_mouse_event(context->input, PTR_FLAGS_MOVE, 20, 20);
99 "input while the connection drops: first %s, then active %s, second %s, last "
100 "error 0x%08" PRIx32
"\n",
101 first ?
"TRUE" :
"FALSE", active ?
"TRUE" :
"FALSE", second ?
"TRUE" :
"FALSE",
104 if (error != FREERDP_ERROR_CONNECT_TRANSPORT_FAILED)
106 (void)fprintf(stderr,
"the dropped connection is not reported\n");
111 (void)fprintf(stderr,
"the input whose write failed reports success\n");
114 if (active || !second)
116 (void)fprintf(stderr,
"the session is still active after its transport closed\n");
122 transport_layer_free(layer);
123 freerdp_client_context_free(context);
125 (void)CloseHandle(s_layerEvent);
126 s_layerEvent =
nullptr;