Reputation: 35460
I have created a named pipe with following flags:
From the server side I am calling ConnectNamedPipe and waiting for the clients to connect.
From the client side I am calling CallNamedPipe to connect to server and write data of length N.
On the server side:
Problem:
I thought of introducing custom header to indicate the buffer length in the message itself but this sounds lot of changes.
Is there any better and reliable way to get the length of the data to be read from pipe ?
Upvotes: 3
Views: 3124
Reputation: 941635
There are a large number of race conditions you can get with named pipes. You have to deal with them in your code. Possibilities:
Upvotes: 8
Reputation: 179907
It sounds like you want Aynschronous I/O. Just let Windows notify you when data is available, and peek at that moment.
Upvotes: 1
Reputation: 6697
Having a packet size in the header is a good idea in any case, making the protocol less dependent on transport layer. Alternatively, if the client sends data and closes the pipe you can accumulate into buffer with ReadFile until EOF.
Upvotes: 0