mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
migrating acl to android;
modify fiber id to unsigned int.
This commit is contained in:
parent
e2bb0ad167
commit
5e1bd3c5d9
@ -1,7 +1,10 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(acl)
|
||||
add_subdirectory(lib_acl/src lib_acl)
|
||||
message(${CMAKE_SYSTEM_NAME})
|
||||
#set(CMAKE_BUILD_TYPE Release)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "set build type to release")
|
||||
add_subdirectory(lib_protocol/src lib_protocol)
|
||||
add_subdirectory(lib_acl/src lib_acl)
|
||||
add_subdirectory(lib_acl_cpp/src lib_acl_cpp)
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "Linuxxx")
|
||||
add_subdirectory(lib_fiber/src lib_fiber)
|
||||
|
@ -1,6 +1,12 @@
|
||||
#ifndef ACL_DEFINE_LINUX_INCLUDE_H
|
||||
#define ACL_DEFINE_LINUX_INCLUDE_H
|
||||
|
||||
#ifdef ACL_ARM_LINUX
|
||||
# ifndef LINUX2
|
||||
# define LINUX2
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef LINUX2
|
||||
# define ACL_LINUX
|
||||
# define ACL_UNIX
|
||||
|
@ -1,6 +1,8 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
#set(CMAKE_BUILD_TYPE Release)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "set build type to release")
|
||||
|
||||
add_definitions("-g")
|
||||
#add_definitions("-g")
|
||||
add_definitions("-W")
|
||||
add_definitions("-O3")
|
||||
add_definitions("-Wall")
|
||||
@ -16,7 +18,8 @@ add_definitions("-Wno-long-long")
|
||||
add_definitions("-Wuninitialized")
|
||||
add_definitions("-D_POSIX_PTHREAD_SEMANTICS")
|
||||
add_definitions("-DACL_PREPARE_COMPILE")
|
||||
|
||||
add_definitions("-Wno-invalid-source-encoding")
|
||||
add_definitions("-DACL_ARM_LINUX")
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
add_definitions("-DLINUX2")
|
||||
add_definitions("-Wstrict-prototypes")
|
||||
@ -66,5 +69,8 @@ aux_source_directory(${src}/thread lib_src)
|
||||
aux_source_directory(${src}/unit_test lib_src)
|
||||
aux_source_directory(${src}/xml lib_src)
|
||||
|
||||
add_library(_acl ${lib_src})
|
||||
#add_library(_acl SHARED ${lib_src})
|
||||
#add_library(_acl ${lib_src})
|
||||
#link_directories("${CMAKE_BINARY_DIR}")
|
||||
set(lib_output_path ${PROJECT_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path})
|
||||
add_library(_acl SHARED ${lib_src})
|
||||
|
@ -44,7 +44,8 @@ static void master_wakeup_timer_event(int type acl_unused,
|
||||
static char wakeup = ACL_TRIGGER_REQ_WAKEUP;
|
||||
int status = 0;
|
||||
|
||||
acl_assert(event == acl_var_master_global_event);
|
||||
if (event != acl_var_master_global_event)
|
||||
abort();
|
||||
|
||||
/*
|
||||
* Don't wakeup services whose automatic wakeup feature was
|
||||
|
@ -173,10 +173,12 @@ static void dispatch_close(ACL_AIO *aio);
|
||||
|
||||
static void aio_init(void)
|
||||
{
|
||||
acl_assert(pthread_mutex_init(&__closing_time_mutex, NULL) == 0);
|
||||
acl_assert(pthread_mutex_init(&__counter_mutex, NULL) == 0);
|
||||
__last_closing_time = time(NULL);
|
||||
if (pthread_mutex_init(&__closing_time_mutex, NULL) != 0)
|
||||
abort();
|
||||
if (pthread_mutex_init(&__counter_mutex, NULL) != 0)
|
||||
abort();
|
||||
|
||||
__last_closing_time = time(NULL);
|
||||
__use_limit_delay = acl_var_aio_delay_sec > 1 ?
|
||||
acl_var_aio_delay_sec : 1;
|
||||
}
|
||||
|
@ -149,10 +149,12 @@ static unsigned ioctl_server_generation;
|
||||
|
||||
static void ioctl_init(void)
|
||||
{
|
||||
acl_assert(pthread_mutex_init(&__closing_time_mutex, NULL) == 0);
|
||||
acl_assert(pthread_mutex_init(&__counter_mutex, NULL) == 0);
|
||||
__last_closing_time = time(NULL);
|
||||
if (pthread_mutex_init(&__closing_time_mutex, NULL) != 0)
|
||||
abort();
|
||||
if (pthread_mutex_init(&__counter_mutex, NULL) != 0)
|
||||
abort();
|
||||
|
||||
__last_closing_time = time(NULL);
|
||||
__use_limit_delay = acl_var_ioctl_delay_sec > 1 ?
|
||||
acl_var_ioctl_delay_sec : 1;
|
||||
}
|
||||
|
@ -552,7 +552,8 @@ static void main_free_buf(void)
|
||||
|
||||
static void thread_buf_init(void)
|
||||
{
|
||||
acl_assert(acl_pthread_key_create(&__errbuf_key, thread_free_buf) == 0);
|
||||
if (acl_pthread_key_create(&__errbuf_key, thread_free_buf) != 0)
|
||||
abort();
|
||||
}
|
||||
|
||||
static acl_pthread_once_t once_control = ACL_PTHREAD_ONCE_INIT;
|
||||
@ -563,7 +564,8 @@ const char *acl_last_serror(void)
|
||||
int error = acl_last_error();
|
||||
static int __buf_size = 4096;
|
||||
|
||||
acl_assert(acl_pthread_once(&once_control, thread_buf_init) == 0);
|
||||
if (acl_pthread_once(&once_control, thread_buf_init) != 0)
|
||||
abort();
|
||||
|
||||
buf = acl_pthread_getspecific(__errbuf_key);
|
||||
if (buf == NULL) {
|
||||
|
@ -71,9 +71,9 @@ struct ACL_LOG {
|
||||
struct sockaddr_in from;
|
||||
struct sockaddr_in dest;
|
||||
int from_len;
|
||||
acl_uint64 count; /**< 已经记录的日志条数 */
|
||||
time_t last_open; /**< 上次日志打开时间 */
|
||||
time_t reopen_inter; /**< 日志重新打开的最小时间间隔 */
|
||||
acl_uint64 count; /**< <EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
time_t last_open; /**< <EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> */
|
||||
time_t reopen_inter; /**< <EFBFBD><EFBFBD>־<EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><EFBFBD><EFBFBD>Сʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
};
|
||||
|
||||
#ifdef ACL_WINDOWS
|
||||
@ -133,7 +133,11 @@ static int open_file_log(const char *filename, const char *logpre)
|
||||
#else
|
||||
int flag = O_RDWR | O_CREAT | O_APPEND;
|
||||
#endif
|
||||
#ifdef ACL_ARM_LINUX
|
||||
int mode = 0644;
|
||||
#else
|
||||
int mode = S_IREAD | S_IWRITE;
|
||||
#endif
|
||||
ACL_LOG *log;
|
||||
ACL_ITER iter;
|
||||
ACL_VSTREAM *fp;
|
||||
@ -423,13 +427,13 @@ static int open_log(const char *recipient, const char *logpre)
|
||||
}
|
||||
|
||||
/*
|
||||
* recipients 可以是以下日志格式的组合:
|
||||
* recipients <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
||||
* tcp:127.0.0.1:8088
|
||||
* udp:127.0.0.1:8088
|
||||
* unix:/var/log/unix.sock
|
||||
* file:/var/log/unix.log
|
||||
* /var/log/unix.log
|
||||
* 如:tcp:127.0.0.1:8088|/var/log/unix.log
|
||||
* <EFBFBD>磺tcp:127.0.0.1:8088|/var/log/unix.log
|
||||
*/
|
||||
int acl_open_log(const char *recipients, const char *logpre)
|
||||
{
|
||||
|
@ -275,7 +275,7 @@ static int sys_read(ACL_VSTREAM *in, void *buf, size_t size)
|
||||
|
||||
AGAIN:
|
||||
|
||||
/* 清除系统错误号 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
acl_set_error(0);
|
||||
|
||||
if (in->type == ACL_VSTREAM_TYPE_FILE) {
|
||||
@ -447,8 +447,8 @@ int acl_vstream_nonb_readn(ACL_VSTREAM *fp, char *buf, int size)
|
||||
acl_non_blocking(ACL_VSTREAM_SOCK(fp), 1);
|
||||
#endif
|
||||
|
||||
/* 先保留读写超时时间值,并将该流的超时值置为0,以免
|
||||
* 启动读超时过程(select)。
|
||||
/* <EFBFBD>ȱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʱֵ<EFBFBD><EFBFBD>Ϊ0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(select)<EFBFBD><EFBFBD>
|
||||
*/
|
||||
rw_timeout = fp->rw_timeout;
|
||||
fp->rw_timeout = 0;
|
||||
@ -458,7 +458,7 @@ int acl_vstream_nonb_readn(ACL_VSTREAM *fp, char *buf, int size)
|
||||
|
||||
fp->rw_timeout = rw_timeout;
|
||||
|
||||
/* 恢复该套接字的原有标记位 */
|
||||
/* <EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ԭ<EFBFBD>б<EFBFBD><EFBFBD>λ */
|
||||
#ifdef ACL_UNIX
|
||||
flags = fcntl(ACL_VSTREAM_SOCK(fp), F_SETFL, flags);
|
||||
if (flags < 0) {
|
||||
@ -541,8 +541,8 @@ int acl_vstream_probe_status(ACL_VSTREAM *fp)
|
||||
|
||||
rw_timeout = fp->rw_timeout;
|
||||
|
||||
/* 先保留读写超时时间值,并将该流的超时值置为0,以免
|
||||
* 启动读超时过程(select)。
|
||||
/* <EFBFBD>ȱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʱֵ<EFBFBD><EFBFBD>Ϊ0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(select)<EFBFBD><EFBFBD>
|
||||
*/
|
||||
fp->rw_timeout = 0;
|
||||
fp->errnum = 0;
|
||||
@ -551,7 +551,7 @@ int acl_vstream_probe_status(ACL_VSTREAM *fp)
|
||||
|
||||
fp->rw_timeout = rw_timeout;
|
||||
|
||||
/* 恢复该套接字的原有标记位 */
|
||||
/* <EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ԭ<EFBFBD>б<EFBFBD><EFBFBD>λ */
|
||||
#ifdef ACL_UNIX
|
||||
flags = fcntl(ACL_VSTREAM_SOCK(fp), F_SETFL, flags);
|
||||
if (flags < 0) {
|
||||
@ -576,7 +576,7 @@ int acl_vstream_probe_status(ACL_VSTREAM *fp)
|
||||
else
|
||||
return -1;
|
||||
} else {
|
||||
/* 将读到的数据再放回原处:) */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٷŻ<EFBFBD>ԭ<EFBFBD><EFBFBD>:) */
|
||||
fp->read_cnt++;
|
||||
fp->read_ptr--;
|
||||
fp->offset--;
|
||||
@ -612,7 +612,7 @@ static void *__vstream_memmove(ACL_VSTREAM *fp, size_t n)
|
||||
src = (char*) fp->read_ptr + fp->read_cnt - 1;
|
||||
dst_saved = dst = (char*) fp->read_ptr + n + fp->read_cnt - 1;
|
||||
|
||||
/* 为了防止内存数据覆盖问题, 采用数据从尾部拷贝方式 */
|
||||
/* Ϊ<EFBFBD>˷<EFBFBD>ֹ<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ */
|
||||
while (src >= (char*) fp->read_ptr)
|
||||
*dst-- = *src--;
|
||||
return dst_saved;
|
||||
@ -637,7 +637,7 @@ int acl_vstream_unread(ACL_VSTREAM *fp, const void *ptr, size_t length)
|
||||
capacity = fp->read_ptr - fp->read_buf;
|
||||
k = (ssize_t) (capacity - length);
|
||||
|
||||
/* 如果读缓冲中前部分空间不足, 则需要调整数据位置或扩充读缓冲区空间 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ֿռ䲻<EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD> */
|
||||
|
||||
if (k < 0) {
|
||||
void *pbuf;
|
||||
@ -645,7 +645,7 @@ int acl_vstream_unread(ACL_VSTREAM *fp, const void *ptr, size_t length)
|
||||
|
||||
n = (size_t) -k;
|
||||
|
||||
/* 如果读缓冲区后部分空间够用, 则只需后移缓冲区中的数据 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ乻<EFBFBD><EFBFBD>, <20><>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
if (fp->read_buf_len - fp->read_cnt > (acl_off_t) length) {
|
||||
if (fp->read_cnt > 0)
|
||||
@ -658,7 +658,7 @@ int acl_vstream_unread(ACL_VSTREAM *fp, const void *ptr, size_t length)
|
||||
return (int) length;
|
||||
}
|
||||
|
||||
/* 说明整个缓冲区的空间都不够用, 所以需要扩充缓冲区空间 */
|
||||
/* ˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀռ䶼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>仺<EFBFBD><E4BBBA><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD> */
|
||||
|
||||
n = min_delta * ((n + min_delta - 1) / min_delta);
|
||||
acl_assert(n > 0);
|
||||
@ -782,16 +782,16 @@ int acl_vstream_readtags(ACL_VSTREAM *fp, void *vptr, size_t maxlen,
|
||||
needle = needle_end - 1;
|
||||
matched = 0;
|
||||
while(1) {
|
||||
/* 已经成功比较完毕(匹配) */
|
||||
/* <EFBFBD>Ѿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD>Ƚ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(ƥ<><C6A5>) */
|
||||
if (needle < (const unsigned char *) tag) {
|
||||
matched = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* 原字符串用完而匹配串还没有比较完(不匹配) */
|
||||
/* ԭ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD>䴮<EFBFBD><EFBFBD>û<EFBFBD>бȽ<EFBFBD><EFBFBD><EFBFBD>(<28><>ƥ<EFBFBD><C6A5>) */
|
||||
if (haystack < (unsigned char *) vptr)
|
||||
break;
|
||||
/* 不相等(不匹配) */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><>ƥ<EFBFBD><C6A5>) */
|
||||
if (*haystack != *needle)
|
||||
break;
|
||||
haystack--;
|
||||
@ -921,7 +921,7 @@ int acl_vstream_readn(ACL_VSTREAM *fp, void *buf, size_t size)
|
||||
|
||||
ptr = (unsigned char*) buf;
|
||||
|
||||
/* 如果缓冲区中有上次读残留数据时,则优先将其拷贝至目标缓冲区 */
|
||||
/* <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> */
|
||||
|
||||
if (fp->read_cnt > 0) {
|
||||
n = acl_vstream_bfcp_some(fp, ptr, size);
|
||||
@ -931,7 +931,7 @@ int acl_vstream_readn(ACL_VSTREAM *fp, void *buf, size_t size)
|
||||
return (int) size_saved;
|
||||
}
|
||||
|
||||
/* 为减少 read 次数,当输入缓冲区较小时,则自动启用双缓冲读方式 */
|
||||
/* Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> read <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сʱ<D0A1><CAB1><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ */
|
||||
|
||||
if (size_saved < (size_t) fp->read_buf_len / 4) {
|
||||
while (size > 0) {
|
||||
@ -943,7 +943,7 @@ int acl_vstream_readn(ACL_VSTREAM *fp, void *buf, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
/* 否则,则直接将读到的数据存入缓冲区,从而避免大数据的二次拷贝 */
|
||||
/* <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> */
|
||||
else {
|
||||
while (size > 0) {
|
||||
n = read_to_buffer(fp, ptr, size);
|
||||
@ -980,12 +980,12 @@ int acl_vstream_read(ACL_VSTREAM *fp, void *buf, size_t size)
|
||||
|
||||
/* fp->read_cnt == 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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (size >= (size_t) fp->read_buf_len / 4) {
|
||||
int n = read_to_buffer(fp, buf, size);
|
||||
return n <= 0 ? ACL_VSTREAM_EOF : n;
|
||||
}
|
||||
/* 否则将数据读到流缓冲区中,然后再拷贝,从而减少 read 次数 */
|
||||
/* <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> read <20><><EFBFBD><EFBFBD> */
|
||||
else {
|
||||
int read_cnt = read_buffed(fp);
|
||||
if (read_cnt <= 0)
|
||||
@ -1063,9 +1063,9 @@ int acl_vstream_gets_peek(ACL_VSTREAM *fp, ACL_VSTRING *buf, int *ready)
|
||||
return (int) LEN(buf) - n;
|
||||
}
|
||||
|
||||
/* XXX: 调用者通过检查 *ready 值来判断是否读够数据, 系统IO读操作出错
|
||||
* 或关闭时返回结束标记; 如果返回 ACL_VSTRING_EOF 则调用者应该通过
|
||||
* 检查缓冲区长度来处理未被处理的数据
|
||||
/* XXX: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *ready ֵ<><D6B5><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ϵͳIO<49><4F><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_VSTRING_EOF <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>
|
||||
*/
|
||||
|
||||
if (fp->read_ready) {
|
||||
@ -1137,9 +1137,9 @@ int acl_vstream_gets_nonl_peek(ACL_VSTREAM *fp, ACL_VSTRING *buf, int *ready)
|
||||
return (int) LEN(buf) - n;
|
||||
}
|
||||
|
||||
/* XXX: 调用者通过检查 *ready 值来判断是否读够数据, 系统IO读操作出错
|
||||
* 或关闭时返回结束标记; 如果返回 ACL_VSTRING_EOF 则调用者应该通过
|
||||
* 检查缓冲区长度来处理未被处理的数据
|
||||
/* XXX: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *ready ֵ<><D6B5><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ϵͳIO<49><4F><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_VSTRING_EOF <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>
|
||||
*/
|
||||
|
||||
if (fp->read_ready) {
|
||||
@ -1202,9 +1202,9 @@ int acl_vstream_readn_peek(ACL_VSTREAM *fp, ACL_VSTRING *buf,
|
||||
return cnt_saved - cnt;
|
||||
}
|
||||
|
||||
/* XXX: 调用者通过检查 *ready 值来判断是否读够数据, 系统IO读操作出错
|
||||
* 或关闭时返回结束标记, 如果返回 ACL_VSTRING_EOF 则调用者应该通过
|
||||
* 检查缓冲区长度来处理未被处理的数据
|
||||
/* XXX: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *ready ֵ<><D6B5><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ϵͳIO<49><4F><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_VSTRING_EOF <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>
|
||||
*/
|
||||
|
||||
if (fp->read_ready) {
|
||||
@ -1256,8 +1256,8 @@ int acl_vstream_read_peek(ACL_VSTREAM *fp, ACL_VSTRING *buf)
|
||||
if (fp->read_cnt > 0)
|
||||
bfread_peek(fp, buf);
|
||||
|
||||
/* 系统IO读操作出错或关闭时返回结束标记, 如果返回 ACL_VSTRING_EOF
|
||||
* 则调用者应该通过检查缓冲区长度来处理未被处理的数据
|
||||
/* ϵͳIO<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ACL_VSTRING_EOF
|
||||
* <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>
|
||||
*/
|
||||
|
||||
if (fp->read_ready) {
|
||||
@ -1335,7 +1335,7 @@ static int write_once(ACL_VSTREAM *fp, const void *vptr, int dlen)
|
||||
|
||||
TAG_AGAIN:
|
||||
|
||||
/* 清除系统错误号 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
acl_set_error(0);
|
||||
|
||||
if (fp->type == ACL_VSTREAM_TYPE_FILE) {
|
||||
@ -1375,7 +1375,7 @@ TAG_AGAIN:
|
||||
fp->sys_offset += n;
|
||||
fp->offset = fp->sys_offset;
|
||||
|
||||
/* 防止缓冲区内的数据与实际不一致, 仅对文件IO有效 */
|
||||
/* <EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʲ<EFBFBD>һ<EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>IO<49><4F>Ч */
|
||||
fp->read_cnt = 0;
|
||||
}
|
||||
} else {
|
||||
@ -1491,18 +1491,18 @@ TAG_AGAIN:
|
||||
fp->sys_offset += n;
|
||||
fp->offset = fp->sys_offset;
|
||||
|
||||
/* 防止缓冲区内的数据与实际不一致, 仅对文件IO有效 */
|
||||
/* <EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʲ<EFBFBD>һ<EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>IO<49><4F>Ч */
|
||||
fp->read_cnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 当写接口函数指针为系统默认的接口时,直接写入 */
|
||||
/* <EFBFBD><EFBFBD>д<EFBFBD>ӿں<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>ΪϵͳĬ<EFBFBD>ϵĽӿ<EFBFBD>ʱ<EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD> */
|
||||
else if (fp->write_fn == acl_socket_write) {
|
||||
n = fp->writev_fn(ACL_VSTREAM_SOCK(fp), vec, count,
|
||||
fp->rw_timeout, fp, fp->context);
|
||||
}
|
||||
|
||||
/* 否则,则模拟 writev 的调用过程 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD> writev <20>ĵ<EFBFBD><C4B5>ù<EFBFBD><C3B9><EFBFBD> */
|
||||
else {
|
||||
int i, ret;
|
||||
|
||||
@ -1759,7 +1759,7 @@ static int loop_writen(ACL_VSTREAM *fp, const void *vptr, size_t size)
|
||||
const char *myname = "loop_writen";
|
||||
#endif
|
||||
const unsigned char *ptr = (const unsigned char *) vptr;
|
||||
int once_dlen = 64 * 1024 * 1024; /* xxx: 以 64KB 为单位写 */
|
||||
int once_dlen = 64 * 1024 * 1024; /* xxx: <EFBFBD><EFBFBD> 64KB Ϊ<><CEAA>λд */
|
||||
int nleft = (int) size, n, len;
|
||||
#if 0
|
||||
time_t begin, end;
|
||||
@ -1779,8 +1779,8 @@ static int loop_writen(ACL_VSTREAM *fp, const void *vptr, size_t size)
|
||||
if (n == len || fp->writev_fn == NULL || fp->rw_timeout <= 0)
|
||||
continue;
|
||||
|
||||
/* 对于套接口写操作,如果一次性写没有写完,可能是系统
|
||||
* 写缓冲区满,需要检测超时写
|
||||
/* <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>ⳬʱд
|
||||
*/
|
||||
begin = time(NULL);
|
||||
|
||||
@ -2100,7 +2100,7 @@ void acl_socket_close_hook(int (*close_fn)(ACL_SOCKET))
|
||||
acl_socket_close_fn = close_fn;
|
||||
}
|
||||
|
||||
/* 定义流的缓冲区的默认大小 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϴ<EFBFBD>С */
|
||||
|
||||
#define ACL_VSTREAM_DEF_MAXLEN 8192
|
||||
|
||||
@ -2120,9 +2120,9 @@ ACL_VSTREAM *acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
myname, __LINE__, (int) buflen);
|
||||
}
|
||||
|
||||
/* XXX: 只有非监听流才需要有读缓冲区 */
|
||||
/* XXX: 目前 UDP 服务端口号在 MASTER 框架中暂时当监听套接口用,所以
|
||||
* 需要给其分配读缓冲区
|
||||
/* XXX: ֻ<EFBFBD>зǼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/* XXX: Ŀǰ UDP <20><><EFBFBD><EFBFBD>˿ں<CBBF><DABA><EFBFBD> MASTER <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<D7BD><D3BF>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
if (buflen < ACL_VSTREAM_DEF_MAXLEN)
|
||||
buflen = ACL_VSTREAM_DEF_MAXLEN;
|
||||
@ -2173,11 +2173,11 @@ ACL_VSTREAM *acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
fp->close_fn = acl_socket_close_fn;
|
||||
|
||||
/**
|
||||
* bugfix: 不应在此处直接设为非阻塞方式,否则会影响上层调用者
|
||||
* 的行为,应该在应用自己来处理此事。---zsx, 2016.11.18
|
||||
* bugfix: <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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¡<EFBFBD>---zsx, 2016.11.18
|
||||
*/
|
||||
/* xxx: 对于带有读写超时的流,需要先将 socket 设为非阻塞模式,
|
||||
* 否则在写大数据包时会造成阻塞,超时作用失效
|
||||
/* xxx: <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ж<EFBFBD>д<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ƚ<EFBFBD> socket <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>
|
||||
* <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>ʧЧ
|
||||
*/
|
||||
/**
|
||||
* if (rw_timeout > 0 && acl_getsocktype(fd) >= 0)
|
||||
@ -2362,7 +2362,11 @@ char *acl_vstream_loadfile2(const char *path, ssize_t *size)
|
||||
#else
|
||||
int oflags = O_RDONLY;
|
||||
#endif
|
||||
#ifdef ACL_ARM_LINUX
|
||||
int mode = 0644;
|
||||
#else
|
||||
int mode = S_IREAD;
|
||||
#endif
|
||||
int ret;
|
||||
ACL_VSTRING *vbuf;
|
||||
unsigned char buf[4096];
|
||||
@ -2490,7 +2494,7 @@ acl_off_t acl_vstream_fseek2(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
goto SYS_SEEK2;
|
||||
}
|
||||
|
||||
/* 获得真正的当前文件指针位置 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ǰ<EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD> */
|
||||
n = acl_lseek(ACL_VSTREAM_FILE(fp), (acl_off_t) 0, SEEK_CUR);
|
||||
if (n < 0)
|
||||
return -1;
|
||||
@ -2498,11 +2502,11 @@ acl_off_t acl_vstream_fseek2(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
if (whence == SEEK_CUR) {
|
||||
if (fp->read_cnt >= offset) {
|
||||
fp->read_cnt -= (int) offset;
|
||||
n = -fp->read_cnt; /* 计算出真实的文件位置 */
|
||||
n = -fp->read_cnt; /* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>λ<EFBFBD><EFBFBD> */
|
||||
fp->read_cnt = 0;
|
||||
} else if (fp->read_cnt >= 0) {
|
||||
offset -= fp->read_cnt;
|
||||
n = offset; /* 计算出真实的文件位置 */
|
||||
n = offset; /* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>λ<EFBFBD><EFBFBD> */
|
||||
fp->read_cnt = 0;
|
||||
} else { /* fp->read_cnt < 0 ? */
|
||||
acl_msg_error("%s, %s(%d): invalud read_cnt = %d",
|
||||
@ -2516,7 +2520,7 @@ acl_off_t acl_vstream_fseek2(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
}
|
||||
|
||||
SYS_SEEK2:
|
||||
/* 定位到合适的位置 */
|
||||
/* <EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>λ<EFBFBD><EFBFBD> */
|
||||
fp->sys_offset = acl_lseek(
|
||||
ACL_VSTREAM_FILE(fp), offset, whence);
|
||||
fp->offset = fp->sys_offset;
|
||||
@ -2554,9 +2558,9 @@ acl_off_t acl_vstream_fseek(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
}
|
||||
|
||||
if (whence == SEEK_CUR) {
|
||||
/* 相对当前流位置 fp->offset 开始偏移 offset 的位置 */
|
||||
/* <EFBFBD><EFBFBD>Ե<EFBFBD>ǰ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD> fp->offset <20><>ʼƫ<CABC><C6AB> offset <20><>λ<EFBFBD><CEBB> */
|
||||
|
||||
/* 必须严格检验 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (fp->offset + fp->read_cnt != fp->sys_offset) {
|
||||
acl_msg_error("%s, %s(%d): offset(" ACL_FMT_I64D
|
||||
") + read_cnt(%d) != sys_offset("
|
||||
@ -2567,23 +2571,23 @@ acl_off_t acl_vstream_fseek(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
goto SYS_SEEK;
|
||||
}
|
||||
|
||||
/* 是否在读缓冲区间内 */
|
||||
/* <EFBFBD>Ƿ<EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (fp->read_cnt >= offset) {
|
||||
/* 因为要从 fp->offset 偏移 offset 个字节后, 读指针
|
||||
* fp->read_ptr 依然在缓冲区内, 所以只需要移动读指针
|
||||
* 且减少缓冲区字节数、增加 fp->offset 偏移量即可.
|
||||
/* <EFBFBD><EFBFBD>ΪҪ<EFBFBD><EFBFBD> fp->offset ƫ<><C6AB> offset <20><><EFBFBD>ֽں<D6BD>, <20><>ָ<EFBFBD><D6B8>
|
||||
* fp->read_ptr <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> fp->offset ƫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*/
|
||||
fp->read_cnt -= (int) offset;
|
||||
fp->read_ptr += (int) offset;
|
||||
fp->offset += offset;
|
||||
return fp->offset;
|
||||
} else if (fp->read_cnt >= 0) {
|
||||
/* 因为要计算从当前流位置 fp->offset 开始偏移 offset
|
||||
* 的位置,而且流中还存在一定的缓存数据(fp->read_cnt),
|
||||
* 所以需要先从 fp->offset 开始移动 fp->read_cnt
|
||||
* 个字节(移动出读缓冲区),然后再移动剩余的字节
|
||||
* (即 offset - fp->read_cnt) 即可; 因为已经称出读缓
|
||||
* 冲区,所以需要将 fp->read_cnt 置 0.
|
||||
/* <EFBFBD><EFBFBD>ΪҪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ǰ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD> fp->offset <20><>ʼƫ<CABC><C6AB> offset
|
||||
* <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>(fp->read_cnt),
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ȴ<EFBFBD> fp->offset <EFBFBD><EFBFBD>ʼ<EFBFBD>ƶ<EFBFBD> fp->read_cnt
|
||||
* <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> offset - fp->read_cnt) <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> fp->read_cnt <EFBFBD><EFBFBD> 0.
|
||||
*/
|
||||
offset -= fp->read_cnt;
|
||||
fp->read_cnt = 0;
|
||||
@ -2595,11 +2599,11 @@ acl_off_t acl_vstream_fseek(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
}
|
||||
} else if (whence == SEEK_SET) {
|
||||
#if 0
|
||||
/* 获得真正的当前文件指针位置 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ǰ<EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD> */
|
||||
fp->sys_offset = acl_lseek(ACL_VSTREAM_FILE(fp),
|
||||
(off_t) 0, SEEK_CUR);
|
||||
#endif
|
||||
/* 利用缓存的偏移位置 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD> */
|
||||
|
||||
if (fp->sys_offset < 0) {
|
||||
acl_msg_error("%s, %s(%d): seek n(" ACL_FMT_I64D
|
||||
@ -2609,7 +2613,7 @@ acl_off_t acl_vstream_fseek(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
goto SYS_SEEK;
|
||||
}
|
||||
|
||||
/* 必须严格检验 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (fp->offset + fp->read_cnt != fp->sys_offset) {
|
||||
acl_msg_error("%s, %s(%d): offset(" ACL_FMT_I64D
|
||||
") + read_cnt(%d) != sys_offset("
|
||||
@ -2620,8 +2624,8 @@ acl_off_t acl_vstream_fseek(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
goto SYS_SEEK;
|
||||
}
|
||||
|
||||
/* 如果读数据指针经过移动,可以将其回移,因为缓冲区内数据
|
||||
* 并未破坏,可以复用
|
||||
/* <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>Ը<EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
if (fp->read_ptr > fp->read_buf) {
|
||||
n = fp->read_ptr - fp->read_buf;
|
||||
@ -2630,7 +2634,7 @@ acl_off_t acl_vstream_fseek(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
fp->read_cnt += (int) n;
|
||||
}
|
||||
|
||||
/* 判断请求的偏移位置是否在读缓存区间内 */
|
||||
/* <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> */
|
||||
if (offset >= fp->offset && offset <= fp->sys_offset) {
|
||||
n = offset - fp->offset;
|
||||
fp->read_cnt -= (int) n;
|
||||
@ -2643,7 +2647,7 @@ acl_off_t acl_vstream_fseek(ACL_VSTREAM *fp, acl_off_t offset, int whence)
|
||||
fp->read_cnt = 0;
|
||||
|
||||
SYS_SEEK:
|
||||
/* 调用系统调用定位位置 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>λλ<EFBFBD><EFBFBD> */
|
||||
fp->sys_offset = acl_lseek(ACL_VSTREAM_FILE(fp), offset, whence);
|
||||
fp->offset = fp->sys_offset;
|
||||
|
||||
@ -2658,7 +2662,7 @@ acl_off_t acl_vstream_ftell(ACL_VSTREAM *fp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 先定位当前位置,然后再减去读缓冲区里的数据长度 */
|
||||
/* <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> */
|
||||
fp->sys_offset = acl_lseek(ACL_VSTREAM_FILE(fp), 0, SEEK_CUR);
|
||||
fp->offset = fp->sys_offset;
|
||||
return fp->offset - fp->read_cnt;
|
||||
@ -2676,15 +2680,15 @@ int acl_file_ftruncate(ACL_VSTREAM *fp, acl_off_t length)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 参见:C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\crt\src
|
||||
/* <EFBFBD>μ<EFBFBD><EFBFBD><EFBFBD>C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\crt\src
|
||||
* osfinfo.c
|
||||
* _open_osfhandle: 将ACL_WINDOWS API的文件句柄转换为标准C的文件句柄
|
||||
* _get_osfhandle: 根据标准C文件句柄查询ACL_WINDOWS API文件句柄
|
||||
* _free_osfhnd: 释放由 _open_osfhandle 打开的标准C文件句柄的资源,
|
||||
* 但并不实际关闭该ACL_WINDOWS API句柄,所以还得要对其真实
|
||||
* ACL_WINDOWS API文件句柄进行关闭
|
||||
* _open_osfhandle: <EFBFBD><EFBFBD>ACL_WINDOWS API<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>C<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* _get_osfhandle: <EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD>C<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯACL_WINDOWS API<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* _free_osfhnd: <EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD> _open_osfhandle <EFBFBD>ı<EFBFBD>C<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʹرո<EFBFBD>ACL_WINDOWS API<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ
|
||||
* ACL_WINDOWS API<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>йر<EFBFBD>
|
||||
* close.c
|
||||
* _close: 关闭并释放标准C的文件句柄
|
||||
* _close: <EFBFBD>رղ<EFBFBD><EFBFBD>ͷű<EFBFBD>C<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
if (acl_vstream_fseek(fp, length, SEEK_SET) < 0) {
|
||||
@ -2809,7 +2813,7 @@ void acl_vstream_free(ACL_VSTREAM *fp)
|
||||
}
|
||||
|
||||
if (fp->nrefer > 0) {
|
||||
/* 设置延迟释放标志位 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD>ͷű<EFBFBD>־λ */
|
||||
fp->flag |= ACL_VSTREAM_FLAG_DEFER_FREE;
|
||||
return;
|
||||
}
|
||||
@ -2818,9 +2822,9 @@ void acl_vstream_free(ACL_VSTREAM *fp)
|
||||
ACL_VSTREAM_CLOSE_HANDLE *close_handle;
|
||||
int i, n = acl_array_size(fp->close_handle_lnk);
|
||||
|
||||
/* 因为添加时是正序的, 所以在删除时是倒序的,
|
||||
* 这样对动态数组的使用的效率才会比较高,
|
||||
* 避免了动态数组内部移动的情况
|
||||
/* <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ʱ<EFBFBD>ǵ<EFBFBD><C7B5><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>
|
||||
*/
|
||||
for (i = n - 1; i >= 0; i++) {
|
||||
close_handle = (ACL_VSTREAM_CLOSE_HANDLE *)
|
||||
@ -2829,9 +2833,9 @@ void acl_vstream_free(ACL_VSTREAM *fp)
|
||||
break;
|
||||
if (close_handle->close_fn == NULL)
|
||||
continue;
|
||||
/* 只所将此调用放在 close_fn 前面,是为了防止有人误在
|
||||
* close_fn 里调用了删除回调函数的操作而造成对同一内
|
||||
* 存的多次释放
|
||||
/* ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD> close_fn ǰ<>棬<EFBFBD><E6A3AC>Ϊ<EFBFBD>˷<EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* close_fn <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD>ͬһ<EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
|
||||
*/
|
||||
acl_array_delete_idx(fp->close_handle_lnk, i, NULL);
|
||||
close_handle->close_fn(fp, close_handle->context);
|
||||
@ -2881,7 +2885,7 @@ int acl_vstream_close(ACL_VSTREAM *fp)
|
||||
}
|
||||
|
||||
if (fp->nrefer > 0) {
|
||||
/* 设置延迟释放标志位 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD>ͷű<EFBFBD>־λ */
|
||||
fp->flag |= ACL_VSTREAM_FLAG_DEFER_FREE;
|
||||
return 0;
|
||||
}
|
||||
@ -2890,21 +2894,21 @@ int acl_vstream_close(ACL_VSTREAM *fp)
|
||||
if (acl_vstream_fflush(fp) == ACL_VSTREAM_EOF)
|
||||
acl_msg_error("%s: fflush fp error", myname);
|
||||
|
||||
/* 须在调用各个关闭回调函数之前将连接关闭,否则会影响 iocp 的事件引擎
|
||||
* 正常工作。在使用 iocp 事件引擎时,当流关闭时会调用 events_iocp.c 中
|
||||
* 的 stream_on_close,该函数会释放掉 fdp->event_read/fdp->event_write
|
||||
* 两个对象,但当套接口未关闭时,这两个对象有可能会被 iocp 使用,当套
|
||||
* 接口关闭时,iocp 才不会使用这两个对象中的 IOCP_EVENT->overlapped 等
|
||||
* 成员. ---2011.5.18, zsx
|
||||
/* <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> iocp <20><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> iocp <EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> events_iocp.c <EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD> stream_on_close<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷŵ<EFBFBD> fdp->event_read/fdp->event_write
|
||||
* <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>ܻᱻ iocp ʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <EFBFBD>ӿڹر<EFBFBD>ʱ<EFBFBD><EFBFBD>iocp <EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> IOCP_EVENT->overlapped <EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD>Ա. ---2011.5.18, zsx
|
||||
*/
|
||||
/*
|
||||
* 2011.5.18 的改动虽解决了事件引擎为 iocp 的问题,但同时造成了 win32
|
||||
* 窗口消息引擎的问题,虽然 win32 消息引擎的方式在关闭套接口之前会回调
|
||||
* stream_on_close,该回调要求套接口必须是打开的,既然二者出现了冲突,
|
||||
* 则 iocp 的问题还是由 iocp 引擎本身去解决吧,即在 iocp 引擎的
|
||||
* stream_on_close 中,在释放 fdp->event_read/fdp->event_write 前关闭
|
||||
* 套接口即可,在 acl_vstream_close 最后需要关闭套接口时只要根据句柄
|
||||
* 是否有效来判断是否调用关闭过程. ---2011.5.19, zsx
|
||||
* 2011.5.18 <EFBFBD>ĸĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ iocp <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> win32
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD>Ȼ win32 <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>ʽ<EFBFBD>ڹر<EFBFBD><EFBFBD>ӿ<EFBFBD>֮ǰ<EFBFBD><EFBFBD>ص<EFBFBD>
|
||||
* stream_on_close<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> iocp <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> iocp <EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> iocp <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* stream_on_close <EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD> fdp->event_read/fdp->event_write ǰ<EFBFBD>ر<EFBFBD>
|
||||
* <EFBFBD>ӿڼ<EFBFBD><EFBFBD>ɣ<EFBFBD><EFBFBD><EFBFBD> acl_vstream_close <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>. ---2011.5.19, zsx
|
||||
*/
|
||||
/*
|
||||
if (fp->read_buf != NULL)
|
||||
@ -2921,9 +2925,9 @@ int acl_vstream_close(ACL_VSTREAM *fp)
|
||||
ACL_VSTREAM_CLOSE_HANDLE *close_handle;
|
||||
int i, n = acl_array_size(fp->close_handle_lnk);
|
||||
|
||||
/* 因为添加时是正序的, 所以在删除时是倒序的,
|
||||
* 这样对动态数组的使用的效率才会比较高,
|
||||
* 避免了动态数组内部移动的情况
|
||||
/* <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ʱ<EFBFBD>ǵ<EFBFBD><C7B5><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>
|
||||
*/
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
close_handle = (ACL_VSTREAM_CLOSE_HANDLE *)
|
||||
@ -2932,9 +2936,9 @@ int acl_vstream_close(ACL_VSTREAM *fp)
|
||||
continue;
|
||||
if (close_handle->close_fn == NULL)
|
||||
continue;
|
||||
/* 只所将此调用放在 close_fn 前面,是为了防止有人误在
|
||||
* close_fn 里调用了删除回调函数的操作而造成对同一内存
|
||||
* 的多次释放
|
||||
/* ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD> close_fn ǰ<>棬<EFBFBD><E6A3AC>Ϊ<EFBFBD>˷<EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* close_fn <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD>ͬһ<EFBFBD>ڴ<EFBFBD>
|
||||
* <EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
|
||||
*/
|
||||
acl_array_delete_idx(fp->close_handle_lnk, i, NULL);
|
||||
close_handle->close_fn(fp, close_handle->context);
|
||||
@ -3142,9 +3146,9 @@ void acl_vstream_call_close_handles(ACL_VSTREAM *fp)
|
||||
ACL_VSTREAM_CLOSE_HANDLE *close_handle;
|
||||
int i, n = acl_array_size(fp->close_handle_lnk);
|
||||
|
||||
/* 因为添加时是正序的, 所以在删除时是倒序的,
|
||||
* 这样对动态数组的使用的效率才会比较高,
|
||||
* 避免了动态数组内部移动的情况
|
||||
/* <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ʱ<EFBFBD>ǵ<EFBFBD><C7B5><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>
|
||||
*/
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
close_handle = (ACL_VSTREAM_CLOSE_HANDLE *)
|
||||
@ -3153,9 +3157,9 @@ void acl_vstream_call_close_handles(ACL_VSTREAM *fp)
|
||||
continue;
|
||||
if (close_handle->close_fn == NULL)
|
||||
continue;
|
||||
/* 只所将此调用放在 close_fn 前面,是为了防止有人误在
|
||||
* close_fn 里调用了删除回调函数的操作而造成对同一内存
|
||||
* 的多次释放
|
||||
/* ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD> close_fn ǰ<>棬<EFBFBD><E6A3AC>Ϊ<EFBFBD>˷<EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* close_fn <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD>ͬһ<EFBFBD>ڴ<EFBFBD>
|
||||
* <EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
|
||||
*/
|
||||
acl_array_delete_idx(fp->close_handle_lnk, i, NULL);
|
||||
close_handle->close_fn(fp, close_handle->context);
|
||||
@ -3231,9 +3235,9 @@ void acl_vstream_delete_close_handle(ACL_VSTREAM *fp,
|
||||
if (n <= 0)
|
||||
return;
|
||||
|
||||
/* 因为添加时是正序的, 所以在删除时是倒序的,
|
||||
* 这样对动态数组的使用的效率才会比较高,
|
||||
* 避免了动态数组内部移动的情况
|
||||
/* <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ʱ<EFBFBD>ǵ<EFBFBD><C7B5><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>
|
||||
*/
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
close_handle = (ACL_VSTREAM_CLOSE_HANDLE *)
|
||||
@ -3259,9 +3263,9 @@ void acl_vstream_clean_close_handle(ACL_VSTREAM *fp)
|
||||
return;
|
||||
|
||||
n = acl_array_size(fp->close_handle_lnk);
|
||||
/* 因为添加时是正序的, 所以在删除时是倒序的,
|
||||
* 这样对动态数组的使用的效率才会比较高,
|
||||
* 避免了动态数组内部移动的情况
|
||||
/* <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ʱ<EFBFBD>ǵ<EFBFBD><C7B5><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>
|
||||
*/
|
||||
for (i = n - 1; i >= 0; i++) {
|
||||
close_handle = (ACL_VSTREAM_CLOSE_HANDLE *)
|
||||
|
@ -904,6 +904,9 @@ avl_create(avl_tree_t *tree, int (*compar) (const void *, const void *),
|
||||
void
|
||||
avl_destroy(avl_tree_t *tree)
|
||||
{
|
||||
#ifdef ACL_ARM_LINUX
|
||||
(void) tree;
|
||||
#endif
|
||||
ASSERT(tree);
|
||||
ASSERT(tree->avl_numnodes == 0);
|
||||
ASSERT(tree->avl_root == NULL);
|
||||
|
@ -234,7 +234,11 @@ ACL_CFG_PARSER *acl_cfg_parser_load(const char *pathname, const char *delimiter)
|
||||
}
|
||||
|
||||
#ifdef ACL_UNIX
|
||||
# ifdef ACL_ARM_LINUX
|
||||
filefd = acl_file_open(pathname, O_RDWR, 0644);
|
||||
# else
|
||||
filefd = acl_file_open(pathname, O_RDWR, S_IREAD | S_IWRITE | S_IRGRP);
|
||||
# endif
|
||||
#elif defined(ACL_WINDOWS)
|
||||
filefd = acl_file_open(pathname, O_RDWR, S_IREAD | S_IWRITE);
|
||||
#else
|
||||
@ -264,7 +268,7 @@ ACL_CFG_PARSER *acl_cfg_parser_load(const char *pathname, const char *delimiter)
|
||||
/* first, skip all ' ' and '\t' */
|
||||
SKIP(ptr, (*ptr == ' ' || *ptr == '\t'));
|
||||
|
||||
/* 操作存储注释行 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (*ptr == '#') { /* the comment line */
|
||||
SKIP(ptr, *ptr != '\n'); /* find the line's end */
|
||||
if (*ptr) { /* this must be '\n' */
|
||||
@ -284,7 +288,7 @@ ACL_CFG_PARSER *acl_cfg_parser_load(const char *pathname, const char *delimiter)
|
||||
cfg_line->line_number = parser->total_line;
|
||||
continue;
|
||||
} else if (*ptr == '\r' || *ptr == '\n') {
|
||||
/* 操作空行 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/* SKIP(ptr, (*ptr == '\r' || *ptr == '\n')); */
|
||||
if (*ptr == '\r' && *(ptr + 1) == '\n') {
|
||||
*ptr = 0; /* set '\0' first and go on */
|
||||
@ -308,7 +312,7 @@ ACL_CFG_PARSER *acl_cfg_parser_load(const char *pathname, const char *delimiter)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 操作有效行 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD> */
|
||||
pline_begin = ptr; /* reset the line header */
|
||||
|
||||
/* find the line's end */
|
||||
@ -351,7 +355,7 @@ ACL_CFG_PARSER *acl_cfg_parser_load(const char *pathname, const char *delimiter)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 释放 ACL_CFG_LINE 项所用的回调函数 */
|
||||
/* <EFBFBD>ͷ<EFBFBD> ACL_CFG_LINE <20><><EFBFBD><EFBFBD><EFBFBD>õĻص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
|
||||
static void _cfg_line_free(void *arg)
|
||||
{
|
||||
ACL_CFG_LINE *cfg_line;
|
||||
@ -561,9 +565,14 @@ int acl_cfg_parser_dump(const ACL_CFG_PARSER *parser,
|
||||
if (parser == NULL || pathname == NULL || *pathname == 0)
|
||||
return (-1);
|
||||
#ifdef ACL_UNIX
|
||||
# ifdef ACL_ARM_LINUX
|
||||
filefd = acl_file_open(pathname,
|
||||
O_CREAT | O_TRUNC | O_APPEND | O_WRONLY, 0644);
|
||||
# else
|
||||
filefd = acl_file_open(pathname,
|
||||
O_CREAT | O_TRUNC | O_APPEND | O_WRONLY,
|
||||
S_IREAD | S_IWRITE | S_IRGRP);
|
||||
# endif
|
||||
#elif defined(ACL_WINDOWS)
|
||||
filefd = acl_file_open(pathname,
|
||||
O_CREAT | O_TRUNC | O_APPEND | O_WRONLY,
|
||||
|
@ -34,6 +34,15 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef ACL_ARM_LINUX
|
||||
int acl_open_limit(int limit)
|
||||
{
|
||||
/* xxx: just limit to 1024 */
|
||||
if (limit <= 0 || limit > 1024)
|
||||
return 1024;
|
||||
return limit;
|
||||
}
|
||||
#else
|
||||
int acl_open_limit(int limit)
|
||||
{
|
||||
const char *myname = "acl_open_limit";
|
||||
@ -90,5 +99,6 @@ int acl_open_limit(int limit)
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* end ACL_UNIX */
|
||||
#endif /* !ACL_ARM_LINUX */
|
||||
#endif /* !ACL_UNIX */
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#ifdef ACL_WINDOWS
|
||||
|
||||
/*-------------------- ACL_WINDOWS 下模拟实现 Posix 标准接口函数 ----------------*/
|
||||
/*-------------------- ACL_WINDOWS <EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD> Posix <20><><EFBFBD>ӿں<D3BF><DABA><EFBFBD> ----------------*/
|
||||
|
||||
#include <process.h>
|
||||
|
||||
@ -69,7 +69,7 @@ void acl_pthread_end(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* 每个进程的唯一初始化函数 */
|
||||
/* ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD>Ψһ<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
static void acl_pthread_init_once(void)
|
||||
{
|
||||
@ -100,7 +100,7 @@ static void acl_pthread_init_once(void)
|
||||
__tls_key_list[__tls_value_list_key].key = __tls_value_list_key;
|
||||
}
|
||||
|
||||
/* 获得线程局部变量链表 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ߳̾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
static ACL_FIFO *tls_value_list_get(void)
|
||||
{
|
||||
@ -141,7 +141,7 @@ static DWORD WINAPI RunThreadWrap(LPVOID data)
|
||||
ACL_FIFO *tls_value_list_ptr = tls_value_list_get();
|
||||
unsigned long *tid = 0;
|
||||
|
||||
/* 只是为了避免与主线程的 h_thread->handle = handle 产生冲突 */
|
||||
/* ֻ<EFBFBD><EFBFBD>Ϊ<EFBFBD>˱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵߳<EFBFBD> h_thread->handle = handle <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ */
|
||||
if (__thread_inited)
|
||||
acl_pthread_mutex_lock(&__thread_lock);
|
||||
if (__thread_inited)
|
||||
@ -151,7 +151,7 @@ static DWORD WINAPI RunThreadWrap(LPVOID data)
|
||||
|
||||
return_arg = (void*) thread->start_routine(thread->routine_arg);
|
||||
|
||||
/* 释放由 acl_pthread_setspecific 添加的线程局部变量 */
|
||||
/* <EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD> acl_pthread_setspecific <20><>ӵ<EFBFBD><D3B5>ֲ߳̾<CCBE><D6B2><EFBFBD><EFBFBD><EFBFBD> */
|
||||
while (1) {
|
||||
TLS_VALUE *tls_value = private_fifo_pop(tls_value_list_ptr);
|
||||
|
||||
@ -172,7 +172,7 @@ static DWORD WINAPI RunThreadWrap(LPVOID data)
|
||||
|
||||
private_fifo_free(tls_value_list_ptr, NULL);
|
||||
|
||||
/* 如果线程创建时为分离方式则需要关闭线程句柄 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>̴߳<EFBFBD><EFBFBD><EFBFBD>ʱΪ<EFBFBD><EFBFBD><EFBFBD>뷽ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ر<EFBFBD><EFBFBD>߳̾<EFBFBD><EFBFBD> */
|
||||
if (thread->detached) {
|
||||
if (!CloseHandle(thread->handle)) {
|
||||
acl_msg_error("close handle error(%s)",
|
||||
@ -253,7 +253,7 @@ int acl_pthread_create(acl_pthread_t *thread, acl_pthread_attr_t *attr,
|
||||
thread->id = id;
|
||||
thread->handle = 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>ģʽ */
|
||||
|
||||
if (attr == NULL || attr->detached) {
|
||||
thread->detached = 1;
|
||||
@ -275,16 +275,16 @@ int acl_pthread_once(acl_pthread_once_t *once_control,
|
||||
return ACL_EINVAL;
|
||||
}
|
||||
|
||||
/* 只有第一个调用 InterlockedCompareExchange 的线程才会执行
|
||||
* init_routine, 后续线程永远在 InterlockedCompareExchange
|
||||
* 外运行,并且一直进入空循环直至第一个线程执行 init_routine
|
||||
* 完毕并且将 *once_control 重新赋值, 只有在多核环境中多个线程
|
||||
* 同时运行至此时才有可能出现短暂的后续线程空循环现象,如果
|
||||
* 多个线程顺序至此,则因为 *once_control 已经被第一个线程重新
|
||||
* 赋值而不会进入循环体内只所以如此处理,是为了保证所有线程在
|
||||
* 调用 acl_pthread_once 返回前 init_routine 必须被调用且仅能
|
||||
* 被调用一次, 但在VC6下,InterlockedCompareExchange 接口定义
|
||||
* 有些怪异,需要做硬性指定参数类型,参见 <Windows 高级编程指南>
|
||||
/* ֻ<EFBFBD>е<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> InterlockedCompareExchange <20><><EFBFBD>̲߳Ż<CCB2>ִ<EFBFBD><D6B4>
|
||||
* init_routine, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD> InterlockedCompareExchange
|
||||
* <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> init_routine
|
||||
* <EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD>ҽ<EFBFBD> *once_control <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><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ *once_control <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><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> acl_pthread_once <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ init_routine <EFBFBD><EFBFBD><EFBFBD>뱻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><EFBFBD><EFBFBD>
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>VC6<EFBFBD>£<EFBFBD>InterlockedCompareExchange <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> <Windows <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>>
|
||||
* Jeffrey Richter, 366 ҳ
|
||||
*/
|
||||
while (1) {
|
||||
@ -298,21 +298,21 @@ int acl_pthread_once(acl_pthread_once_t *once_control,
|
||||
if (prev == 2)
|
||||
return 0;
|
||||
else if (prev == 0) {
|
||||
/* 只有第一个线程才会至此 */
|
||||
/* ֻ<EFBFBD>е<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>̲߳Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
init_routine();
|
||||
/* 将 *conce_control 重新赋值以使后续线程不进入 while
|
||||
* 循环或从 while 循环中跳出
|
||||
/* <EFBFBD><EFBFBD> *conce_control <20><><EFBFBD>¸<EFBFBD>ֵ<EFBFBD><D6B5>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>̲߳<DFB3><CCB2><EFBFBD><EFBFBD><EFBFBD> while
|
||||
* ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> while ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
InterlockedExchange(once_control, 2);
|
||||
return 0;
|
||||
} else {
|
||||
acl_assert(prev == 1);
|
||||
|
||||
/* 防止空循环过多地浪费CPU */
|
||||
/* <EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD>CPU */
|
||||
Sleep(1); /** sleep 1ms */
|
||||
}
|
||||
}
|
||||
return 1; /* 不可达代码,避免编译器报警告 */
|
||||
return 1; /* <EFBFBD><EFBFBD><EFBFBD>ɴ<EFBFBD><EFBFBD><EFBFBD>룬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
}
|
||||
|
||||
int acl_pthread_attr_init(acl_pthread_attr_t *thr_attr)
|
||||
@ -425,7 +425,7 @@ int acl_pthread_setspecific(acl_pthread_key_t key, void *value)
|
||||
if (tls_value->tls_key != NULL
|
||||
&& tls_value->tls_key->key == key)
|
||||
{
|
||||
/* 如果相同的键存在则需要先释放旧数据 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ͷž<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (tls_value->tls_key->destructor || tls_value->value)
|
||||
tls_value->tls_key->destructor(tls_value->value);
|
||||
tls_value->tls_key = NULL;
|
||||
@ -494,7 +494,7 @@ int acl_pthread_join(acl_pthread_t thread, void **thread_return)
|
||||
|
||||
#endif /* ACL_WINDOWS */
|
||||
|
||||
/*----------------- 跨平台的通用函数集,是 Posix 标准的扩展 ----------------*/
|
||||
/*----------------- <EFBFBD><EFBFBD>ƽ̨<EFBFBD><EFBFBD>ͨ<EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Posix <20><><EFBFBD><D7BC><EFBFBD><EFBFBD>չ ----------------*/
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
@ -636,7 +636,7 @@ int acl_pthread_tls_get_max(void)
|
||||
return acl_tls_ctx_max;
|
||||
}
|
||||
|
||||
/* 线程退出时调用此函数释放属于本线程的局部变量 */
|
||||
/* <EFBFBD>߳<EFBFBD><EFBFBD>˳<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><EFBFBD>̵߳ľֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
static void tls_ctx_free(void *ctx)
|
||||
{
|
||||
@ -651,7 +651,7 @@ static void tls_ctx_free(void *ctx)
|
||||
acl_default_free(__FILE__, __LINE__, tls_ctxes);
|
||||
}
|
||||
|
||||
/* 主线程退出时释放局部变量 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD>˳<EFBFBD>ʱ<EFBFBD>ͷžֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
static void main_tls_ctx_free(void)
|
||||
{
|
||||
@ -688,7 +688,7 @@ void *acl_pthread_tls_get(acl_pthread_key_t *key_ptr)
|
||||
}
|
||||
tls_ctxes = (TLS_CTX*) acl_pthread_getspecific(__tls_ctx_key);
|
||||
if (tls_ctxes == NULL) {
|
||||
/* 因为该线程中不存在该线程局部变量,所以需要分配一个新的 */
|
||||
/* <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> */
|
||||
tls_ctxes = (TLS_CTX*) acl_default_malloc(__FILE__, __LINE__,
|
||||
acl_tls_ctx_max * sizeof(TLS_CTX));
|
||||
if (acl_pthread_setspecific(__tls_ctx_key, tls_ctxes) != 0) {
|
||||
@ -698,7 +698,7 @@ void *acl_pthread_tls_get(acl_pthread_key_t *key_ptr)
|
||||
(unsigned long) acl_pthread_self());
|
||||
return NULL;
|
||||
}
|
||||
/* 初始化 */
|
||||
/* <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD> */
|
||||
for (i = 0; i < acl_tls_ctx_max; i++) {
|
||||
tls_ctxes[i].key = (acl_pthread_key_t) ACL_TLS_OUT_OF_INDEXES;
|
||||
tls_ctxes[i].ptr = NULL;
|
||||
@ -712,7 +712,7 @@ void *acl_pthread_tls_get(acl_pthread_key_t *key_ptr)
|
||||
}
|
||||
}
|
||||
|
||||
/* 如果该键已经存在则取出对应数据 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if ((int) (*key_ptr) >= 0 && (int) (*key_ptr) < acl_tls_ctx_max) {
|
||||
if (tls_ctxes[(int) (*key_ptr)].key == *key_ptr)
|
||||
return tls_ctxes[(int) (*key_ptr)].ptr;
|
||||
@ -728,13 +728,13 @@ void *acl_pthread_tls_get(acl_pthread_key_t *key_ptr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 找出一个空位 */
|
||||
/* <EFBFBD>ҳ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ */
|
||||
for (i = 0; i < acl_tls_ctx_max; i++) {
|
||||
if (tls_ctxes[i].key == (acl_pthread_key_t) ACL_TLS_OUT_OF_INDEXES)
|
||||
break;
|
||||
}
|
||||
|
||||
/* 如果没有空位可用则返回空并置错误标志位 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>п<EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؿղ<EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ */
|
||||
if (i == acl_tls_ctx_max) {
|
||||
acl_msg_error("%s(%d): no space for tls key", myname, __LINE__);
|
||||
*key_ptr = (acl_pthread_key_t) ACL_TLS_OUT_OF_INDEXES;
|
||||
@ -742,7 +742,7 @@ void *acl_pthread_tls_get(acl_pthread_key_t *key_ptr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 为新分配的键初始化线程局部数据对象 */
|
||||
/* Ϊ<EFBFBD>·<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ֲ߳̾<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><EFBFBD><EFBFBD> */
|
||||
tls_ctxes[i].key = (acl_pthread_key_t) i;
|
||||
tls_ctxes[i].free_fn = NULL;
|
||||
tls_ctxes[i].ptr = NULL;
|
||||
@ -781,7 +781,7 @@ int acl_pthread_tls_set(acl_pthread_key_t key, void *ptr,
|
||||
acl_set_error(ACL_EINVAL);
|
||||
return ACL_EINVAL;
|
||||
}
|
||||
/* 如果该键值存在旧数据则首先需要释放掉旧数据 */
|
||||
/* <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> */
|
||||
if (tls_ctxes[(int) key].ptr != NULL && tls_ctxes[(int) key].free_fn != NULL)
|
||||
tls_ctxes[(int) key].free_fn(tls_ctxes[(int) key].ptr);
|
||||
|
||||
@ -831,7 +831,7 @@ int acl_pthread_tls_del(acl_pthread_key_t key)
|
||||
|
||||
void acl_pthread_tls_once_get(acl_pthread_once_t *control_once)
|
||||
{
|
||||
memcpy(control_once, &__tls_ctx_control_once,
|
||||
memcpy((void *)control_once, (void *)&__tls_ctx_control_once,
|
||||
sizeof(acl_pthread_once_t));
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ private:
|
||||
#else
|
||||
int fHandle_;
|
||||
pthread_mutexattr_t mutex_attr_;
|
||||
# if !defined(MINGW) && !defined(MACOSX)
|
||||
# if !defined(MINGW) && !defined(MACOSX) && !defined(ACL_ARM_LINUX)
|
||||
pthread_spinlock_t* spinlock_;
|
||||
# endif
|
||||
#endif
|
||||
|
@ -1,6 +1,8 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
#set(CMAKE_BUILD_TYPE Release)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "set build type to release")
|
||||
|
||||
add_definitions("-g")
|
||||
#add_definitions("-g")
|
||||
add_definitions("-W")
|
||||
add_definitions("-O3")
|
||||
add_definitions("-Wall")
|
||||
@ -15,6 +17,12 @@ add_definitions("-Wuninitialized")
|
||||
add_definitions("-D_POSIX_PTHREAD_SEMANTICS")
|
||||
add_definitions("-DHAS_MYSQL_DLL")
|
||||
add_definitions("-DHAS_SQLITE_DLL")
|
||||
add_definitions("-Wno-invalid-source-encoding")
|
||||
add_definitions("-Wno-unused-private-field")
|
||||
add_definitions("-Wno-unused-parameter")
|
||||
add_definitions("-Wno-unused-const-variable")
|
||||
add_definitions("-fexceptions")
|
||||
add_definitions("-DACL_ARM_LINUX")
|
||||
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
add_definitions("-DLINUX2")
|
||||
@ -59,4 +67,9 @@ aux_source_directory(${src}/smtp lib_src)
|
||||
aux_source_directory(${src}/stdlib lib_src)
|
||||
aux_source_directory(${src}/stream lib_src)
|
||||
|
||||
add_library(_acl_cpp ${lib_src})
|
||||
set(lib_output_path ${PROJECT_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path})
|
||||
SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath,. -L${lib_output_path} -l_protocol -l_acl")
|
||||
add_library(_acl_cpp SHARED ${lib_src})
|
||||
link_directories(${PROJECT_BINARY_DIR}/lib)
|
||||
target_link_libraries(_acl_cpp _protocol _acl)
|
||||
|
@ -485,7 +485,8 @@ static acl_pthread_once_t __thread_once_control = ACL_PTHREAD_ONCE_INIT;
|
||||
|
||||
static void thread_once(void)
|
||||
{
|
||||
acl_assert(!acl_pthread_key_create(&__thread_key, thread_free_dummy));
|
||||
if (acl_pthread_key_create(&__thread_key, thread_free_dummy) != 0)
|
||||
abort();
|
||||
}
|
||||
|
||||
bool db_mysql::dbopen(const char* charset /* = NULL */)
|
||||
|
@ -685,7 +685,7 @@ void redis_command::logger_result(const redis_result* result)
|
||||
string res;
|
||||
result->to_string(res);
|
||||
|
||||
logger_error("result type: %d, error: %s, res: [%s], req: [%s]",
|
||||
logger_error("result type: %d, error: %s, res: [%s], req:[%s]",
|
||||
result->get_type(), result_error(), res.c_str(),
|
||||
request_buf_ ? request_buf_->c_str() : "slice request");
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "acl_stdafx.hpp"
|
||||
|
||||
#ifndef HAVE_H_ICONV
|
||||
#if !defined(HAVE_H_ICONV) && !defined(ACL_ARM_LINUX)
|
||||
# define HAVE_H_ICONV
|
||||
#endif
|
||||
|
||||
|
@ -43,15 +43,15 @@ ACL_FIBER *acl_fiber_running(void);
|
||||
/**
|
||||
* 获得所给协程的协程 ID 号
|
||||
* @param fiber {const ACL_FIBER*} acl_fiber_create 创建的协程对象,必须非空
|
||||
* @return {int} 协程 ID 号
|
||||
* @return {unsigned int} 协程 ID 号
|
||||
*/
|
||||
int acl_fiber_id(const ACL_FIBER *fiber);
|
||||
unsigned int acl_fiber_id(const ACL_FIBER *fiber);
|
||||
|
||||
/**
|
||||
* 获得当前所运行的协程的 ID 号
|
||||
* @return {int} 当前运行协程的 ID 号
|
||||
* @return {unsigned int} 当前运行协程的 ID 号
|
||||
*/
|
||||
int acl_fiber_self(void);
|
||||
unsigned int acl_fiber_self(void);
|
||||
|
||||
/**
|
||||
* 设置所给协程的错误号
|
||||
|
@ -22,13 +22,13 @@ typedef struct {
|
||||
ACL_RING ready; /* ready fiber queue */
|
||||
ACL_RING dead; /* dead fiber queue */
|
||||
ACL_FIBER **fibers;
|
||||
size_t size;
|
||||
size_t slot;
|
||||
unsigned size;
|
||||
unsigned slot;
|
||||
int exitcode;
|
||||
ACL_FIBER *running;
|
||||
ACL_FIBER original;
|
||||
int errnum;
|
||||
size_t idgen;
|
||||
unsigned idgen;
|
||||
int count;
|
||||
int switched;
|
||||
int nlocal;
|
||||
@ -543,7 +543,10 @@ static ACL_FIBER *fiber_alloc(void (*fn)(ACL_FIBER *, void *),
|
||||
fiber->fn = fn;
|
||||
fiber->arg = arg;
|
||||
fiber->size = size;
|
||||
fiber->id = ++__thread_fiber->idgen;
|
||||
__thread_fiber->idgen++;
|
||||
if (__thread_fiber->idgen == 0) /* overflow ? */
|
||||
__thread_fiber->idgen++;
|
||||
fiber->id = __thread_fiber->idgen;
|
||||
fiber->flag = 0;
|
||||
fiber->status = FIBER_STATUS_READY;
|
||||
|
||||
@ -601,12 +604,12 @@ ACL_FIBER *acl_fiber_create(void (*fn)(ACL_FIBER *, void *),
|
||||
return fiber;
|
||||
}
|
||||
|
||||
int acl_fiber_id(const ACL_FIBER *fiber)
|
||||
unsigned int acl_fiber_id(const ACL_FIBER *fiber)
|
||||
{
|
||||
return fiber ? fiber->id : 0;
|
||||
}
|
||||
|
||||
int acl_fiber_self(void)
|
||||
unsigned int acl_fiber_self(void)
|
||||
{
|
||||
ACL_FIBER *curr = acl_fiber_running();
|
||||
return acl_fiber_id(curr);
|
||||
@ -777,13 +780,10 @@ void *acl_fiber_get_specific(int key)
|
||||
} else
|
||||
curr = __thread_fiber->running;
|
||||
|
||||
if (key > curr->nlocal) {
|
||||
acl_msg_error("%s(%d), %s: invalid key: %d > nlocal: %d",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
key, curr->nlocal);
|
||||
if (key > curr->nlocal)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
local = curr->locals[key - 1];
|
||||
|
||||
return local ? local->ctx : NULL;
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ struct ACL_FIBER {
|
||||
#endif
|
||||
fiber_status_t status;
|
||||
ACL_RING me;
|
||||
size_t id;
|
||||
size_t slot;
|
||||
unsigned id;
|
||||
unsigned slot;
|
||||
acl_int64 when;
|
||||
int errnum;
|
||||
int sys;
|
||||
|
@ -43,7 +43,7 @@ static int __lock(ACL_FIBER_MUTEX *lk, int block)
|
||||
return 1;
|
||||
|
||||
if (acl_fiber_killed(curr))
|
||||
acl_msg_info("%s(%d), %s: lock fiber-%d was killed",
|
||||
acl_msg_info("%s(%d), %s: lock fiber-%u was killed",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(curr));
|
||||
else
|
||||
acl_msg_warn("%s(%d), %s: qlock: owner=%p self=%p oops",
|
||||
|
@ -298,7 +298,7 @@ inline ssize_t fiber_read(int fd, void *buf, size_t count)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me));
|
||||
|
||||
return ret;
|
||||
@ -344,7 +344,7 @@ inline ssize_t fiber_readv(int fd, const struct iovec *iov, int iovcnt)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me));
|
||||
|
||||
return ret;
|
||||
@ -391,7 +391,7 @@ inline ssize_t fiber_recv(int sockfd, void *buf, size_t len, int flags)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me));
|
||||
|
||||
return ret;
|
||||
@ -440,7 +440,7 @@ inline ssize_t fiber_recvfrom(int sockfd, void *buf, size_t len, int flags,
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me));
|
||||
return -1;
|
||||
}
|
||||
@ -488,7 +488,7 @@ inline ssize_t fiber_recvmsg(int sockfd, struct msghdr *msg, int flags)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me));
|
||||
|
||||
return ret;
|
||||
@ -524,7 +524,7 @@ inline ssize_t fiber_read(int fd, void *buf, size_t count)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
}
|
||||
@ -559,7 +559,7 @@ inline ssize_t fiber_readv(int fd, const struct iovec *iov, int iovcnt)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
}
|
||||
@ -594,7 +594,7 @@ inline ssize_t fiber_recv(int sockfd, void *buf, size_t len, int flags)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
}
|
||||
@ -631,7 +631,7 @@ inline ssize_t fiber_recvfrom(int sockfd, void *buf, size_t len, int flags,
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
}
|
||||
@ -666,7 +666,7 @@ inline ssize_t fiber_recvmsg(int sockfd, struct msghdr *msg, int flags)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me))
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
}
|
||||
@ -705,7 +705,7 @@ inline ssize_t fiber_write(int fd, const void *buf, size_t count)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
return -1;
|
||||
@ -742,7 +742,7 @@ inline ssize_t fiber_writev(int fd, const struct iovec *iov, int iovcnt)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
return -1;
|
||||
@ -779,7 +779,7 @@ inline ssize_t fiber_send(int sockfd, const void *buf, size_t len, int flags)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
return -1;
|
||||
@ -818,7 +818,7 @@ inline ssize_t fiber_sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
return -1;
|
||||
@ -855,7 +855,7 @@ inline ssize_t fiber_sendmsg(int sockfd, const struct msghdr *msg, int flags)
|
||||
|
||||
me = acl_fiber_running();
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d is existing",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u is existing",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(me));
|
||||
return -1;
|
||||
|
@ -209,7 +209,7 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
||||
event_clear_readable(ev, sockfd);
|
||||
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d was killed",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u was killed",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me));
|
||||
return -1;
|
||||
}
|
||||
@ -242,7 +242,7 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
||||
event_clear_readable(ev, sockfd);
|
||||
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d was killed",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u was killed",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me));
|
||||
return -1;
|
||||
}
|
||||
@ -321,7 +321,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
|
||||
fiber_wait_write(sockfd);
|
||||
|
||||
if (acl_fiber_killed(me)) {
|
||||
acl_msg_info("%s(%d), %s: fiber-%d was killed",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u was killed",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me));
|
||||
return -1;
|
||||
}
|
||||
@ -449,7 +449,7 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
|
||||
if (acl_fiber_killed(pe.fiber)) {
|
||||
acl_ring_detach(&pe.me);
|
||||
acl_msg_info("%s(%d), %s: fiber-%d was killed",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u was killed",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(pe.fiber));
|
||||
break;
|
||||
@ -891,7 +891,7 @@ int epoll_wait(int epfd, struct epoll_event *events,
|
||||
|
||||
if (acl_fiber_killed(ee->fiber)) {
|
||||
acl_ring_detach(&ee->me);
|
||||
acl_msg_info("%s(%d), %s: fiber-%d was killed",
|
||||
acl_msg_info("%s(%d), %s: fiber-%u was killed",
|
||||
__FILE__, __LINE__, __FUNCTION__,
|
||||
acl_fiber_id(ee->fiber));
|
||||
break;
|
||||
|
@ -79,7 +79,7 @@ static unsigned __nused = 0;
|
||||
|
||||
static void server_exit(ACL_FIBER *fiber, int status)
|
||||
{
|
||||
acl_msg_info("%s(%d), %s: fiber = %d, service exit now!",
|
||||
acl_msg_info("%s(%d), %s: fiber = %u, service exit now!",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(fiber));
|
||||
exit(status);
|
||||
}
|
||||
@ -346,7 +346,7 @@ static void fiber_dispatch(ACL_FIBER *fiber, void *ctx)
|
||||
acl_vstream_close(conn);
|
||||
}
|
||||
|
||||
acl_msg_info("%s(%d), %s: fiber-%d exit now", __FILE__, __LINE__,
|
||||
acl_msg_info("%s(%d), %s: fiber-%u exit now", __FILE__, __LINE__,
|
||||
__FUNCTION__, acl_fiber_id(fiber));
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ static unsigned __nused = 0;
|
||||
|
||||
static void server_exit(ACL_FIBER *fiber, int status)
|
||||
{
|
||||
acl_msg_info("%s(%d), %s: fiber = %d, service exit now!",
|
||||
acl_msg_info("%s(%d), %s: fiber = %u, service exit now!",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_fiber_id(fiber));
|
||||
exit (status);
|
||||
}
|
||||
@ -301,7 +301,7 @@ static void fiber_dispatch(ACL_FIBER *fiber, void *ctx acl_unused)
|
||||
acl_vstream_close(conn);
|
||||
}
|
||||
|
||||
acl_msg_info("%s(%d), %s: fiber-%d exit now", __FILE__, __LINE__,
|
||||
acl_msg_info("%s(%d), %s: fiber-%u exit now", __FILE__, __LINE__,
|
||||
__FUNCTION__, acl_fiber_id(fiber));
|
||||
}
|
||||
|
||||
@ -339,7 +339,7 @@ static void fiber_accept_main(ACL_FIBER *fiber, void *ctx)
|
||||
server_abort(acl_fiber_running());
|
||||
}
|
||||
|
||||
acl_msg_info("%s(%d), %s: fiber-%d exit now", __FILE__, __LINE__,
|
||||
acl_msg_info("%s(%d), %s: fiber-%u exit now", __FILE__, __LINE__,
|
||||
__FUNCTION__, acl_fiber_id(fiber));
|
||||
acl_vstream_close(sstream);
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
40) 2017.1.23
|
||||
40.1) workaround: 协程号统一改成无符号 32 位整数
|
||||
|
||||
39) 2017.1.12
|
||||
39.1) bugfix: 协程在双通模式下,如果写时堵塞会导致读也堵塞,是因为延迟关闭
|
||||
及事件设置不合理
|
||||
|
@ -52,14 +52,15 @@ public:
|
||||
|
||||
/**
|
||||
* 获得本协程对象的 ID 号
|
||||
* @return {int}
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
int get_id(void) const;
|
||||
unsigned int get_id(void) const;
|
||||
|
||||
/**
|
||||
* 获得当前运行的协程对象的 ID 号
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
static int self(void);
|
||||
static unsigned int self(void);
|
||||
|
||||
/**
|
||||
* 获得当前协程在执行某个系统 API 出错时的错误号
|
||||
|
@ -20,12 +20,12 @@ fiber::~fiber(void)
|
||||
{
|
||||
}
|
||||
|
||||
int fiber::get_id(void) const
|
||||
unsigned int fiber::get_id(void) const
|
||||
{
|
||||
return f_ ? acl_fiber_id(f_) : -1;
|
||||
return f_ ? acl_fiber_id(f_) : 0;
|
||||
}
|
||||
|
||||
int fiber::self(void)
|
||||
unsigned int fiber::self(void)
|
||||
{
|
||||
return acl_fiber_self();
|
||||
}
|
||||
@ -78,7 +78,7 @@ void fiber::run(void)
|
||||
void fiber::start(size_t stack_size /* = 64000 */)
|
||||
{
|
||||
if (f_ != NULL)
|
||||
acl_msg_fatal("%s(%d), %s: fiber-%d, already running!",
|
||||
acl_msg_fatal("%s(%d), %s: fiber-%u, already running!",
|
||||
__FILE__, __LINE__, __FUNCTION__, self());
|
||||
|
||||
acl_fiber_create(fiber_callback, this, stack_size);
|
||||
|
@ -1,6 +1,8 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
#set(CMAKE_BUILD_TYPE Release)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "set build type to release")
|
||||
|
||||
add_definitions("-g")
|
||||
#add_definitions("-g")
|
||||
add_definitions("-W")
|
||||
add_definitions("-O3")
|
||||
add_definitions("-Wall")
|
||||
@ -14,6 +16,7 @@ add_definitions("-D_USE_FAST_MACRO")
|
||||
add_definitions("-Wno-long-long")
|
||||
add_definitions("-Wuninitialized")
|
||||
add_definitions("-D_POSIX_PTHREAD_SEMANTICS")
|
||||
add_definitions("-DACL_ARM_LINUX")
|
||||
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
add_definitions("-DLINUX2")
|
||||
@ -35,4 +38,12 @@ aux_source_directory(${src}/http lib_src)
|
||||
aux_source_directory(${src}/smtp lib_src)
|
||||
aux_source_directory(${src}/icmp lib_src)
|
||||
|
||||
add_library(_protocol ${lib_src})
|
||||
#add_library(_protocol ${lib_src})
|
||||
set(lib_output_path ${PROJECT_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path})
|
||||
#SET(CMAKE_SKIP_BUILD_RPATH FALSE)
|
||||
#set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
||||
SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath,. -L${lib_output_path} -l_acl")
|
||||
add_library(_protocol SHARED ${lib_src})
|
||||
link_directories(${PROJECT_BINARY_DIR}/lib)
|
||||
target_link_libraries(_protocol _acl)
|
||||
|
Loading…
Reference in New Issue
Block a user