K
kjell
Hi,
I'm trying to write a program that reads data from a network stream.
I would like the program to read all available data in the buffer and
then process the data. I do not want the program to hang unless there
is no data in the buffer. For example if there are ten bytes available
in the buffer I would like the program to read those ten bytes and then
processed the data. If there are twenty bytes available in the buffer
I would like the program to read those twenty bytes and then process
them. My implementation looks something like this:
// Allocate the buffer
const unsigned long nBlockSize = 1000;
unsigned char pData[nBlockSize];
// Get data
while (true)
{
size_t sizeBytesRead;
sizeBytesRead = fread(pData, 1, nBlockSize, m_pFileInStream);
// Process the data
.
.
.
}
The problem with this code is that it will hang until a full 1000 bytes
has been read before processing the data. Is there a way I can modify
these code so that will process the data as soon as it becomes
available?
Thanks for your help,
Kjell
I'm trying to write a program that reads data from a network stream.
I would like the program to read all available data in the buffer and
then process the data. I do not want the program to hang unless there
is no data in the buffer. For example if there are ten bytes available
in the buffer I would like the program to read those ten bytes and then
processed the data. If there are twenty bytes available in the buffer
I would like the program to read those twenty bytes and then process
them. My implementation looks something like this:
// Allocate the buffer
const unsigned long nBlockSize = 1000;
unsigned char pData[nBlockSize];
// Get data
while (true)
{
size_t sizeBytesRead;
sizeBytesRead = fread(pData, 1, nBlockSize, m_pFileInStream);
// Process the data
.
.
.
}
The problem with this code is that it will hang until a full 1000 bytes
has been read before processing the data. Is there a way I can modify
these code so that will process the data as soon as it becomes
available?
Thanks for your help,
Kjell