Chinaunix首页 | 论坛 | 博客
  • 博客访问: 378705
  • 博文数量: 715
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:46
文章分类

全部博文(715)

文章存档

2011年(1)

2008年(714)

我的朋友

分类:

2008-10-13 16:36:15

yunyi:可以用文件长度和读到地字节作比较阿
(发表于2002-9-15 20:46:00)

busy:CFile实际上是使用windows file api(如createfile,readfile等)
先看看windows file api是怎么处理的吧。
1。同步读取文件
// Attempt a synchronous read operation. 
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL) ; 
// Check for end of file. 
if (bResult &&  nBytesRead == 0, ) 

    // we're at the end of the file 
}
(发表于2002-11-13 15:18:00)

busy:
2。异步读取文件
// set up overlapped structure fields 
gOverLapped.Offset     = 0; 
gOverLapped.OffsetHigh = 0; 
gOverLapped.hEvent     = hEvent; 
 
// attempt an asynchronous read operation 
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, 
    &gOverlapped) ; 
 
// if there was a problem, or the async. operation's still pending ... 
if (!bResult) 

    // deal with the error code 
    switch (dwError = GetLastError()) 
    { 
        case ERROR_HANDLE_EOF: 
        { 
            // we're reached the end of the file 
            // during the call to ReadFile 
 
            // code to handle that 
        } 
 

(发表于2002-11-13 15:19:00)

busy:case ERROR_IO_PENDING: 
        { 
            // asynchronous i/o is still in progress 
 
            // do something else for a while 
            GoDoSomethingElse() ; 
 
            // check on the results of the asynchronous read 
            bResult = GetOverlappedResult(hFile, &gOverlapped, 
                &nBytesRead, FALSE) ; 
 
            // if there was a problem ... 
            if (!bResult) 
            { 
                // deal with the error code 
                switch (dwError = GetLastError()) 
                { 

(发表于2002-11-13 15:22:00)

busy:
                    case ERROR_HANDLE_EOF: 
                    { 
                        // we're reached the end of the file 
                        //during asynchronous operation 
                    } 
 
                    // deal with other error cases 
                } 
            } 
        } // end case 
 
        // deal with other error cases 
 
    } // end switch 
} // end if
(发表于2002-11-13 15:22:00)

busy:一般是同步读取的了。所以只要判断readfile返回的值是 true与读出来的字节为0就好了。
(发表于2002-11-13 15:25:00)

..........................................................................
--------------------next---------------------

阅读(143) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~