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.
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.