-1

I associate an HANDLE "h_server" that I create with CreateNamedPipe() with an I/O Completion Port, and for the completion key I use a function pointer: namedpipe_server_completion_routine().

Now, when a named pipe client connection request triggers, that HANDLE "h_server" became the client endpoint in the named pipe server application, so I should change its I/O Completion Key to another kind of routine pointer, the one that completes I/O, Read, Write etc, io_arrival_completion_routine(), which is different from the named pipe server completion routine.

I thought to call again CreateIoCompletionPort() with the new completion key on that HANDLE, but it seems not working, so there is a way to change that key? Maybe with some hacks with DuplicateHandle or something?

If not, how I could solve this?

NOTE: this problem is only present with named pipe servers, because AcceptEx() works in a different way: with tcp servers, when a connection arrives, you basically got a new HANDLE for the client endpoint on the server, so you can associate that new HANDLE with the io completion port and the correct completion key as the correct io_arrival_completion_routine(), while the HANDLE of the tcp server associated with the tcp_server_completion_routine() will remain correct, and its unique role will be to listen for new connections.

Marco Pagliaricci
  • 1,366
  • 17
  • 31
  • 1
    CreateIoCompletionPort() explicitly supports this scenario with its 2nd argument. Nobody can see you using it, a code snippet is required. – Hans Passant Oct 05 '13 at 11:52
  • This is exactly what I use to associate an HANDLE to a completion port with a completion key. Now my question is to *change* that completion key of the HANDLE... – Marco Pagliaricci Oct 05 '13 at 13:59

1 Answers1

1

Change the completion key from being a pointer to a function to being a pointer to a data block. This data block can then include whatever status information you need.

In the simplest case the data block would just contain the function pointer you're currently trying to use as the completion key.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
  • Thanks. Yeah, this is the solution I'm adopting right now. I have also thought to ignore the completion key at all, and using the structure which I derive from OVERLAPPED to set the callback pointer, so I could change it at every request. – Marco Pagliaricci Oct 08 '13 at 17:36