在Unix系统中,与文件关联的两个数据结构通常是两个:FILE和stat。前者通常称之为文件句柄,而后者则通常称之为文件的状态信息,用于描述文件的内部信息。APR中,与之对应提供了两个封装数据结构apr_file_t和apr_finfo_t,前者描述文件句柄信息,后者描述文件内部信息。
根据操作系统支持的不同,apr_file_t了可以分为四个版本,不过我们仅仅介绍Unix版本,至于Window版本,我们会提及,而其余的netware和OS/2版本我们不打算做任何分析。在Unix系统中,apr_file_t定义如下:
struct apr_file_t {
apr_pool_t *pool;
int filedes;
char *fname;
apr_int32_t flags;
int eof_hit;
int is_pipe;
apr_interval_time_t timeout;
int buffered;
enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking;
int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/
#ifndef WAITIO_USES_POLL
/* if there is a timeout set, then this pollset is used */
apr_pollset_t *pollset;
#endif
/* Stuff for buffered mode */
char *buffer;
int bufpos; /* Read/Write position in buffer */
unsigned long dataRead; /* amount of valid data read into buffer */
int direction; /* buffer being used for 0 = read, 1 = write */
unsigned long filePtr; /* position in file of handle */
#if APR_HAS_THREADS
struct apr_thread_mutex_t *thlock;
#endif
};
该结构描述了一个文件的大部分的属性,也是整个文件I/O系统的核心数据结构之一。