简体   繁体   中英

Trigger to read from windows pipe

This is a very basic question. Trying to write IPC mechanism using pipes. I have used a simple client and server example from msdn that tosses char messages to and fro. Now my requirement is that server keeps listening for the commands from the clients. On receiving a instruction from the client, server performs some action and gets back to client.

The example demonstrates how to read the stuff. But I need to trigger or a signal when something comes into my pipe, so that I can perform read operation that time and get out. Dedicating a single thread to keep reading looks inefficient. If i have 10 clients, 10 threads per client and 10 threads for reading is not good.

so, Is there a mechanism where I can get notification from the pipe that I got to read something?

You can use IOCP on pipes. ReadFile, WriteFile, TransactNamedPipe, and ConnectNamedPipe API's can be used with pipe handles.

ReadFileEx and WriteFileEx can also be used with completion routines, (don't go near the hEvent synchro design), for pipe I/O.

See MSDN for fuller details.

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