Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/native/eventpipe/ds-ipc-pal-namedpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,25 @@ ds_ipc_free (DiagnosticsIpc *ipc)
ep_rt_object_free (ipc);
}

void
ds_ipc_reset (DiagnosticsIpc *ipc)
{
if (!ipc)
return;

if (ipc->pipe != INVALID_HANDLE_VALUE) {
CloseHandle (ipc->pipe);
ipc->pipe = INVALID_HANDLE_VALUE;
}

if (ipc->overlap.hEvent != INVALID_HANDLE_VALUE) {
CloseHandle (ipc->overlap.hEvent);
ipc->overlap.hEvent = INVALID_HANDLE_VALUE;
}

ipc->is_listening = false;
}

int32_t
ds_ipc_poll (
DiagnosticsIpcPollHandle *poll_handles_data,
Expand All @@ -192,6 +211,10 @@ ds_ipc_poll (
// SERVER
EP_ASSERT (poll_handles_data [i].ipc->mode == DS_IPC_CONNECTION_MODE_LISTEN);
handles [i] = poll_handles_data [i].ipc->overlap.hEvent;
if (handles [i] == INVALID_HANDLE_VALUE) {
// Invalid handle, wait will fail. Signal error
poll_handles_data [i].events = DS_IPC_POLL_EVENTS_ERR;
}
} else {
// CLIENT
bool success = true;
Expand Down
5 changes: 5 additions & 0 deletions src/native/eventpipe/ds-ipc-pal-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,11 @@ ds_ipc_free (DiagnosticsIpc *ipc)
ep_rt_object_free (ipc);
}

void
ds_ipc_reset (DiagnosticsIpc *ipc)
{
}

int32_t
ds_ipc_poll (
DiagnosticsIpcPollHandle *poll_handles_data,
Expand Down
3 changes: 3 additions & 0 deletions src/native/eventpipe/ds-ipc-pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ ds_ipc_alloc (
void
ds_ipc_free (DiagnosticsIpc *ipc);

void
ds_ipc_reset (DiagnosticsIpc *ipc);

// Poll
// Parameters:
// - IpcPollHandle * poll_handles_data: Array of IpcPollHandles to poll
Expand Down
11 changes: 10 additions & 1 deletion src/native/eventpipe/ds-ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ ds_ipc_stream_factory_get_next_available_stream (ds_ipc_error_callback_func call
DS_LOG_INFO_2 ("ds_ipc_stream_factory_get_next_available_stream - NON :: Poll attempt: %d, connection %d had no events.", poll_attempts, connection_id);
break;
default:
ds_port_reset_vcall ((DiagnosticsPort *)ipc_poll_handle.user_data, callback);
DS_LOG_INFO_2 ("ds_ipc_stream_factory_get_next_available_stream - UNK :: Poll attempt: %d, connection %d had invalid PollEvent.", poll_attempts, connection_id);
saw_error = true;
break;
Expand All @@ -441,6 +442,12 @@ ds_ipc_stream_factory_get_next_available_stream (ds_ipc_error_callback_func call
}

if (!stream && saw_error) {
// Some errors can cause the poll to return instantly, we want to delay if we see an error to avoid
// runaway CPU usage.
if (poll_timeout_ms == DS_IPC_TIMEOUT_INFINITE)
poll_timeout_ms = DS_IPC_POLL_TIMEOUT_MAX_MS;
DS_LOG_DEBUG_1 ("ds_ipc_stream_factory_get_next_available_stream - Saw error, sleeping using timeout: %dms.", poll_timeout_ms);
ep_rt_thread_sleep ((uint64_t)poll_timeout_ms * NUM_NANOSECONDS_IN_1_MS);
_ds_current_port = NULL;
ep_raise_error ();
}
Expand Down Expand Up @@ -839,7 +846,9 @@ listen_port_reset (
ds_ipc_error_callback_func callback)
{
EP_ASSERT (object != NULL);
return;
DiagnosticsListenPort *listen_port = (DiagnosticsListenPort *)object;
ds_ipc_reset (listen_port->port.ipc);
ds_ipc_listen (listen_port->port.ipc, callback);
}

static DiagnosticsPortVtable listen_port_vtable = {
Expand Down