Skip to content

Commit

Permalink
Fix named pipes (#236)
Browse files Browse the repository at this point in the history
On connected callback was called too early(overlapped wasn't awaited)
Also added a DsiconnectNamedPipe during destruction
  • Loading branch information
furrycoding committed Oct 9, 2023
1 parent 6b131d6 commit 6521106
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/lib/named_pipe/named_pipe_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ class NamedPipeListener : public INamedPipeListener {

if (!Connect(&listener_data)) return;

if (thread_active_) on_event_callback_({NamedPipeListenerEventType::ClientConnected});

while (thread_active_) {
switch (WaitForSingleObject(listener_data.overlap.hEvent, 5)) {
case WAIT_OBJECT_0:
Expand Down Expand Up @@ -177,6 +175,13 @@ class NamedPipeListener : public INamedPipeListener {
LogError("GetOverlappedResult failed");
break;
}

if (listener_data.state == NamedPipeListenerState::Connecting) {
if (thread_active_) {
on_event_callback_({NamedPipeListenerEventType::ClientConnected});
}
}

listener_data.state = NamedPipeListenerState::Reading;
}
}
Expand Down Expand Up @@ -205,6 +210,7 @@ class NamedPipeListener : public INamedPipeListener {
}
}

DisconnectNamedPipe(hPipeInst); // Not 100% sure this is needed, but winapi seems to like this better
CloseHandle(hPipeInst);
CloseHandle(hEvent);
}
Expand All @@ -216,4 +222,4 @@ class NamedPipeListener : public INamedPipeListener {

std::function<void(NamedPipeListenerEvent)> on_event_callback_;
std::function<void(T*)> on_data_callback_;
};
};

0 comments on commit 6521106

Please sign in to comment.