Both the server and the client processes write to a pipe by calling DosWrite. The server writes to the handle that was returned to it by DosCreateNPipe, and the client writes to the handle that was returned to it by DosOpen.
Either bytes or messages can be written, depending on whether the pipe was created as a byte pipe or as a message pipe.
Named pipes created with the NP_ACCESS_OUTBOUND access mode cannot use the DosWrite function. If the named pipe's client uses the DosWrite function, the function returns error code 5 (ERROR_ACCESS_DENIED).
An attempt to write to a pipe whose other end has been closed returns ERROR_BROKEN_PIPE or, if the other end was closed without without reading all pending data, ERROR_DISCARDED.
When a process writes to a message pipe, the buffer-length parameter for DosWrite holds the size of the message that the process is writing. Because DosWrite automatically encodes message lengths in the pipe, applications do not have to encode this information in the data buffers.
The action taken by DosWrite depends on the blocking mode of the pipe, which is not necessarily the same for the server and client ends of the pipe. For the server process, the blocking mode of the pipe is specified when the pipe is created. For a client process, the blocking mode is automatically set to blocking when the pipe is opened. The blocking mode can also be reset by calling DosSetNPHState.
If the end of the message pipe that is being written to is in blocking mode, DosWrite does not return until all of the requested bytes have been written. (It might have to wait for the first part of the message to be read before it can write the rest of the message.)
If the message pipe is in nonblocking mode, DosWrite takes the following action:
If a byte pipe is in nonblocking mode, and if there is more data to be written than will fit in the pipe buffer, then DosWrite writes as many bytes as will fit in the buffer and returns the number of bytes that were actually written.
If a process tries to write to a pipe whose other end is closed, ERROR_BROKEN_PIPE is returned.