Does CFile:Read() block on a read? 
Author Message
 Does CFile:Read() block on a read?

Just wanted to confirm: for the CFile members Read(), and Write() are these
blocking i/o routines, meaning that in a loop such as the following:

 for ( ;; )
       {
        dwRead = pFile->Read(szBuffer, 1048576) ;
        if (dwRead == 0 )
         break ;
        file1.Write( szBuffer, dwRead );
        nSize +=dwRead ;
        strDownLoad  += szBuffer ;

       }

I wanted to confirm if the loop will block on Read (until up to the number
of bytes have been read into the buffer before proceeding to the next
statement.)

Also assuming that this read is based on a HTTP Post request for a file on
an intranet server, wherein the server will return a byte stream, would it
be wise to use an algorithm such as the above. The goal is to receive the
byte stream and write to file. I'm using a large buffer since the file is
between 1M to 10M. (I didn't show the code for the HTTP request but it's
basically a POST method, with a request for a particular file.. the WinInet
protocols: OpenRequest() and SendRequest is used.)

Any feedback would be appreciated.
Manny



Thu, 18 Oct 2001 03:00:00 GMT  
 Does CFile:Read() block on a read?

Quote:

> Just wanted to confirm: for the CFile members Read(), and Write() are these
> blocking i/o routines, meaning that in a loop such as the following:

>  for ( ;; )
>        {
>         dwRead = pFile->Read(szBuffer, 1048576) ;
>         if (dwRead == 0 )
>          break ;
>         file1.Write( szBuffer, dwRead );
>         nSize +=dwRead ;
>         strDownLoad  += szBuffer ;

>        }

> I wanted to confirm if the loop will block on Read (until up to the number
> of bytes have been read into the buffer before proceeding to the next
> statement.)

> Also assuming that this read is based on a HTTP Post request for a file on
> an intranet server, wherein the server will return a byte stream, would it
> be wise to use an algorithm such as the above. The goal is to receive the
> byte stream and write to file. I'm using a large buffer since the file is
> between 1M to 10M. (I didn't show the code for the HTTP request but it's
> basically a POST method, with a request for a particular file.. the WinInet
> protocols: OpenRequest() and SendRequest is used.)

> Any feedback would be appreciated.
> Manny

CFile uses blocking reads/writes.  If you would like non-blocking, so you can write while reading more, use the Win32 CreateFile/ReadFile/WriteFile with the overlapped option.


Thu, 18 Oct 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Reading ASCII float values with CFile.Read?

2. Reading a file with CFile::Read

3. CFile::Seek and CFile::Read over the network

4. Are CFile::Read() and CFile::Write() Really Unbuffered?

5. CFile can't read file's update lie in novell

6. Millenium Read File problems (CFile)!

7. Reading from text files using CFile object

8. CFile Help please: reading data from file

9. CFile problem --- reading junk characters at the end of an file

10. CFile - question about reading file

11. CFile::Read and CString

12. CFile vs CStdioFile problem writh reading / writing text

 

 
Powered by phpBB® Forum Software