If the method succeeds, the return value is the number of bytes
read. A return value of zero indicates that the client has closed
the connection and there is no more data available to be read. If
the method fails, the return value is INET_ERROR. To get extended
error information, call the GetLastError method.
The Read method will read up to the specified number of
bytes and store the data in the buffer provided by the caller. If
there is no data available to be read at the time this method is
invoked, the session thread will block until at least one byte of data
becomes available, the timeout period elapses or an error occurs. This
method will return if any amount of data is sent by the client, and
will not block until the entire buffer has been filled.
The application should never make an assumption about the amount of
data that will be available to read. TCP considers all data to be an
arbitrary stream of bytes and does not impose any structure on the
data itself. For example, if the client is sending data to the server
in fixed 512 byte blocks of data, it is possible that a single call to
the Read method will return only a partial block of data, or it
may return multiple blocks combined together. It is the responsibility
of the application to buffer and process this data appropriately.
For applications that are built using the Unicode character set, it
is important to note that the buffer is an array of bytes, not
characters. If the client is sending string data to the server, it
must be read as a stream of bytes and converted using the
MultiByteToWideChar function. If the client is sending lines of
text terminated with a linefeed or carriage return and linefeed pair,
the ReadLine method will return a line of text at a time and
perform this conversion for you.
To determine if there is data available to be read without causing
the session thread to block, call the IsReadable method.