Named Pipes and OVERLAPPED for Windows

I am going to implement my first windows service. The service connects to a Bluetooth dongle and associates some commands and data with one client. Each process (client, server) must have at least two threads: one blocks Read (), the other curves business logic, and writes () from time to time.

While checking out the alternatives, I decided to go with Named Pipes for IPC, but I had trouble understanding some of the options. In particular:

  • I want to allow simultaneous reading and writing. Do I need to create a channel with FILE_FLAG_OVERLAPPED, although I'm not going to do reads and writes in the same thread?
  • If the answer is "yes", I still need to pass a structure OVERLAPPEDto ReadFile(), WriteFile()use GetOverlappedResult(), etc.? If so, what is the rationality of this?
  • What is so good that reading and writing are not blocked in one thread? What are the use cases?

EDIT

I want to clarify the question:

  • Assuming both threads (read / write) will access the pipe at the same time, will there be one block until the other is executed due to some internal pipe mutex?
  • Will the setting FILE_FLAG_OVERLAPPEDchange this behavior?
+4
source share
2 answers

FILE_FLAG_OVERLAPPED, , , . . , -, , -, .

FILE_FLAG_OVERLAPPED, OVERLAPPED ReadFile WriteFile lpOverlapped. , (, ), NULL.

- , concurrency. , . ( , : , , , , , - .)

+2

, PIPE_ACCESS_DUPLEX dwOpenMode. (FILE_FLAG_OVERLAPPED) .

-, , . (. WaitForMultipleObjects). . , , . , , , , , .

CreateNamedPipe:

[overlapped], , , , , . , , . , (-) . , , , , . ReadFileEx WriteFileEx . ReadFile, WriteFile, ConnectNamedPipe TransactNamedPipe , .

+2

All Articles