Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you explain in more detail what's the difference between PIPE_READMODE_MESSAGE/PIPE_READMODE_BYTE?

Though I've go through the document here, it still doesn't make sense to me what it is:

Data is read from the pipe as a stream of messages. This mode can be only used if PIPE_TYPE_MESSAGE is also specified.

like image 419
user198729 Avatar asked Aug 22 '10 02:08

user198729


People also ask

How do you make a named pipe?

Within the application program, you create a named pipe by coding a mkfifo() or mknod() function. You give the FIFO a name and an access mode when you create it. If the access mode allows all users read and write access to the named pipe, any process that knows its name can use it to send or receive data.

Which API is used to create named pipe?

To create an instance of a named pipe by using CreateNamedPipe, the user must have FILE_CREATE_PIPE_INSTANCE access to the named pipe object. If a new named pipe is being created, the access control list (ACL) from the security attributes parameter defines the discretionary access control for the named pipe.


2 Answers

In BYTE mode, you are the one that needs to figure out the separation of the data so that it can be decoded at the receiving end. In MESSAGE mode, the API will do this for you. When you read the message on the other side you will have the whole block of data (the message).

In both cases, you will still need some header data to wrap your message/data to know what it is if you are mixing data types sent through the pipe.

EDIT: The documentation points to a very clear example of Client/Server using this API and the MESSAGE mode between both.

http://msdn.microsoft.com/en-us/library/aa365592%28v=VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/aa365588%28v=VS.85%29.aspx

like image 61
David Avatar answered Sep 18 '22 16:09

David


The difference between PIPE_TYPE_BYTE and PIPE_TYPE_MESSAGE type mode are explained on the http://msdn.microsoft.com/en-us/library/aa365605.aspx:

Type Mode

The type mode of a pipe determines how data is written to a named pipe. Data can be transmitted through a named pipe as either a stream of bytes or as a stream of messages. The pipe server specifies the pipe type when calling CreateNamedPipe to create an instance of a named pipe. The type modes must be the same for all instances of a pipe.

To create a byte-type pipe, specify PIPE_TYPE_BYTE or use the default value. The data is written to the pipe as a stream of bytes, and the system does not differentiate between the bytes written in different write operations.

To create a message-type pipe, specify PIPE_TYPE_MESSAGE. The system treats the bytes written in each write operation to the pipe as a message unit. The system always performs write operations on message-type pipes as if write-through mode were enabled.

If you want to write a data stream with respect of pipes you should use PIPE_TYPE_BYTE type mode. Then you can write any data in the pipe buffer with respect of WriteFile and read there on the other side with respect of ReadFile. How exactly the data will be send is not important for you. The data from some WriteFile operation can be transfered as one data block.

If you use PIPE_TYPE_MESSAGE type mode every write operation follows to the data transfer, because the writing in the pipe will be interpret as a sending of the message. There are a special function TransactNamedPipe which allow you to write a message to and read a message from the specified named pipe into a single network operation.

like image 34
Oleg Avatar answered Sep 19 '22 16:09

Oleg