Windows Named Pipe issue: Error code 233 alternates

后端 未结 1 1978
太阳男子
太阳男子 2020-12-16 19:35

I need help on my application I am making. It\'s a simple program that responds to command line parameters. If the application is invoked for the first time, it starts up as

相关标签:
1条回答
  • 2020-12-16 20:25

    You should handle communication with each client instance on a different server-side instance of the pipe, using a separate thread for each. So, when ConnectNamedPipe() returns, immediately spawn a new listener thread to wait for the next client, before processing the message from the client which just connected.

    Each client will then be talking via a freshly created instance of the pipe, and you won't see the ERROR_PIPE_NOT_CONNECTED errors.

    i.e. psuedo-code something like this:

    Main Thread
    {
        CreateListenerThread();
        WaitForQuitEvent();
    }
    
    ListenerThread
    {
        ConnectNamedPipe();
        if (no error)
        {
            CreateListenerThread();
            if( PeekNamedPipe() has a message )
            {
                ReadFile();
                ProcessReceivedMessage(); // if -quit signal quit event
            }
            FileFlushBuffers();
            DisconnectNamedPipe();
            CloseHandle();
        }
        else
        {
            // handle/report error
        }
    }
    
    0 讨论(0)
提交回复
热议问题