Click to See Complete Forum and Search --> : A question on mailslot


cyberninja
June 10th, 2004, 07:19 PM
When reading a stream from a mailslot, the following Win32 API is used:

BOOL ReadFile(HANDLE hFile,
LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverlapped
);

However, there are some difference between calling ReadFile for a disk file and for a mailslot stream. If hFile is a handle for the a mailslot, if the param of "nNumberOfBytesToRead" is less than the total message size (you can retrieve it from GetMailslotInfo()), nothing will be read and *lpNumberOfBytesRead will be 0.

This situation raise a problem: if *lpNumberOfBytesRead is less than nNumberOfBytesToRead, what can we do except return an error? As you know, in file stream, you still get something and *lpNumberOfBytesRead will not be 0, so you can continue reading the handle in a loop until all data are read. In mailslot stream, if you do so, in the next loop you still get 0 in *lpNumberOfBytesRead.

Any suggestion for handling this situation.

cyberninja
June 11th, 2004, 01:21 PM
The key question here is:

If the value of nNumberOfBytesToRead and the size of lpBuffer is larger than or equals to the message size, is it possible for ReadFile to ouputs a value of *lpNumberOfBytesRead, which is less than nNumberOfBytesToRead? If it is possible, how should this situation be handled except raising an error?

Thanks