简体   繁体   中英

Named Pipe server can't get the pipe handle state

I'm currently working on an application that acts as the server for a named pipe. This application is solely designed to send data out to a client (not written by me), but also needs to be informed of when the pipe is broken. My idea for this task was to use GetNamedPipeHandleState() to retrieve the number of instances of the pipe and see if the pipe was still resident in the system. If it was no longer connected, the program is designed to reset the pipe so that the client can reconnect and resume pulling data from the application. Unfortunately, I can't retrieve the number of instances of the pipe. Whenever the call is made, the function fails with GetLastError() returning ERROR_ACCESS_DENIED . However, this only occurs if I attempt the call as follows:

GetNamedPipeHandleStateA(pipe,0,&npipeinstances,0,0,0,0);

If I call the function like this:

GetNamedPipeHandleStateA(pipe,0,0,0,0,0,0);

no errors occur, but I don't receive any state information. Is there a creation parameter that could be missing, or a better way to check for this information?

The creation code for the pipe is as follows:

pipe=CreateNamedPipeA(pipename,             // name of the pipe
                      PIPE_ACCESS_OUTBOUND, // read/write access 
                      PIPE_TYPE_MESSAGE |   // message type pipe 
                      PIPE_WAIT,            // blocking mode 
                      1,                    // max. instances  
                      65535,                // output buffer size 
                      65535,                // input buffer size 
                      300,                  // client time-out 
                      NULL);                // default security attribute 

From the API docs :

hNamedPipe [in] A handle to the named pipe for which information is wanted. The handle must have GENERIC_READ access for a read-only or read/write pipe, or it must have GENERIC_WRITE and FILE_READ_ATTRIBUTES access for a write-only pipe.

If you have opened your pipe handle ( pipe ) with only PIPE_ACCESS_OUTBOUND , I don't think you satisfy this condition. Hence the ERROR_ACCESS_DENIED error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM