apache中的文件与目录(2)[10]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

            blocksize = thefile->dataRead;//size > thefile->dataRead - 0 ? thefile->dataRead - 0 : size;
            memcpy(pos, thefile->buffer + 0, blocksize);
            thefile->bufpos += blocksize;
            pos += thefile->dataRead;
            size -= thefile->dataRead;
此时各个指针的位置如下图所示意

从上图可以看到,第一次读取之后,各个指针都指向相应的缓冲区的末尾,pos指向用户缓冲区,随后的数据直接从pos位置往后拷贝;bufpos指向文件缓冲区的末尾。由于此时尚有size-dataRead大小的数据尚未读取,因此,函数将从thefile->filedes中去读取:
            if (thefile->bufpos >= thefile->dataRead) {
                int bytesread = read(thefile->filedes, thefile->buffer, APR_FILE_BUFSIZE);
                if (bytesread == 0) {
                    thefile->eof_hit = TRUE;
                    rv = APR_EOF;
                    break;
                }
                else if (bytesread == -1) {
                    rv = errno;
                    break;
                }
                thefile->dataRead = bytesread;
                thefile->filePtr += thefile->dataRead;
                thefile->bufpos = 0;
            }
但实际上,当Apache再次到磁盘文件中去读取的时候,它并不会吝啬的仅读取size-dataRead大小,相反它会调用read函数一次性的从文件中读取APR_FILE_BUFSIZE(4K)大小的数据到文件缓冲区中,然后设置dataRead为新的实际的读取字节长度。
        *nbytes = pos - (char *)buf;
        if (*nbytes) {
            rv = 0;
        }

本文关键:apache中的文件与目录(2)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top