2014-11-19 00:25:21 +08:00
|
|
|
|
#ifndef ACL_FHANDLE_INCLUDE_H
|
|
|
|
|
#define ACL_FHANDLE_INCLUDE_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "acl_define.h"
|
|
|
|
|
#include "acl_vstream.h"
|
|
|
|
|
#include "acl_vstring.h"
|
|
|
|
|
#include "acl_ring.h"
|
|
|
|
|
#include "thread/acl_thread.h"
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ͨ<EFBFBD>õĴ洢<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct ACL_FHANDLE ACL_FHANDLE;
|
|
|
|
|
|
|
|
|
|
struct ACL_FHANDLE {
|
|
|
|
|
ACL_VSTREAM *fp; /**< <20>洢<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
acl_int64 fsize; /**< <20>洢<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С */
|
|
|
|
|
int nrefer; /**< <20>ô洢<C3B4><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õļ<C3B5><C4BC><EFBFBD>ֵ */
|
|
|
|
|
acl_pthread_mutex_t mutex; /**< <20>߳<EFBFBD><DFB3><EFBFBD> */
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
unsigned long tid; /**< <20>ô洢<C3B4><E6B4A2><EFBFBD>̺߳<DFB3> */
|
|
|
|
|
unsigned long lock_mutex_tid; /**< <20><><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺߳<DFB3> */
|
|
|
|
|
#else
|
|
|
|
|
acl_pthread_t tid; /**< <20>ô洢<C3B4><E6B4A2><EFBFBD>̺߳<DFB3> */
|
|
|
|
|
acl_pthread_t lock_mutex_tid; /**< <20><><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺߳<DFB3> */
|
|
|
|
|
#endif
|
|
|
|
|
unsigned int oflags; /**< <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>ı<EFBFBD>־λ */
|
|
|
|
|
#define ACL_FHANDLE_O_FLOCK (1 << 0) /**< ʹ<><CAB9><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD> */
|
|
|
|
|
#define ACL_FHANDLE_O_MLOCK (1 << 1) /**< ʹ<><CAB9><EFBFBD>߳<EFBFBD><DFB3><EFBFBD> */
|
|
|
|
|
#define ACL_FHANDLE_O_MKDIR (1 << 2) /**< <20>Ƿ<EFBFBD><C7B7>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>鲢<EFBFBD><E9B2A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>Ŀ¼ */
|
|
|
|
|
#define ACL_FHANDLE_O_NOATIME (1 << 3) /**< <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> O_NOATIME <20><>־λ */
|
|
|
|
|
#define ACL_FHANDLE_O_DIRECT (1 << 4) /**< <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> O_DIRECT <20><>־λ */
|
|
|
|
|
#define ACL_FHANDLE_O_SYNC (1 << 5) /**< <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> O_SYNC <20><>־λ */
|
|
|
|
|
#define ACL_FHANDLE_O_EXCL (1 << 6) /**< <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
|
|
|
|
|
unsigned int status; /**< <20>ô洢<C3B4>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ */
|
|
|
|
|
#define ACL_FHANDLE_S_FLOCK_ON (1 << 0) /**< <20>ô洢<C3B4><E6B4A2><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD> */
|
|
|
|
|
#define ACL_FHANDLE_S_MUTEX_ON (1 << 1) /**< <20>ô洢<C3B4><E6B4A2><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD> */
|
|
|
|
|
|
|
|
|
|
time_t when_free; /**< <20><><EFBFBD>ӳٹرջ<D8B1><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> */
|
|
|
|
|
ACL_RING ring; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD> */
|
|
|
|
|
size_t size; /**< <20><> ACL_FHANDLE <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʴ<EFBFBD>С >= sizeof(ACL_FHANDLE) */
|
|
|
|
|
void (*on_close)(ACL_FHANDLE*); /**< <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA> */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define ACL_FHANDLE_PATH(x) (ACL_VSTREAM_PATH((x)->fp))
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD>ܱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param cache_size {int} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param debug_section {int} <EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param flags {unsigned int}
|
|
|
|
|
*/
|
|
|
|
|
void acl_fhandle_init(int cache_size, int debug_section, unsigned int flags);
|
|
|
|
|
#define ACL_FHANDLE_F_LOCK (1 << 0)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>ʱ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ϵͳ<EFBFBD><EFBFBD>Դ
|
|
|
|
|
*/
|
|
|
|
|
void acl_fhandle_end(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
* @param size {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ FS_HANDDLE <EFBFBD><EFBFBD>Ҫ<EFBFBD>Ŀռ<EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @param oflags {unsigned int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ı<EFBFBD>־λ, ACL_FHANDLE_O_XXX
|
|
|
|
|
* @param file_path {const char*} <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>)
|
|
|
|
|
* @param on_open {int (*)(ACL_FHANDLE*, void*)} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param open_arg {void *} on_open <EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮һ
|
|
|
|
|
* @param on_close {void (*)(ACL_FHANDLE*)} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ر<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
ACL_FHANDLE *acl_fhandle_open(size_t size, unsigned int oflags,
|
|
|
|
|
const char *file_path,
|
|
|
|
|
int (*on_open)(ACL_FHANDLE*, void*), void *open_arg,
|
|
|
|
|
void (*on_close)(ACL_FHANDLE*));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>ر<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param fs {ACL_FHANDLE*}
|
|
|
|
|
* @param delay_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> > 0, <EFBFBD><EFBFBD><EFBFBD>ӳٸ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>,
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD>Ϊ 0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void acl_fhandle_close(ACL_FHANDLE *fs, int delay_timeout);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ȼ<EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
* @param fs {ACL_FHANDLE*}
|
|
|
|
|
*/
|
|
|
|
|
void acl_fhandle_lock(ACL_FHANDLE *fs);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>Ƚ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٽ<EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
* @param fs {ACL_FHANDLE*}
|
|
|
|
|
*/
|
|
|
|
|
void acl_fhandle_unlock(ACL_FHANDLE *fs);
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|