C# Класс Rsdn.Janus.Framework.Ipc.NamedPipeWrapper

A utility class that exposes named pipes operations.
This class uses the exposed exposed kernel32.dll methods by the NamedPipeNative class to provided controlled named pipe functionality.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Connect ( PipeHandle handle ) : void

Starts waiting for client connections.

Blocks the current execution until a client pipe attempts to establish a connection.

ConnectToPipe ( string pipeName ) : PipeHandle

Connects to a server named pipe on the same machine.

This method is used by clients to establish a pipe connection with a server pipe.

ConnectToPipe ( string pipeName, string serverName ) : PipeHandle

Connects to a server named pipe.

This method is used by clients to establish a pipe connection with a server pipe.

Create ( string name, uint outBuffer, uint inBuffer ) : PipeHandle

Creates a server named pipe.

Disconnect ( PipeHandle handle ) : void

Disconnects a server named pipe from the client.

Server pipes can be reused by first disconnecting them from the client and then calling the Connect method to start listening. This improves the performance as it is not necessary to create new pipe handles.

Flush ( PipeHandle handle ) : void

Flushes all the data in a named pipe.

NumberPipeInstances ( PipeHandle handle ) : uint

Returns the number of instances of a named pipe.

Read ( PipeHandle handle, int maxBytes ) : string

Reads a string from a named pipe using the UTF16 encoding.

This function uses AppModule.Ipc.ReadBytes to read the bytes from the pipe and then converts them to string.

The first four bytes of the pipe data are expected to contain the data length of the message. This method first reads those four bytes and converts them to integer. It then continues to read from the pipe using the extracted data length.

ReadBytes ( PipeHandle handle, int maxBytes ) : byte[]

Reads the bytes from a named pipe.

This method expects that the first four bytes in the pipe define the length of the data to read. If the data length is greater than maxBytes the method returns null.

The first four bytes of the pipe data are expected to contain the data length of the message. This method first reads those four bytes and converts them to integer. It then continues to read from the pipe using the extracted data length.

TryConnectToPipe ( string pipeName, PipeHandle &handle ) : bool

Tries to connect to a named pipe on the same machine.

This method is used mainly when stopping the pipe server. It unblocks the existing pipes, which wait for client connection.

TryConnectToPipe ( string pipeName, string serverName, PipeHandle &handle ) : bool

Tries to connect to a named pipe.

This method is used mainly when stopping the pipe server. It unblocks the existing pipes, which wait for client connection.

Write ( PipeHandle handle, string text ) : void

Writes a string to a named pipe.

This method converts the text into an array of bytes, using the UTF16 encoding and the uses AppModule.Ipc.WriteBytes to write to the pipe.

When writing to a pipe the method first writes four bytes that define the data length. It then writes the whole message.

WriteBytes ( PipeHandle handle, byte bytes ) : void

Writes an array of bytes to a named pipe.

If we try bytes array we attempt to write is empty then this method write a space character to the pipe. This is necessary because the other end of the pipe uses a blocking Read operation so we must write someting.

The bytes length is restricted by the maxBytes parameter, which is done primarily for security reasons.

When writing to a pipe the method first writes four bytes that define the data length. It then writes the whole message.

Описание методов

Connect() публичный статический Метод

Starts waiting for client connections.
Blocks the current execution until a client pipe attempts to establish a connection.
public static Connect ( PipeHandle handle ) : void
handle PipeHandle The pipe handle.
Результат void

ConnectToPipe() публичный статический Метод

Connects to a server named pipe on the same machine.
This method is used by clients to establish a pipe connection with a server pipe.
public static ConnectToPipe ( string pipeName ) : PipeHandle
pipeName string The pipe name.
Результат PipeHandle

ConnectToPipe() публичный статический Метод

Connects to a server named pipe.
This method is used by clients to establish a pipe connection with a server pipe.
public static ConnectToPipe ( string pipeName, string serverName ) : PipeHandle
pipeName string The pipe name.
serverName string The server name.
Результат PipeHandle

Create() публичный статический Метод

Creates a server named pipe.
public static Create ( string name, uint outBuffer, uint inBuffer ) : PipeHandle
name string The name of the pipe.
outBuffer uint The size of the outbound buffer.
inBuffer uint The size of the inbound buffer.
Результат PipeHandle

Disconnect() публичный статический Метод

Disconnects a server named pipe from the client.
Server pipes can be reused by first disconnecting them from the client and then calling the Connect method to start listening. This improves the performance as it is not necessary to create new pipe handles.
public static Disconnect ( PipeHandle handle ) : void
handle PipeHandle The pipe handle.
Результат void

Flush() публичный статический Метод

Flushes all the data in a named pipe.
public static Flush ( PipeHandle handle ) : void
handle PipeHandle The pipe handle.
Результат void

NumberPipeInstances() публичный статический Метод

Returns the number of instances of a named pipe.
public static NumberPipeInstances ( PipeHandle handle ) : uint
handle PipeHandle The pipe handle.
Результат uint

Read() публичный статический Метод

Reads a string from a named pipe using the UTF16 encoding.
This function uses AppModule.Ipc.ReadBytes to read the bytes from the pipe and then converts them to string.

The first four bytes of the pipe data are expected to contain the data length of the message. This method first reads those four bytes and converts them to integer. It then continues to read from the pipe using the extracted data length.
public static Read ( PipeHandle handle, int maxBytes ) : string
handle PipeHandle The pipe handle.
maxBytes int The maximum bytes to read.
Результат string

ReadBytes() публичный статический Метод

Reads the bytes from a named pipe.
This method expects that the first four bytes in the pipe define the length of the data to read. If the data length is greater than maxBytes the method returns null.

The first four bytes of the pipe data are expected to contain the data length of the message. This method first reads those four bytes and converts them to integer. It then continues to read from the pipe using the extracted data length.
public static ReadBytes ( PipeHandle handle, int maxBytes ) : byte[]
handle PipeHandle The pipe handle.
maxBytes int The maximum bytes to read.
Результат byte[]

TryConnectToPipe() публичный статический Метод

Tries to connect to a named pipe on the same machine.
This method is used mainly when stopping the pipe server. It unblocks the existing pipes, which wait for client connection.
public static TryConnectToPipe ( string pipeName, PipeHandle &handle ) : bool
pipeName string The name of the pipe.
handle PipeHandle The resulting pipe handle.
Результат bool

TryConnectToPipe() публичный статический Метод

Tries to connect to a named pipe.
This method is used mainly when stopping the pipe server. It unblocks the existing pipes, which wait for client connection.
public static TryConnectToPipe ( string pipeName, string serverName, PipeHandle &handle ) : bool
pipeName string The name of the pipe.
serverName string The name of the server.
handle PipeHandle The resulting pipe handle.
Результат bool

Write() публичный статический Метод

Writes a string to a named pipe.
This method converts the text into an array of bytes, using the UTF16 encoding and the uses AppModule.Ipc.WriteBytes to write to the pipe.

When writing to a pipe the method first writes four bytes that define the data length. It then writes the whole message.
public static Write ( PipeHandle handle, string text ) : void
handle PipeHandle The pipe handle.
text string The text to write to the pipe.
Результат void

WriteBytes() публичный статический Метод

Writes an array of bytes to a named pipe.
If we try bytes array we attempt to write is empty then this method write a space character to the pipe. This is necessary because the other end of the pipe uses a blocking Read operation so we must write someting.

The bytes length is restricted by the maxBytes parameter, which is done primarily for security reasons.

When writing to a pipe the method first writes four bytes that define the data length. It then writes the whole message.
public static WriteBytes ( PipeHandle handle, byte bytes ) : void
handle PipeHandle The pipe handle.
bytes byte The bytes to write.
Результат void