Skip to content

Commit

Permalink
fixed some bugs, add some samples, and release 3.1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ubuntu14 committed Dec 29, 2015
1 parent 256d4cf commit c700540
Show file tree
Hide file tree
Showing 20 changed files with 505 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ endif
##############################################################################

.PHONY = check help all_lib all samples all clean install uninstall uninstall_all build_bin build_src build_one
VERSION = 3.1.4
VERSION = 3.1.4.3

help:
@(echo "usage: make help|all|all_lib|all_samples|clean|install|uninstall|uninstall_all|build_bin|build_src|build_one")
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
�޸���ʷ�б���
------------------------------------------------------------------------
93) 2015.12.29 --- acl 3.1.4.3 �汾������(�޸��˼������� BUG)
92) 2015.12.21 --- acl 3.1.4.2 �汾������(�޸���һ������ BUG)
91) 2015.12.21 --- acl 3.1.4.1 �汾������(�޸��˼������� BUG)
90) 2015.12.20 --- acl 3.1.4 �汾������
Expand Down
11 changes: 11 additions & 0 deletions lib_acl/changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
�޸���ʷ�б���

------------------------------------------------------------------------
523) 2015.12.28
523.1) acl_read_wait.c �еĺ��� acl_read_wait �� 32 λ�ĵͰ汾 LINUX ƽ̨��
ʹ�� epoll ����ģ�����ʱ���������⣬���Ը��� poll ������ʵ�ֶ���ʱ����

522) 2015.12.24
522.1) bugfix: �޸��� valgrind ������ acl_xml_parse.c �к��� cdata_prepare
����ָ��Ƿ���������

521) 2015.12.23
521.1) bugfix: acl_xml_parse.c/acl_xml2_parse.c ������һ���յ� CDATA ʱ������

520) 2015.12.21
520.1) bugfix: master_sig.c ���ڶ�����ʱӦ��ʹ�� acl_vstream_read��������
����ϵͳ API read��������γ���ѭ��
Expand Down
2 changes: 1 addition & 1 deletion lib_acl/src/init/acl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "init.h"

static char *version = "acl_3.1.4.2";
static char *version = "acl_3.1.4.3";

const char *acl_version(void)
{
Expand Down
108 changes: 74 additions & 34 deletions lib_acl/src/stdlib/iostuff/acl_read_wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,81 +22,119 @@
#include "stdlib/acl_iostuff.h"
#include "../../init/init.h"

#if defined(LINUX2) && !defined(MINGW)
#if defined(LINUX2) && !defined(MINGW) && defined(USE_EPOLL)

#include "init/acl_init.h"
#include "thread/acl_pthread.h"
#include <sys/epoll.h>

static int *main_epoll_read_fd = NULL;
typedef struct EPOLL_CTX
{
acl_pthread_t tid;
int epfd;
} EPOLL_CTX;

static EPOLL_CTX *main_epoll_ctx = NULL;

static void main_epoll_end(void)
{
if (main_epoll_read_fd != NULL) {
close(*main_epoll_read_fd);
acl_myfree(main_epoll_read_fd);
const char *myname = "main_epoll_end";

if (main_epoll_ctx != NULL) {
acl_msg_info("%s(%d), %s: close epoll_fd: %d, tid: %lu, %lu",
__FILE__, __LINE__, myname, main_epoll_ctx->epfd,
main_epoll_ctx->tid, acl_pthread_self());

close(main_epoll_ctx->epfd);
acl_myfree(main_epoll_ctx);
main_epoll_ctx = NULL;
}
}

static acl_pthread_key_t epoll_key;
static acl_pthread_once_t epoll_once = ACL_PTHREAD_ONCE_INIT;

static void thread_epoll_end(void *buf)
static void thread_epoll_end(void *ctx)
{
int *epoll_fd = (int*) buf;
const char *myname = "thread_epoll_end";
EPOLL_CTX *epoll_ctx = (EPOLL_CTX*) ctx;

close(*epoll_fd);
acl_myfree(epoll_fd);
acl_msg_info("%s(%d), %s: close epoll_fd: %d, tid: %lu, %lu",
__FILE__, __LINE__, myname, epoll_ctx->epfd,
epoll_ctx->tid, acl_pthread_self());

close(epoll_ctx->epfd);
acl_myfree(epoll_ctx);
}

static void thread_epoll_init(void)
static void thread_epoll_once(void)
{
acl_assert(acl_pthread_key_create(&epoll_key, thread_epoll_end) == 0);
}

static EPOLL_CTX *thread_epoll_init(void)
{
const char *myname = "thread_epoll_init";
EPOLL_CTX *epoll_ctx = (EPOLL_CTX*) acl_mymalloc(sizeof(EPOLL_CTX));

acl_assert(acl_pthread_setspecific(epoll_key, epoll_ctx) == 0);

epoll_ctx->tid = acl_pthread_self();
epoll_ctx->epfd = epoll_create(1);

if (acl_pthread_self() == acl_main_thread_self()) {
main_epoll_ctx = epoll_ctx;
atexit(main_epoll_end);
acl_msg_info("%s(%d): %s, create epoll_fd: %d, tid: %lu, %lu",
__FILE__, __LINE__, myname, epoll_ctx->epfd,
epoll_ctx->tid, acl_pthread_self());
} else {
acl_msg_info("%s(%d): %s, create epoll_fd: %d, tid: %lu, %lu",
__FILE__, __LINE__, myname, epoll_ctx->epfd,
epoll_ctx->tid, acl_pthread_self());
}

return epoll_ctx;
}

int acl_read_wait(ACL_SOCKET fd, int timeout)
{
const char *myname = "acl_read_wait";
int op = EPOLL_CTL_ADD, delay = timeout * 1000, *epoll_fd, ret;
int delay = timeout * 1000, ret;
EPOLL_CTX *epoll_ctx;
struct epoll_event ee, events[1];

acl_assert(acl_pthread_once(&epoll_once, thread_epoll_init) == 0);
epoll_fd = (int*) acl_pthread_getspecific(epoll_key);
if (epoll_fd == NULL) {
epoll_fd = (int*) acl_mymalloc(sizeof(int));
acl_assert(acl_pthread_setspecific(epoll_key, epoll_fd) == 0);
if ((unsigned long) acl_pthread_self()
== acl_main_thread_self())
{
main_epoll_read_fd = epoll_fd;
atexit(main_epoll_end);
}

*epoll_fd = epoll_create(1);
}
acl_assert(acl_pthread_once(&epoll_once, thread_epoll_once) == 0);
epoll_ctx = (EPOLL_CTX*) acl_pthread_getspecific(epoll_key);
if (epoll_ctx == NULL)
epoll_ctx = thread_epoll_init();

ee.events = EPOLLIN | EPOLLHUP | EPOLLERR;
ee.data.u64 = 0;
ee.data.fd = fd;
if (epoll_ctl(*epoll_fd, op, fd, &ee) == -1
if (epoll_ctl(epoll_ctx->epfd, EPOLL_CTL_ADD, fd, &ee) == -1
&& acl_last_error() != EEXIST)
{
acl_msg_error("%s(%d): epoll_ctl error: %s, fd: %d",
myname, __LINE__, acl_last_serror(), fd);
acl_msg_error("%s(%d): epoll_ctl error: %s, fd: %d, epfd: %d,"
" tid: %lu, %lu", myname, __LINE__, acl_last_serror(),
fd, epoll_ctx->epfd, epoll_ctx->tid,
acl_pthread_self());
return -1;
}

for (;;) {
ret = epoll_wait(*epoll_fd, events, 1, delay);
ret = epoll_wait(epoll_ctx->epfd, events, 1, delay);

if (ret == -1) {
if (acl_last_error() == ACL_EINTR) {
acl_msg_warn(">>>>catch EINTR, try again<<<");
continue;
}

acl_msg_error("%s(%d): epoll_wait error: %s, fd: %d",
myname, __LINE__, acl_last_serror(), fd);
acl_msg_error("%s(%d): epoll_wait error: %s, fd: %d,"
" epfd: %d, tid: %lu, %lu", myname, __LINE__,
acl_last_serror(), fd, epoll_ctx->epfd,
epoll_ctx->tid, acl_pthread_self());
ret = -1;
break;
} else if (ret == 0) {
Expand All @@ -118,9 +156,11 @@ int acl_read_wait(ACL_SOCKET fd, int timeout)
ee.events = 0;
ee.data.u64 = 0;
ee.data.fd = fd;
if (epoll_ctl(*epoll_fd, EPOLL_CTL_DEL, fd, &ee) == -1) {
acl_msg_error("%s(%d): epoll_ctl error: %s, fd: %d",
myname, __LINE__, acl_last_serror(), fd);
if (epoll_ctl(epoll_ctx->epfd, EPOLL_CTL_DEL, fd, &ee) == -1) {
acl_msg_error("%s(%d): epoll_ctl error: %s, fd: %d, epfd: %d,"
" tid: %lu, %lu", myname, __LINE__, acl_last_serror(),
fd, epoll_ctx->epfd, epoll_ctx->tid,
acl_pthread_self());
return -1;
}

Expand Down
44 changes: 36 additions & 8 deletions lib_acl/src/xml/acl_xml2_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,8 @@ static const char *xml_parse_cdata(ACL_XML2 *xml, const char *data)
*xml->ptr = 0;
return data;
}
#define IS_CDATA(x) (*(x) == '[' \
&& (*(x + 1) == 'C' || *(x + 1) == 'c') \
&& (*(x + 2) == 'D' || *(x + 2) == 'd') \
&& (*(x + 3) == 'A' || *(x + 3) == 'a') \
&& (*(x + 4) == 'T' || *(x + 4) == 't') \
&& (*(x + 5) == 'A' || *(x + 5) == 't') \
&& *(x + 6) == '[')

static void cdata_prepare(ACL_XML2 *xml, int last_ch)
static void cdata_prepare(ACL_XML2 *xml)
{
size_t cdata_len = sizeof("[CDATA[") - 1, len, max, i;
ACL_XML2_NODE *curr_node = xml->curr_node;
Expand Down Expand Up @@ -252,12 +245,23 @@ static void cdata_prepare(ACL_XML2 *xml, int last_ch)
curr_node->ltag_size = cdata_len;
curr_node->ltag[curr_node->ltag_size] = 0;

#if 0
if (xml->len < MIN_LEN)
return;
*xml->ptr++ = last_ch;
xml->len--;
#endif
}

#define CDATA_SIZE (sizeof("[CDATA[") - 1)
#define IS_CDATA(x) (*(x) == '[' \
&& (*(x + 1) == 'C' || *(x + 1) == 'c') \
&& (*(x + 2) == 'D' || *(x + 2) == 'd') \
&& (*(x + 3) == 'A' || *(x + 3) == 'a') \
&& (*(x + 4) == 'T' || *(x + 4) == 't') \
&& (*(x + 5) == 'A' || *(x + 5) == 't') \
&& *(x + 6) == '[')

static const char *xml_parse_meta_tag(ACL_XML2 *xml, const char *data)
{
int ch;
Expand All @@ -269,6 +273,7 @@ static const char *xml_parse_meta_tag(ACL_XML2 *xml, const char *data)
xml->curr_node->ltag = xml->ptr;

while ((ch = *data) != 0) {
#if 0
if (IS_SPACE(ch) || ch == '>') {
if (xml->len < MIN_LEN)
return data;
Expand All @@ -289,6 +294,29 @@ static const char *xml_parse_meta_tag(ACL_XML2 *xml, const char *data)
}
break;
}
#else

if (xml->ptr - xml->curr_node->ltag >= (ssize_t) CDATA_SIZE
&& IS_CDATA(xml->curr_node->ltag))
{
xml->curr_node->ltag_size =
xml->ptr - xml->curr_node->ltag;
cdata_prepare(xml);
xml->curr_node->status = ACL_XML2_S_CDATA;
xml->curr_node->flag |= ACL_XML2_F_CDATA;
break;
} else if (IS_SPACE(ch) || ch == '>') {
xml->curr_node->ltag_size =
xml->ptr - xml->curr_node->ltag;
if (xml->len < MIN_LEN)
return data;
data++;
*xml->ptr++ = 0;
xml->len--;
xml->curr_node->status = ACL_XML2_S_MTXT;
break;
}
#endif

if (xml->len < MIN_LEN)
return data;
Expand Down
30 changes: 26 additions & 4 deletions lib_acl/src/xml/acl_xml_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,17 @@ static const char *xml_parse_cdata(ACL_XML *xml, const char *data)
&& (*(x + 5) == 'A' || *(x + 5) == 't') \
&& *(x + 6) == '[')

#define CDATA_S sizeof("[CDATA[") - 1

static void cdata_prepare(ACL_XML_NODE *curr_node)
{
char *ptr = STR(curr_node->ltag) + sizeof("[CDATA[") - 1;
char *ptr;

ACL_VSTRING_TERMINATE(curr_node->ltag);
ptr = STR(curr_node->ltag) + sizeof("[CDATA[") - 1;

acl_vstring_strcpy(curr_node->text, ptr);
if (*ptr)
acl_vstring_strcpy(curr_node->text, ptr);
ACL_VSTRING_AT_OFFSET(curr_node->ltag, sizeof("[CDATA[") - 1);
ACL_VSTRING_TERMINATE(curr_node->ltag);
}
Expand All @@ -197,8 +203,8 @@ static const char *xml_parse_meta_tag(ACL_XML *xml, const char *data)
int ch;

while ((ch = *data) != 0) {
data++;
if (IS_SPACE(ch) || ch == '>') {
#if 0
if (IS_SPACE(ch) || ch == '>' || ch == ']') {
if (IS_CDATA(STR(xml->curr_node->ltag))) {
cdata_prepare(xml->curr_node);
ADDCH(xml->curr_node->text, ch);
Expand All @@ -208,6 +214,22 @@ static const char *xml_parse_meta_tag(ACL_XML *xml, const char *data)
xml->curr_node->status = ACL_XML_S_MTXT;
break;
}
#else
if (LEN(xml->curr_node->ltag) >= CDATA_S
&& IS_CDATA(STR(xml->curr_node->ltag)))
{
cdata_prepare(xml->curr_node);
xml->curr_node->status = ACL_XML_S_CDATA;
xml->curr_node->flag |= ACL_XML_F_CDATA;
break;
} else if (IS_SPACE(ch) || ch == '>') {
xml->curr_node->status = ACL_XML_S_MTXT;
data++;
break;
}
#endif
data++;

ADDCH(xml->curr_node->ltag, ch);
}

Expand Down
20 changes: 20 additions & 0 deletions lib_acl_cpp/changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
�޸���ʷ�б���

-----------------------------------------------------------------------
393) 2015.12.28
393.1) bugfix: �� xml1, xml2 �еĺ��� getFirstElementByTag �ڲ�û���ж� NULL
393.2) bugfix: ȡ���� http_request ���е� acl_assert(client_) �����ж�

392.1) 2015.12.25
392.1) bugfix: dbuf_guard ��Ӧ��ֹ���ÿ����������ڵ��� create �IJ����������
dbuf_guard ������Ϊ�����������⣬�磺
class myobj : public acl::dbuf_obj
{
public:
myobj(acl::dbuf_guard& dbuf) : dbuf_(dbuf) {}
~myobj(void) {}
};

acl::dbuf_guard dbuf;
myobj* obj = dbuf.create<myobj, acl::dbuf_guard>(dbuf);

��Ȼ myobj ���캯������һ�����ã�����Ȼ���� create ʱ�γ����ÿ����������Ӷ�
����� dbuf �ڵĻ������������ͷţ����Խ����ʽ�ǽ�ֹ dbuf_guard �����ÿ���

391.1) 2015.12.22
391.1) compile: polarssl_io.cpp �н� sys_read_ready ����Ϊ read_ready

Expand Down
3 changes: 3 additions & 0 deletions lib_acl_cpp/include/acl_cpp/stdlib/dbuf_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ class ACL_CPP_API dbuf_guard

// 扩充 objs_ 数组对象的空间
void extend_objs();

// 禁止引用拷贝
dbuf_guard(dbuf_guard&) {}
};

/**
Expand Down
3 changes: 3 additions & 0 deletions lib_acl_cpp/samples/socket/c1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
base_path = ../../..
include ../../Makefile.in
PROG = socket_client
Loading

0 comments on commit c700540

Please sign in to comment.