|
Named Pipe Operations
The first time the server calls CreateNamedPipe, the function specifies the maximum number of instances of the pipe that can
exist simultaneously. Limited by this maximum, the server can call CreateNamedPipe repeatedly to create additional instances of the pipe. If the function
succeeds, each call returns a handle to the server end of a named pipe instance.
As soon as a pipe instance is created, a client process can connect to it by
calling the CreateFile or CallNamedPipe function. If a pipe instance is available, CreateFile returns a handle to the client end of the pipe instance. If no instances of
the pipe are available, a client process can use the WaitNamedPipe function to wait for one to become available.
A client process can also use CallNamedPipe to combine into a single operation the functions that connect to a pipe
instance (waiting for one to be available, if necessary), write a message, read a
message, and close its pipe handle. CallNamedPipe can be used only by a client process and only with a message-type pipe.
A server process specifies a handle to a pipe instance in a call to the ConnectNamedPipe function to determine when a client process is connected to it. If the pipe
handle is in blocking mode, the ConnectNamedPipe operation does not return until a client is connected.
Client and server processes can call one of several functions in addition to CallNamedPipe to read from and write to a named pipe. The behavior of these functions
depends on the type of pipe and the modes in effect for the specified pipe handle,
as follows:
- The ReadFile and WriteFile functions can be used with either byte-type or message-type pipes.
- The ReadFileEx and WriteFileEx functions can be used with either byte-type or message-type pipes if the pipe
handle was opened for overlapped operations.
- The PeekNamedPipe function can be used to read without removing the contents of either a
byte-type pipe or a message-type pipe. PeekNamedPipe can also return additional information about the pipe instance.
- The TransactNamedPipe function can be used with message-type pipes if the pipe handle of the
calling process is set to message-read mode. The function writes a request message
and reads a reply message in a single operation, enhancing network performance.
For a pipe handle in byte-read mode, a read operation is completed
successfully when all available bytes in the pipe are read or when the specified number of
bytes is read.
For a pipe handle in message-read mode, a ReadFile or ReadFileEx operation is completed successfully only when the entire message is read. If
the specified number of bytes to read is less than the size of the next
message, the function reads as much of the message as possible before returning FALSE
(with the GetLastError function returning ERROR_MORE_DATA). However, the remainder of the message
can be read by making additional calls to ReadFile, ReadFileEx, or PeekNamedPipe. Note that PeekNamedPipe returns TRUE after reading a complete or partial message, and it reports the
number of bytes remaining in a partially read message.
For a message-type pipe with multiple unread messages, a read operation using
a message-read pipe handle returns after reading one message. An operation
using a byte-read handle does not distinguish between the messages it reads all available bytes up to the specified number.
When a client and server finish using a pipe instance, the server calls the DisconnectNamedPipe function to close the connection to the client process. This function makes
the client's handle invalid (if it has not already been closed). Any unread data
in the pipe is discarded. To ensure that all bytes or messages written to the
pipe are read by the client, the server first calls the FlushFileBuffers function, which does not return until the client has read all data from the
pipe. After the client is disconnected, the server calls the CloseHandle function to close its handle to the pipe instance. Alternatively, the server
can use ConnectNamedPipe to enable a new client to connect to this instance of the pipe.
A process can retrieve information about a named pipe by calling the GetNamedPipeInfo function, which returns the type of the pipe, the size of the input and
output buffers, and the maximum number of pipe instances that can be created. The GetNamedPipeHandleState function reports on the read and wait modes of a pipe handle, the current
number of pipe instances, and additional relevant information for pipes that
communicate over a network. The SetNamedPipeHandleState function sets the read mode and wait modes of a pipe handle. For client
processes communicating with a remote server, the function also controls the maximum
number of bytes to collect or the maximum time to wait before transmitting a
message (assuming the client's handle was not opened with write-through mode
enabled).
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|