Merge pull request #19 from zhengshuxin/master

merge from acl
This commit is contained in:
郑树新 2016-11-01 21:55:54 +08:00 committed by GitHub
commit b3c2f911b7
77 changed files with 795 additions and 1279 deletions

View File

@ -81,7 +81,7 @@ endif
##############################################################################
.PHONY = check help all_lib all samples all clean install uninstall uninstall_all build_bin build_src build_one
VERSION = 3.1.5
VERSION = 3.2.2
help:
@(echo "usage: make help|all|all_lib|all_samples|clean|install|uninstall|uninstall_all|build_bin|build_src|build_one")

View File

@ -1,103 +0,0 @@
SHELL = /bin/sh
CC = g++
AR = ar
ARFL = rv
RANLIB = ranlib
#OSNAME = $(shell uname -sm)
#OSTYPE = $(shell uname -p)
OSNAME = $(shell uname -a)
OSTYPE = $(shell uname -a)
LIB_PATH = ./dist/lib
ACL_LIB = $(LIB_PATH)
PROTO_LIB = $(LIB_PATH)
DICT_LIB = $(LIB_PATH)
TLS_LIB = $(LIB_PATH)
INC_PATH = ./dist/include
ACL_INC = $(INC_PATH)/acl
PROTO_INC = $(INC_PATH)/protocol
DICT_INC = $(INC_PATH)/dict
TLS_INC = $(INC_PATH)/tls
RPATH =
DATE_NOW = 20`date +%y`.`date +%m`.`date +%d`
MAKE_ARGS =
SYSLIB = -lpthread -lz
LDFLAGS = -shared
ifeq ($(findstring Linux, $(OSNAME)), Linux)
ifeq ($(findstring i686, $(OSTYPE)), i686)
RPATH = linux32
endif
ifeq ($(findstring x86_64, $(OSTYPE)), x86_64)
RPATH = linux64
endif
n = `cat /proc/cpuinfo | grep processor | wc -l`
MAKE_ARGS = -j $(n)
SYSLIB += -lrt -ldl
endif
# For Darwin
ifeq ($(findstring Darwin, $(OSNAME)), Darwin)
RPATH = macos
SYSLIB += -rdynamic -L/usr/lib -liconv
LDFLAGS = -dynamiclib -shared
endif
ifeq ($(findstring FreeBSD, $(OSNAME)), FreeBSD)
RPATH = freebsd
SYSLIB += -L/usr/local/lib -liconv
endif
ifeq ($(findstring SunOS, $(OSNAME)), SunOS)
ifeq ($(findstring i386, $(OSTYPE)), i386)
RPATH = sunos_x86
endif
SYSLIB += -liconv
endif
##############################################################################
.PHONY = check help all_lib all samples all clean install uninstall uninstall_all build_bin build_src build_one
VERSION = 3.1.5
help:
@(echo "usage: make help|all|all_lib|all_samples|clean|install|uninstall|uninstall_all|build_bin|build_src|build_one")
all_lib:
@(cd lib_acl; make $(MAKE_ARGS) -f Makefile.debug)
@(cd lib_protocol; make $(MAKE_ARGS) -f Makefile.debug)
@(cd lib_acl_cpp; make $(MAKE_ARGS) -f Makefile.debug)
clean:
@(cd lib_acl; make clean -f Makefile.debug)
@(cd lib_protocol; make clean -f Makefile.debug)
@(cd lib_acl_cpp; make clean -f Makefile.debug)
@(rm -f lib_acl.a lib_acl.so)
RELEASE_PATH = release
build_one: all_lib
@(mkdir -p $(RELEASE_PATH); mkdir -p $(RELEASE_PATH)/acl; \
mkdir -p $(RELEASE_PATH)/protocol; \
mkdir -p $(RELEASE_PATH)/acl_cpp)
@(cp lib_acl/lib/lib_acl.a $(RELEASE_PATH)/acl/)
@(cp lib_protocol/lib/lib_protocol.a $(RELEASE_PATH)/protocol/)
@(cp lib_acl_cpp/lib/lib_acl_cpp.a $(RELEASE_PATH)/acl_cpp/)
@(cd $(RELEASE_PATH)/acl; ar -x lib_acl.a)
@(cd $(RELEASE_PATH)/protocol; ar -x lib_protocol.a)
@(cd $(RELEASE_PATH)/acl_cpp; ar -x lib_acl_cpp.a)
$(AR) $(ARFL) ./lib_acl.a $(RELEASE_PATH)/acl/*.o \
$(RELEASE_PATH)/protocol/*.o $(RELEASE_PATH)/acl_cpp/*.o
$(RANLIB) ./lib_acl.a
$(CC) $(LDFLAGS) -o ./lib_acl.so $(RELEASE_PATH)/acl_cpp/*.o \
$(RELEASE_PATH)/protocol/*.o $(RELEASE_PATH)/acl/*.o \
$(SYSLIB)
@(rm -rf $(RELEASE_PATH))
@echo ""
@echo "Over, lib_acl.a and lib_acl.so were built ok!"
@echo ""
check:
@(echo "TYPE: $(OSTYPE)")
@(echo "OSNAME: $(OSNAME)")
@(echo "RPATH: $(RPATH)")

View File

@ -1,5 +1,6 @@
修改历史列表:
------------------------------------------------------------------------
99) 2016.11.1 --- acl 3.2.2 版本发布!
98) 2016.9.7 --- acl 3.2.1 版本发布!
97) 2016.8.27 --- acl 3.2.0 版本发布!

View File

@ -1,528 +0,0 @@
SHELL = /bin/sh
#CC = gcc
#CC = g++
CC = ${ENV_CC}
AR = ar
ARFL = rv
#ARFL = cru
RANLIB = ranlib
FLAGS = ${ENV_FLAGS}
# default lib name
LIB_NAME = lib_acl.a
#-fno-strict-aliasing \
#CFLAGS = -c -g -W -Wall -Wcast-qual -Wcast-align
CFLAGS = -c -g -W \
-Wall \
-Wshadow \
-Wpointer-arith \
-Waggregate-return \
-Wmissing-prototypes \
-D_REENTRANT \
-D_USE_FAST_MACRO \
-Wno-long-long \
-D_POSIX_PTHREAD_SEMANTICS \
#-Wno-invalid-source-encoding \
#-Wno-extended-offsetof
#-Wcast-align
#-Winvalid-pch -DACL_PREPARE_COMPILE
###########################################################
#Check system:
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
SYSLIB = -lpthread
CHECKSYSRES = @echo "Unknow system type!";exit 1
UNIXNAME = $(shell uname -sm)
UNIXTYPE = LINUX
ifeq ($(CC),)
CC = gcc
endif
ifeq ($(findstring gcc, $(CC)), gcc)
CFLAGS += -Wstrict-prototypes
endif
ifeq ($(findstring clang, $(CC)), clang)
CFLAGS += -Wstrict-prototypes \
-Wno-invalid-source-encoding \
-Wno-extended-offsetof
endif
ifeq ($(findstring clang++, $(CC)), clang)
CFLAGS += -Wno-invalid-source-encoding \
-Wno-extended-offsetof
endif
# For FreeBSD
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
CFLAGS += -DFREEBSD -fPIC -Werror
UNIXTYPE = FREEBSD
endif
# For Darwin
ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
CFLAGS += -DMACOSX -Wno-invalid-source-encoding \
-Wno-extended-offsetof -fPIC -Werror
UNIXTYPE = MACOSX
endif
# For Linux
ifeq ($(findstring Linux, $(UNIXNAME)), Linux)
CFLAGS += -DLINUX2 -fPIC -Werror
UNIXTYPE = LINUX
endif
ifeq ($(findstring HAS_TRACE, $(FLAGS)), HAS_TRACE)
CFLAGS += -DHAS_TRACE
endif
EXECINFO_H = /usr/include/execinfo.h
EXECINFO_H_EXIST = $(shell if [ -f $(EXECINFO_H) ]; \
then echo "exist"; else echo "notexist"; fi;)
ifeq ($(findstring exist, $(EXECINFO_H_EXIST)), exist)
CFLAGS += -DHAS_EXECINFO_HEAD
endif
# For MINGW
ifeq ($(findstring MINGW, $(UNIXNAME)), MINGW)
CFLAGS += -DLINUX2 -DMINGW
UNIXTYPE = LINUX
SYSLIB = -lpthread-2
endif
# For SunOS
ifeq ($(findstring SunOS, $(UNIXNAME)), SunOS)
ifeq ($(findstring 86, $(UNIXNAME)), 86)
SYSLIB += -lsocket -lnsl -lrt
endif
ifeq ($(findstring sun4u, $(UNIXNAME)), sun4u)
SYSLIB += -lsocket -lnsl -lrt
endif
CFLAGS += -DSUNOS5 -fPIC -Werror
UNIXTYPE = SUNOS5
endif
# For HP-UX
ifeq ($(findstring HP-UX, $(UNIXNAME)), HP-UX)
CFLAGS += -DHP_UX -DHPUX11 -fPIC -Werror
UNIXTYPE = HPUX
endif
#CCARGS =
#ifeq ($(findstring HAS_MYSQL, $(CCARGS)), HAS_MYSQL)
# CFLAGS += -DHAS_MYSQL
# LIB_NAME = lib_acl.a
#endif
#CFLAGS += -DHAS_MYSQL
#Find system type.
ifneq ($(SYSPATH),)
CHECKSYSRES = @echo "System is $(shell uname -sm)"
endif
###########################################################
OUT_PATH = .
OBJ_PATH_DST = $(OUT_PATH)/debug
LIB_PATH_DST = $(OUT_PATH)/lib
DEF_PATH_DST = $(OUT_PATH)/debug
BASE_PATH = .
INC_PATH_SRC = $(BASE_PATH)/include
SRC_PATH_SRC = $(BASE_PATH)/src
CFLAGS += -I. -I$(INC_PATH_SRC) -I../include/mysql
###########################################################
#Project's objs
INIT_SRC = $(wildcard $(SRC_PATH_SRC)/init/*.c)
PRIV_SRC = $(wildcard $(SRC_PATH_SRC)/private/*.c)
STDLIB_SRC = $(wildcard $(SRC_PATH_SRC)/stdlib/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/common/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/iostuff/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/configure/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/filedir/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/string/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/memory/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/debug/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/sys/*.c) \
$(wildcard $(SRC_PATH_SRC)/stdlib/sys/unix/*.c)
NET_SRC = $(wildcard $(SRC_PATH_SRC)/net/*.c) \
$(wildcard $(SRC_PATH_SRC)/net/listen/*.c) \
$(wildcard $(SRC_PATH_SRC)/net/connect/*.c) \
$(wildcard $(SRC_PATH_SRC)/net/dns/*.c)
ENGINE_SRC = $(wildcard $(SRC_PATH_SRC)/event/*.c)
IOCTL_SRC = $(wildcard $(SRC_PATH_SRC)/ioctl/*.c)
AIO_SRC = $(wildcard $(SRC_PATH_SRC)/aio/*.c)
MSG_SRC = $(wildcard $(SRC_PATH_SRC)/msg/*.c)
THREAD_SRC = $(wildcard $(SRC_PATH_SRC)/thread/*.c)
SVR_SRC = $(wildcard $(SRC_PATH_SRC)/svr/*.c)
DB_SRC = $(wildcard $(SRC_PATH_SRC)/db/*.c) \
$(wildcard $(SRC_PATH_SRC)/db/mysql/*.c) \
$(wildcard $(SRC_PATH_SRC)/db/null/*.c) \
$(wildcard $(SRC_PATH_SRC)/db/memdb/*.c) \
$(wildcard $(SRC_PATH_SRC)/db/zdb/*.c)
CODE_SRC = $(wildcard $(SRC_PATH_SRC)/code/*.c)
MASTER_SRC = $(wildcard $(SRC_PATH_SRC)/master/*.c) \
$(wildcard $(SRC_PATH_SRC)/master/framework/*.c) \
$(wildcard $(SRC_PATH_SRC)/master/framework/trigger/*.c) \
$(wildcard $(SRC_PATH_SRC)/master/template/*.c)
PROCTL_SRC = $(wildcard $(SRC_PATH_SRC)/proctl/*.c)
XML_SRC = $(wildcard $(SRC_PATH_SRC)/xml/*.c)
JSON_SRC = $(wildcard $(SRC_PATH_SRC)/json/*.c)
UTEST_SRC = $(wildcard $(SRC_PATH_SRC)/unit_test/*.c)
#EXP_SRC = $(wildcard $(SRC_PATH_SRC)/experiment/avl/*.c)
SOURCES_SRC = $(INIT_SRC) $(STDLIB_SRC) $(NET_SRC) \
$(ENGINE_SRC) $(IOCTL_SRC) $(AIO_SRC) \
$(MSG_SRC) $(THREAD_SRC) $(SVR_SRC) \
$(DB_SRC) $(CODE_SRC) $(MASTER_SRC) \
$(PROCTL_SRC) $(XML_SRC) $(UTEST_SRC)
#$(EXP_SRC)
###########################################################
INIT_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(INIT_SRC)))
PRIV_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(PRIV_SRC)))
STDLIB_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(STDLIB_SRC)))
NET_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(NET_SRC)))
ENGINE_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(ENGINE_SRC)))
IOCTL_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(IOCTL_SRC)))
AIO_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(AIO_SRC)))
MSG_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(MSG_SRC)))
THREAD_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(THREAD_SRC)))
SVR_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(SVR_SRC)))
DB_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(DB_SRC)))
CODE_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(CODE_SRC)))
MASTER_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(MASTER_SRC)))
PROCTL_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(PROCTL_SRC)))
XML_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(XML_SRC)))
JSON_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(JSON_SRC)))
UTEST_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(UTEST_SRC)))
#EXP_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(EXP_SRC)))
OBJS_DST = $(INIT_OBJ) $(PRIV_OBJ) $(STDLIB_OBJ) \
$(NET_OBJ) $(ENGINE_OBJ) $(IOCTL_OBJ) \
$(AIO_OBJ) $(MSG_OBJ) $(THREAD_OBJ) \
$(SVR_OBJ) $(DB_OBJ) $(CODE_OBJ) \
$(MASTER_OBJ) $(PROCTL_OBJ) $(XML_OBJ) \
$(JSON_OBJ) $(UTEST_OBJ)
#$(EXP_OBJ)
###########################################################
INIT_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(INIT_SRC)))
PRIV_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(PRIV_SRC)))
STDLIB_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(STDLIB_SRC)))
NET_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(NET_SRC)))
ENGINE_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(ENGINE_SRC)))
IOCTL_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(IOCTL_SRC)))
AIO_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(AIO_SRC)))
MSG_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(MSG_SRC)))
THREAD_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(THREAD_SRC)))
SVR_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(SVR_SRC)))
DB_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(DB_SRC)))
CODE_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(CODE_SRC)))
MASTER_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(MASTER_SRC)))
PROCTL_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(PROCTL_SRC)))
XML_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(XML_SRC)))
JSON_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(JSON_SRC)))
UTEST_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(UTEST_SRC)))
#EXP_DEF = $(patsubst %.c, $(DEF_PATH_DST)/%.inc, $(notdir $(EXP_SRC)))
OBJS_DEF = $(INIT_DEF) $(PRIV_DEF) $(STDLIB_DEF) \
$(NET_DEF) $(ENGINE_DEF) $(IOCTL_DEF) \
$(AIO_DEF) $(MSG_DEF) $(THREAD_DEF) \
$(SVR_DEF) $(DB_DEF) $(CODE_DEF) \
$(MASTER_DEF) $(PROCTL_DEF) $(XML_DEF) \
$(JSON_DEF) $(UTEST_DEF)
###########################################################
.PHONY = all static shared acl_master clean clean_lib clean_master rebuild
STATIC_LIBNAME = lib_acl.a
SHARED_LIBNAME = lib_acl.so
all: static shared acl_master
$(shell mkdir -p $(DEF_PATH_DST))
ifneq ($(MAKECMDGOALS),clean)
-include $(OBJS_DEF)
endif
clean: clean_lib clean_master
rebuild: clean all
LIB_GCH = StdAfx.h.gch
###########################################################
COMPILE = $(CC) $(CFLAGS)
COMPILE_OBJ = @(echo 'building $<'; $(COMPILE) $< -o $@)
CREATE_DEF = @(echo 'creating $@'; rm -f $@; \
$(COMPILE) -MM $< > $@.$$$$; \
sed 's,.*.o\( \)*:,$(patsubst %.inc,%.o,$@) $@ :,g' < $@.$$$$ > $@; \
rm -f $@.$$$$)
static: depends $(OBJS_DST)
@echo 'creating $(LIB_PATH_DST)/$(STATIC_LIBNAME)'
@$(AR) $(ARFL) $(LIB_PATH_DST)/$(STATIC_LIBNAME) $(OBJS_DST)
@$(RANLIB) $(LIB_PATH_DST)/$(STATIC_LIBNAME)
@echo 'build $(LIB_PATH_DST)/$(STATIC_LIBNAME) ok!'
#shared_ldflags = -lmysqlclient -lrt -lpthread -ldl
shared_ldflags = -lrt -lpthread -ldl
shared: depends $(OBJS_DST)
@echo ''
@echo 'creating $(SHARED_LIBNAME)'
@if test -n "$(rpath)" && test "$(UNIXTYPE)" = "LINUX"; then \
echo "building for linux"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-L$(rpath) $(shared_ldflags) -Wl,-rpath,$(rpath); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "SUNOS5"; then \
echo "building for sunos5"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-L$(rpath) $(shared_ldflags); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "MACOSX"; then \
echo "building for Darwin"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-L$(rpath) -lpthread; \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "FREEBSD"; then \
echo "building for FreeBSD"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-L$(rpath) -lpthread; \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
else \
echo 'skip build $(SHARED_LIBNAME); usage: make shared rpath=xxx'; \
fi
depends: $(OBJS_DEF)
lib_gch: include/StdAfx.h
$(CC) -o include/$(LIB_GCH) -x c-header $(CFLAGS) include/StdAfx.h
###########################################################
# init
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/init/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/init/%.c
$(CREATE_DEF)
# private
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/private/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/private/%.c
$(CREATE_DEF)
# stdlib
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/common/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/common/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/iostuff/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/iostuff/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/configure/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/configure/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/filedir/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/filedir/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/string/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/string/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/memory/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/memory/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/debug/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/debug/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/sys/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/sys/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/stdlib/sys/unix/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/stdlib/sys/unix/%.c
$(CREATE_DEF)
# net
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/net/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/net/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/net/listen/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/net/listen/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/net/connect/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/net/connect/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/net/dns/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/net/dns/%.c
$(CREATE_DEF)
# event
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/event/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/event/%.c
$(CREATE_DEF)
# ioctl
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/ioctl/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/ioctl/%.c
$(CREATE_DEF)
# aio
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/aio/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/aio/%.c
$(CREATE_DEF)
# msg
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/msg/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/msg/%.c
$(CREATE_DEF)
# thread
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/thread/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/thread/%.c
$(CREATE_DEF)
# svr
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/svr/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/svr/%.c
$(CREATE_DEF)
# db
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/db/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/db/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/db/mysql/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/db/mysql/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/db/null/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/db/null/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/db/memdb/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/db/memdb/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/db/zdb/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/db/zdb/%.c
$(CREATE_DEF)
# code
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/code/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/code/%.c
$(CREATE_DEF)
# master
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/master/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/master/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/master/framework/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/master/framework/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/master/framework/trigger/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/master/framework/trigger/%.c
$(CREATE_DEF)
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/master/template/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/master/template/%.c
$(CREATE_DEF)
# proctl
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/proctl/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/proctl/%.c
$(CREATE_DEF)
# xml
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/xml/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/xml/%.c
$(CREATE_DEF)
# json
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/json/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/json/%.c
$(CREATE_DEF)
# unit_test
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/unit_test/%.c
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/unit_test/%.c
$(CREATE_DEF)
# experiment
#$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/experiment/%.c
# $(COMPILE_OBJ)
#$(DEF_PATH_DST)/%.inc: $(SRC_PATH_SRC)/experiment/%.c
# $(CREATE_DEF)
clean_lib:
rm -f $(LIB_PATH_DST)/$(LIB_NAME)
rm -f $(LIB_PATH_DST)/lib_acl.so
rm -f $(OBJS_DST)
rm -f $(OBJS_DEF)
rm -f include/$(LIB_GCH)
###########################################################
MASTER = acl_master
MASTER_OBJ_PATH = $(OUT_PATH)/master
MASTERD_SRC = $(wildcard $(SRC_PATH_SRC)/master/daemon/*.c)
MASTERD_OBJ = $(patsubst %.c, $(MASTER_OBJ_PATH)/%.o, $(notdir $(MASTERD_SRC)))
# master
acl_master: static $(MASTERD_OBJ)
@echo ''
@echo 'creating acl_master'
@if test -n "$(rpath)"; then \
$(CC) -o $(MASTER_OBJ_PATH)/$(MASTER) $(MASTERD_OBJ) \
$(LIB_PATH_DST)/$(LIB_NAME) $(SYSLIB) -Wl,-rpath,$(rpath); \
else \
$(CC) -o $(MASTER_OBJ_PATH)/$(MASTER) $(MASTERD_OBJ) \
$(LIB_PATH_DST)/$(LIB_NAME) $(SYSLIB); \
fi
@echo 'create acl_master ok!'
$(MASTER_OBJ_PATH)/%.o: $(SRC_PATH_SRC)/master/daemon/%.c
$(COMPILE_OBJ)
clean_master:
rm -f $(MASTERD_OBJ)
rm -f $(MASTER_OBJ_PATH)/acl_master
###########################################################

View File

@ -27,9 +27,6 @@ int acl_secure_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap);
# endif /* _WIN32 */
# ifdef ACL_UNIX
# ifndef __USE_XOPEN2K
# define __USE_XOPEN2K
# endif
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif

View File

@ -1,5 +1,12 @@
修改历史列表:
567) 2016.10.28
567.1) compile: 可以在 centos4.7 上使用 gcc 3.x.x 编译
566) 2016.10.25
566.1) compile: 使用 gcc 编译时若打开预编译选项,个别文件会因头文件未包含而报错
566.2) bugfix: 修复了 url coder 针对 '+' 编码时的不兼容性问题
565) 2016.10.21
565.1) feature: ACL_VSTREAM 结构体中新增标志位 omode主要用于 UNIX 平台打开文件
565.2) bugfix: acl_json.h 头文件中定义的 ACL_JSON_T_XXX 有重复值,容易造成混乱

View File

@ -10,12 +10,12 @@ extern "C" {
/**
* ACL库
*/
ACL_API void acl_init(void);
ACL_API void acl_lib_init(void);
/**
* ACL库
*/
ACL_API void acl_end(void);
ACL_API void acl_lib_end(void);
/**
* 使 poll select

View File

@ -18,6 +18,10 @@ typedef struct acl_stat acl_stat_t;
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#define _ACL_UCHAR_(c) ((unsigned char)(c))

View File

@ -10,6 +10,11 @@ extern "C" {
#define ACL_MUTEX_MAXWAIT (~(unsigned int)0)
#ifdef ACL_HAS_PTHREAD
#ifdef ACL_UNIX
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
#endif
# include <pthread.h>
typedef pthread_t acl_pthread_t;

View File

@ -28,7 +28,7 @@ static void init(int use_slice)
acl_mem_slice_init(8, 10240, 100000, ACL_SLICE_FLAG_GC2
| ACL_SLICE_FLAG_RTGC_OFF | ACL_SLICE_FLAG_LP64_ALIGN);
acl_init();
acl_lib_init();
echo_client_init(ECHO_CTL_SERV_ADDR, __svr_addr,
ECHO_CTL_MAX_CONNECT, __nconnect,
ECHO_CTL_MAX_LOOP, __nloop,

View File

@ -34,7 +34,7 @@ static void init(void)
acl_mem_slice_init(8, 10240, 100000,
ACL_SLICE_FLAG_GC2 | ACL_SLICE_FLAG_RTGC_OFF | ACL_SLICE_FLAG_LP64_ALIGN);
acl_init();
acl_lib_init();
#ifdef USE_LOG
acl_msg_open(logfile, logpre);
#endif

View File

@ -100,7 +100,7 @@ int main(int argc, char *argv[])
dns_ips[0] = 0;
domains[0] = 0;
acl_init();
acl_lib_init();
while ((ch = getopt(argc, argv, "s:p:d:")) > 0) {
switch (ch) {

View File

@ -88,7 +88,7 @@ int main(int argc acl_unused, char *argv[] acl_unused)
int meter = 0;
/* 初始化 acl 库 */
acl_init();
acl_lib_init();
/* 将错误日志输出至标准输出 */
acl_msg_stdout_enable(1);

View File

@ -8,7 +8,7 @@ static void end(void)
fflush(stdout);
getchar();
#endif
acl_end();
acl_lib_end();
}
static void test_file(void)
@ -81,7 +81,7 @@ static int test_vstream(void)
char buf[256];
struct tm *local_time;
acl_init();
acl_lib_init();
if (fp == NULL) {
printf("open file(%s) error(%s)\r\n", filename, acl_last_serror());

View File

@ -113,7 +113,7 @@ static void init(int nthread)
acl_pthread_attr_t attr;
int i;
acl_init();
acl_lib_init();
__ipc_clients = (IPC_CLIENT*) acl_mycalloc(nthread, sizeof(IPC_CLIENT));

View File

@ -169,7 +169,7 @@ int main(int argc acl_unused, char *argv[] acl_unused)
char addr[256];
int ch, n, f;
acl_init();
acl_lib_init();
acl_msg_stdout_enable(1);
addr[0] = 0;

View File

@ -4,12 +4,12 @@
static void init(void)
{
acl_init();
acl_lib_init();
}
static void end(void)
{
acl_end();
acl_lib_end();
}
static void thread_run(void *arg)

View File

@ -154,7 +154,7 @@ int main(int argc, char *argv[])
}
}
acl_init();
acl_lib_init();
if (use_slice)
acl_mem_slice_init(base, nslice, nalloc_gc, slice_flag);
if (use_thrpool)

View File

@ -124,7 +124,7 @@ int main(int argc, char *argv[])
int ch, count = 1, dlen = 100, inter = 1000, nthreads = 1, quit = 0;
int need_read = 0;
acl_init();
acl_lib_init();
snprintf(peer, sizeof(peer), "127.0.0.1:8888");
snprintf(local, sizeof(local), "127.0.0.1:0");
@ -192,7 +192,7 @@ int main(int argc, char *argv[])
printf("\r\nlocal: %s, peer: %s, count: %d, dlen: %d, inter: %d\r\n",
local, peer, count, dlen, inter);
acl_end();
acl_lib_end();
return 0;
}

View File

@ -74,7 +74,7 @@ int main(int argc, char *argv[])
char addr[64];
int ch, can_quit = 0, need_echo = 0, inter = 1000;
acl_init();
acl_lib_init();
snprintf(addr, sizeof(addr), "127.0.0.1:8888");
@ -109,7 +109,7 @@ int main(int argc, char *argv[])
signal(SIGINT, on_sigint);
run(addr, can_quit, need_echo, inter);
acl_end();
acl_lib_end();
return 0;
}

View File

@ -0,0 +1,2 @@
include ../Makefile_cpp.in
PROG = urlcode

View File

@ -1,27 +1,29 @@
#if defined(ACL_WINDOWS)
#pragma comment(lib,"ws2_32")
#endif
#include "lib_acl.h"
#include <assert.h>
static void test_urlcode(void)
{
const char *params = "name=中国&value=人民&name2=姓名&value2=逍遥仙";
const char *params = "n a m e=中国&value=人民&name2=姓名&value2=逍遥仙";
char *tmp1, *tmp2;
printf("params: (%s), len=%d\r\n", params, strlen(params));
tmp1 = acl_url_encode(params);
printf("params: (%s), len=%d\r\n", params, (int) strlen(params));
tmp1 = acl_url_encode(params, NULL);
assert(tmp1);
printf("encode: (%s), len=%d\r\n", tmp1, strlen(tmp1));
tmp2 = acl_url_decode(tmp1);
printf("encode: (%s), len=%d\r\n", tmp1, (int) strlen(tmp1));
tmp2 = acl_url_decode(tmp1, NULL);
assert(tmp2);
printf("decode: (%s), len=%d\r\n", tmp2, strlen(tmp2));
printf("decode: (%s), len=%d\r\n", tmp2, (int) strlen(tmp2));
acl_myfree(tmp1);
acl_myfree(tmp2);
}
int main(int argc, char *argv[])
int main(void)
{
test_urlcode();
printf(">>\\r: %d, \\n: %d\r\n", (int) '\r', (int) '\n');

View File

@ -152,7 +152,7 @@ int main(int argc acl_unused, char *argv[] acl_unused)
ACL_VSTRING *sbuf;
int flag = 0;
acl_init();
acl_lib_init();
#if 0
return (vstream_server());

View File

@ -0,0 +1,2 @@
include ../Makefile.in
PROG = xml

112
lib_acl/samples/xml2/main.c Normal file
View File

@ -0,0 +1,112 @@
#include "lib_acl.h"
static double stamp_sub(const struct timeval *from, const struct timeval *sub_by)
{
struct timeval res;
memcpy(&res, from, sizeof(struct timeval));
res.tv_usec -= sub_by->tv_usec;
if (res.tv_usec < 0) {
--res.tv_sec;
res.tv_usec += 1000000;
}
res.tv_sec -= sub_by->tv_sec;
return (res.tv_sec * 1000.0 + res.tv_usec/1000.0);
}
static void usage(const char* proc)
{
printf("usage: %s -h[help] -m[use_memslice] -c cache_count -f filepath\r\n", proc);
}
int main(int argc, char* argv[])
{
char buf[8192], filepath[256];
int ret, n;
ACL_VSTREAM* fp;
ACL_XML* xml;
struct timeval begin, end;
double spent;
int ch, use_slice = 0, cache_count = 1000;
filepath[0] = 0;
while ((ch = getopt(argc, argv, "hmc:f:")) > 0)
{
switch (ch)
{
case 'h':
usage(argv[0]);
return 0;
case 'm':
use_slice = 1;
break;
case 'c':
cache_count = atoi(optarg);
if (cache_count <= 0)
cache_count = 1000;
break;
case 'f':
snprintf(filepath, sizeof(filepath), "%s", optarg);
break;
default:
break;
}
}
if (use_slice)
acl_mem_slice_init(8, 1024, 100000,
ACL_SLICE_FLAG_GC2 |
ACL_SLICE_FLAG_RTGC_OFF |
ACL_SLICE_FLAG_LP64_ALIGN);
if (filepath[0] == 0)
{
usage(argv[0]);
return 1;
}
xml = acl_xml_alloc();
if (cache_count > 0)
acl_xml_cache(xml, cache_count);
fp = acl_vstream_fopen(filepath, O_RDONLY, 0600, 8192);
if (fp == NULL)
{
printf("open file %s error %s\r\n",
filepath, acl_last_serror());
acl_xml_free(xml);
return 1;
}
gettimeofday(&begin, NULL);
n = 0;
ACL_METER_TIME("------begin------");
while (1)
{
ret = acl_vstream_fgets(fp, buf, sizeof(buf) - 1);
if (ret == ACL_VSTREAM_EOF)
break;
buf[ret] = 0;
acl_xml_parse(xml, buf);
if (++n % 10000 == 0)
{
printf("line: %d\r\n", n);
ACL_METER_TIME("-------ok------");
}
if (n % cache_count == 0)
{
printf("reset xml, line: %d\r\n", n);
acl_xml_reset(xml);
}
}
gettimeofday(&end, NULL);
spent = stamp_sub(&end, &begin);
printf("\r\ntotal spent: %0.2f ms\r\n", spent);
acl_xml_free(xml);
acl_vstream_fclose(fp);
return 0;
}

View File

@ -29,9 +29,10 @@ char *acl_url_encode(const char *str, ACL_DBUF_POOL *dbuf)
for (i = 0, j = 0; i < len; i++, j++) {
tmp[j] = (unsigned char) str[i];
if (tmp[j] == ' ')
/* if (tmp[j] == ' ')
tmp[j] = '+';
else if (!isalnum(tmp[j]) && strchr("_-.", tmp[j]) == NULL) {
else */
if (!isalnum(tmp[j]) && strchr("_-.", tmp[j]) == NULL) {
tmp_len += 3;
if (dbuf != NULL) {
unsigned char *t = (unsigned char*)
@ -89,9 +90,11 @@ char *acl_url_decode(const char *str, ACL_DBUF_POOL *dbuf)
* needs to be multiplied by 16 ( << 4 ), and the
* another one we just get the value from hextable variable
*/
/*
if (str[i] == '+')
tmp[pos] = ' ';
else if (str[i] != '%')
else */
if (str[i] != '%')
tmp[pos] = str[i];
else if (i + 2 >= len) { /* check boundary */
tmp[pos++] = '%'; /* keep it */

View File

@ -3,18 +3,6 @@
#include "stdlib/acl_define.h"
#if defined(ACL_LINUX) && !defined(MINGW)
# define __USE_UNIX98
# include <unistd.h>
# define PWRITE pwrite64
# define PREAD pread64
#else
# undef PWRITE
# undef PREAD
#endif
#include <string.h>
#include "stdlib/avl.h"
#include "stdlib/acl_msg.h"
@ -25,7 +13,17 @@
#include "stdlib/acl_mymalloc.h"
#include "stdlib/acl_mystring.h"
#include "db/zdb.h"
#endif
#if defined(ACL_LINUX) && !defined(MINGW) && defined(__GNUC__) && __GNUC__ >= 4
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
# include <unistd.h>
# ifdef __USE_LARGEFILE64
# define PWRITE pwrite64
# define PREAD pread64
# endif
#endif
#include "zdb_private.h"

View File

@ -24,7 +24,7 @@
#include "init.h"
static char *version = "acl_3.1.5";
static char *version = "acl_3.2.2";
const char *acl_version(void)
{
@ -40,10 +40,10 @@ static unsigned long acl_var_main_tid = (unsigned long) -1;
#endif
#ifdef ACL_UNIX
void acl_init(void) __attribute__ ((constructor));
void acl_lib_init(void) __attribute__ ((constructor));
#endif
void acl_init(void)
void acl_lib_init(void)
{
static int __have_inited = 0;
@ -60,10 +60,10 @@ void acl_init(void)
}
#ifdef ACL_UNIX
void acl_end(void) __attribute__ ((destructor));
void acl_lib_end(void) __attribute__ ((destructor));
#endif
void acl_end(void)
void acl_lib_end(void)
{
static int __have_ended = 0;

View File

@ -2,7 +2,6 @@
#ifndef ACL_PREPARE_COMPILE
#include "stdlib/acl_define.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -2,6 +2,7 @@
#ifndef ACL_PREPARE_COMPILE
#include "stdlib/acl_define.h"
#include "stdlib/acl_msg.h"
#include "stdlib/acl_mymalloc.h"
#include "thread/acl_pthread.h"
#include "stdlib/acl_atomic.h"
@ -50,7 +51,14 @@ void acl_atomic_set(ACL_ATOMIC *self, void *value)
#elif defined(ACL_WINDOWS)
InterlockedExchangePointer((volatile PVOID*) &self->value, value);
#elif defined(ACL_LINUX)
# if defined(__GNUC__) && (__GNUC__ >= 4)
(void) __sync_lock_test_and_set(&self->value, value);
# else
(void) self;
(void) value;
acl_msg_error("%s(%d), %s: not support!",
__FILE__, __LINE__, __FUNCTION__);
# endif
#endif
}
@ -70,7 +78,16 @@ void *acl_atomic_cas(ACL_ATOMIC *self, void *cmp, void *value)
return InterlockedCompareExchangePointer(
(volatile PVOID*)&self->value, value, cmp);
#elif defined(ACL_LINUX)
# if defined(__GNUC__) && (__GNUC__ >= 4)
return __sync_val_compare_and_swap(&self->value, cmp, value);
# else
(void) self;
(void) cmp;
(void) value;
acl_msg_error("%s(%d), %s: not support!",
__FILE__, __LINE__, __FUNCTION__);
return NULL;
# endif
#endif
}
@ -88,6 +105,14 @@ void * acl_atomic_xchg(ACL_ATOMIC *self, void *value)
#elif defined(ACL_WINDOWS)
return InterlockedExchangePointer((volatile PVOID*)&self->value, value);
#elif defined(ACL_LINUX)
# if defined(__GNUC__) && (__GNUC__ >= 4)
return __sync_lock_test_and_set(&self->value, value);
# else
(void) self;
(void) value;
acl_msg_error("%s(%d), %s: not support!",
__FILE__, __LINE__, __FUNCTION__);
return NULL;
# endif
#endif
}

View File

@ -2,8 +2,10 @@
#ifndef ACL_PREPARE_COMPILE
#include <string.h>
#include "stdlib/acl_define.h"
#include "stdlib/acl_mymalloc.h"
#include "stdlib/acl_atomic.h"
#include "stdlib/acl_yqueue.h"
#endif

View File

@ -24,9 +24,6 @@
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
# ifndef __USE_XOPEN2K
# define __USE_XOPEN2K
# endif
# include <pthread.h>
#endif

View File

@ -20,9 +20,6 @@
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
# ifndef __USE_XOPEN2K
# define __USE_XOPEN2K
# endif
# include <pthread.h>
#endif

View File

@ -7,6 +7,7 @@
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef ACL_WINDOWS
#include <search.h> /* just for qsort */
#endif

View File

@ -1,332 +0,0 @@
SHELL = /bin/sh
CC = ${ENV_CC}
#CC = g++
AR = ar
ARFL = rv
#ARFL = cru
RANLIB = ranlib
FLAGS = ${ENV_FLAGS}
CFLAGS = -c -g -W \
-Wall \
-Wpointer-arith \
-Wshadow \
-D_REENTRANT \
-D_POSIX_PTHREAD_SEMANTICS \
-Wno-long-long \
-Wformat \
-DHAS_MYSQL_DLL
#-DHAS_POLARSSL
#-DUSE_DYNAMIC
# -Wcast-align
#-Wcast-qual
#just for freebsd's iconv.h
CFLAGS += -I/usr/local/include
shared_ldflags = -l_protocol -l_acl -lz -lpthread
###########################################################
#Check system:
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
SYSLIB =
CHECKSYSRES = @echo "Unknow system type!";exit 1
UNIXNAME = $(shell uname -sm)
UNIXTYPE = LINUX
ifeq ($(CC),)
CC = g++
endif
ifeq ($(findstring HAS_POLARSSL, $(FLAGS)), HAS_POLARSSL)
CFLAGS += -DHAS_POLARSSL
endif
ifeq ($(findstring clang++, $(CC)), clang++)
CFLAGS += -Wno-invalid-source-encoding \
-Wno-extended-offsetof
endif
# For FreeBSD
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
CFLAGS += -DFREEBSD -fPIC -Werror
UNIXTYPE = FREEBSD
shared_ldflags = -l_protocol -l_acl -L/usr/local/lib -liconv -lz -lpthread
endif
# For Darwin
ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
CFLAGS += -DMACOSX -Wno-invalid-source-encoding \
-Wno-extended-offsetof -fPIC -Werror \
-Wno-unused-private-field
UNIXTYPE = MACOSX
shared_ldflags = -l_protocol -l_acl -L/usr/lib -liconv -lz -lpthread
endif
# For Linux
ifeq ($(findstring Linux, $(UNIXNAME)), Linux)
CFLAGS += -DLINUX2 -fPIC -Werror
UNIXTYPE = LINUX
shared_ldflags = -l_protocol -l_acl -lrt -lpthread -lz -ldl
endif
# For MINGW
ifeq ($(findstring MINGW, $(UNIXNAME)), MINGW)
CFLAGS += -DLINUX2 -DMINGW
UNIXTYPE = LINUX
endif
# For SunOS
ifeq ($(findstring SunOS, $(UNIXNAME)), SunOS)
ifeq ($(findstring 86, $(UNIXNAME)), 86)
SYSLIB = -lsocket -lnsl -lrt
endif
ifeq ($(findstring sun4u, $(UNIXNAME)), sun4u)
SYSLIB = -lsocket -lnsl -lrt
endif
CFLAGS += -DSUNOS5 -fPIC -Werror
UNIXTYPE = SUNOS5
endif
# For HP-UX
ifeq ($(findstring HP-UX, $(UNIXNAME)), HP-UX)
CFLAGS += -DHP_UX -DHPUX11 -fPIC -Werror
UNIXTYPE = HPUX
endif
#Find system type.
ifneq ($(SYSPATH),)
CHECKSYSRES = @echo "System is $(shell uname -sm)"
endif
###########################################################
OBJ_PATH_DST = ./Debug
LIB_PATH_DST = ./lib
DEF_PATH_DST = ./Debug
CFLAGS += -I./src -I./include -I../lib_acl/include -I../lib_protocol/include \
-I../include/sqlite -I../include/mysql -I../include/zlib -I../include
#Project's objs
OBJS_DST = $(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/stdlib/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/stream/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/master/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/ipc/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/db/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/event/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/queue/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/http/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/hsocket/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/beanstalk/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/memcache/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/session/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/smtp/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/mime/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/mime/internal/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/connpool/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/redis/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/disque/*.cpp)))
OBJS_DEF = $(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/stdlib/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/stream/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/master/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/ipc/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/db/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/event/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/queue/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/http/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/hsocket/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/beanstalk/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/memcache/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/session/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/smtp/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/mime/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/mime/internal/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/connpool/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/redis/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/disque/*.cpp)))
###########################################################
.PHONY = static shared clean
VERSION = 1.1.1.2
DATE_NOW = 20`date +%y`.`date +%m`.`date +%d`
STATIC_LIBNAME = lib_acl_cpp.a
SHARED_LIBNAME = lib_acl_cpp.so
lib: static
all: static shared sample
$(shell mkdir -p $(DEF_PATH_DST))
ifneq ($(MAKECMDGOALS),clean)
-include $(OBJS_DEF)
endif
COMPILE = $(CC) $(CFLAGS)
COMPILE_OBJ = @(echo 'building $<'; $(COMPILE) $< -o $@)
CREATE_DEF = @(echo 'creating $@'; rm -f $@; \
$(COMPILE) -MM $< > $@.$$$$; \
sed 's,.*.o\( \)*:,$(patsubst %.inc,%.o,$@) $@ :,g' < $@.$$$$ > $@; \
rm -f $@.$$$$)
###########################################################
sample: static
@(cd samples; make)
static: depends $(OBJS_DST)
@echo 'creating $(LIB_PATH_DST)/$(STATIC_LIBNAME)'
@$(AR) $(ARFL) $(LIB_PATH_DST)/$(STATIC_LIBNAME) $(OBJS_DST)
@$(RANLIB) $(LIB_PATH_DST)/$(STATIC_LIBNAME)
@echo 'create $(LIB_PATH_DST)/$(STATIC_LIBNAME) ok!'
shared: depends $(OBJS_DST)
@echo 'creating $(SHARED_LIBNAME)'
@if test -n "$(rpath)" && test "$(UNIXTYPE)" = "LINUX"; then \
echo "building for linux"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-L$(rpath) $(shared_ldflags) -Wl,-rpath,$(rpath); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "SUNOS5"; then \
echo "building for sunos5"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-R$(rpath) -L$(rpath) $(shared_ldflags); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "MACOSX"; then \
echo "building for Darwin"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-R$(rpath) -L$(rpath) $(shared_ldflags); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "FREEBSD"; then \
echo "building for Darwin"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-R$(rpath) -L$(rpath) $(shared_ldflags); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
else \
echo 'skip build $(SHARED_LIBNAME); usage: make shared rpath=xxx'; \
fi
depends: $(OBJS_DEF)
# src
$(OBJ_PATH_DST)/%.o: ./src/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/stdlib/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/stream/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/master/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/ipc/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/db/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/event/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/queue/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/http/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/hsocket/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/beanstalk/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/memcache/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/session/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/connpool/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/smtp/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/mime/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/mime/internal/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/redis/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/disque/%.cpp
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: ./src/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/stdlib/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/stream/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/master/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/ipc/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/db/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/event/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/queue/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/http/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/hsocket/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/beanstalk/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/memcache/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/session/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/connpool/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/smtp/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/mime/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/mime/internal/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/redis/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/disque/%.cpp
$(CREATE_DEF)
clean:
rm -f $(LIB_PATH_DST)/lib_acl_cpp.a
rm -f $(LIB_PATH_DST)/lib_acl_cpp.so
rm -f $(OBJS_DST)
rm -f $(OBJS_DEF)
@(cd samples; make clean)
rebuild rb: clean static
build_src: clean
@(echo "begin building src release...")
@(rm -rf acl_cpp)
@(echo "copy files ...")
@(mkdir acl_cpp)
@(cp -R src acl_cpp/)
@(cp -R mime acl_cpp/)
@(cp -R lib acl_cpp/)
@(cp -R include acl_cpp/)
@(cp -R samples acl_cpp/)
@(cp -R Debug acl_cpp/)
@(cp -R DebugDll acl_cpp/)
@(cp -R Release acl_cpp/)
@(cp -R ReleaseDll acl_cpp/)
@(cp -R bin acl_cpp/)
@(cp -R doc acl_cpp/)
@(cp lib_acl_cpp_vc2003.vcproj acl_cpp/)
@(cp acl_wrap_vc2003.sln acl_cpp/)
@(cp lib_acl_cpp_vc2010.vcxproj acl_cpp/)
@(cp acl_wrap_vc2010.sln acl_cpp/)
@(cp Makefile acl_cpp/)
@(cp changes.txt acl_cpp/)
@(cp ReadMe.txt acl_cpp/)
@(cp Doxyfile acl_cpp/)
@(echo "make tar package ...")
@(tar -cf acl_cpp.src.tar acl_cpp)
@(echo "make gzip package ...")
@(gzip -c acl_cpp.src.tar > acl_cpp.src.tgz)
@(rm acl_cpp.src.tar)
@(rm -rf acl_cpp)
@(echo "move acl_cpp.src.tgz to ../acl_cpp$(VERSION).src.$(DATE_NOW).tgz")
(mv acl_cpp.src.tgz ../acl_cpp$(VERSION).src.$(DATE_NOW).tgz)

View File

@ -1,6 +1,17 @@
修改历史列表:
-----------------------------------------------------------------------
447) 2016.10.31
447.1) bugfix: redis_string::incrbyfloat 及 redis_hash::hincrbyfloat 中在
调用 get_string 后判断是否出错的方式有问题,应该使用长度做为判定条件而不是 bool 值
446) 2016.10.26
446.1) bugfix: redis_zset.cpp 中第二个 zrevrangebyscore_with_scores 返回结果
集顺序是反的
445) 2016.10.24
445.1) bugfix: db_handle::peek_open 函数中的参数 charset 没有生效
444) 2016.10.21
444.1) bugfix: HttpServletRequest.cpp 中的方法 getLocalPort 无法取得本地端口
444.2) feature: fstream 类新方法 rename 用于修改文件名

View File

@ -57,6 +57,11 @@ public:
{
set_idle_ttl(ttl);
}
protected:
// 虚函数,子类根据需要设置字符集,当 peek_open 被调用时,此函数
// 会先被调用用来设置数据库连接的字符集
virtual void set_charset(const char*) {}
};
class ACL_CPP_API db_guard : public connect_guard

View File

@ -67,9 +67,9 @@ public:
return db_;
}
/************************************************************************/
/* 以下为基类 db_handle 的虚接口 */
/************************************************************************/
/********************************************************************/
/* 以下为基类 db_handle 的虚接口 */
/********************************************************************/
/**
*

View File

@ -41,6 +41,9 @@ protected:
// 基类 connect_pool 纯虚函数:创建数据库连接句柄
connect_client* create_connect();
//@override
void set_charset(const char* charset);
private:
mysql_conf* conf_;
};

View File

@ -23,6 +23,9 @@ protected:
// 基类 connect_pool 纯虚函数:创建数据库连接句柄
connect_client* create_connect();
//@override
void set_charset(const char* charset);
private:
// sqlite 数据文件名
char* dbfile_;

View File

@ -382,9 +382,9 @@ public:
* 3.1"ZRANGEBYSCORE zset (1 5" 1 < score <= 5
* 3.2"ZRANGEBYSCORE zset (5 (10" 5 < score < 10
*/
int zrevrangebyscore(const char* key, const char* min, const char* max,
std::vector<string>* out, const int* offset = NULL,
const int* count = NULL);
//int zrevrangebyscore(const char* key, const char* min, const char* max,
// std::vector<string>* out, const int* offset = NULL,
// const int* count = NULL);
/**
* key score min max ( min max )

View File

@ -514,7 +514,9 @@
<ClCompile Include="src\stdlib\xml2.cpp">
<Filter>Source Files\stdlib</Filter>
</ClCompile>
<ClCompile Include="src\serialize\gsoner.cpp" />
<ClCompile Include="src\serialize\gsoner.cpp">
<Filter>Source Files\serialize</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\acl_stdafx.hpp">
@ -1058,7 +1060,9 @@
<Filter>Header Files\stdlib</Filter>
</ClInclude>
<ClInclude Include="resource_vc2015.h" />
<ClInclude Include="include\acl_cpp\serialize\gsoner.hpp" />
<ClInclude Include="include\acl_cpp\serialize\gsoner.hpp">
<Filter>Header Files\serialize</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
@ -1184,6 +1188,12 @@
<Filter Include="Header Files\smtp">
<UniqueIdentifier>{d34f52dc-798d-4c26-b23f-25210566d571}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\serialize">
<UniqueIdentifier>{61183180-d88a-4f27-96bf-34a9c11fd714}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\serialize">
<UniqueIdentifier>{2b06d3aa-a69d-4f30-a8c3-4c5443a1d0a8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="lib_acl_cpp_vc2015.rc" />

View File

@ -3,6 +3,7 @@
#include <getopt.h>
#endif
#include <iostream>
#include "acl_cpp/acl_cpp_init.hpp"
#include "acl_cpp/stream/aio_handle.hpp"
#include "acl_cpp/stdlib/dns_service.hpp"
@ -72,7 +73,7 @@ int main(int argc, char* argv[])
}
}
acl_init();
acl_cpp_init();
aio_handle handle;

View File

@ -3,6 +3,7 @@
#include <getopt.h>
#endif
#include <iostream>
#include "acl_cpp/acl_cpp_init.hpp"
#include "acl_cpp/stream/aio_handle.hpp"
#include "acl_cpp/ipc/ipc_server.hpp"
#include "acl_cpp/ipc/ipc_client.hpp"
@ -189,7 +190,7 @@ int main(int argc, char* argv[])
}
}
acl_init();
acl_cpp_init();
aio_handle handle;

View File

@ -13,8 +13,8 @@ static const int __value_len = 32;
#define DELETE_VALUES(values,n)\
do\
{ for(int i = 0; i < (n) ; ++i)\
delete (values)[i];\
delete (values);\
delete [](values)[i];\
delete [](values);\
} while (0);

View File

@ -1,6 +1,5 @@
#include "lib_acl.h"
#include "acl_cpp/stream/socket_stream.hpp"
#include "acl_cpp/stdlib/string.hpp"
#include "acl_cpp/lib_acl.hpp"
#include <stdlib.h>
#include <stdio.h>
@ -9,7 +8,7 @@ int main(void)
acl::socket_stream client;
acl::string addr = "127.0.0.1:9001";
acl_init();
acl::acl_cpp_init();
if (client.open(addr, 0, 0) == false)
{
printf("open %s error\n", addr.c_str());

View File

@ -20,7 +20,8 @@ int main(int argc, char* argv[])
"Connection: close\r\n\r\n";
acl::string respond;
acl_init();
acl::acl_cpp_init();
if (client.open(addr, 0, 0) == false) {
printf("connect %s error(%s)\n", addr.c_str(), acl_last_serror());
printf("input any key to exit\n");

View File

@ -6,7 +6,7 @@ namespace acl
void acl_cpp_init(void)
{
acl_init();
acl_lib_init();
}
#ifdef ACL_WINDOWS

View File

@ -15,15 +15,13 @@ db_pool::db_pool(const char* dbaddr, size_t count, size_t idx /* = 0 */)
db_handle* db_pool::peek_open(const char* charset /* = NULL */)
{
db_handle* conn = (db_handle*) peek();
if (charset)
set_charset(charset);
db_handle* conn = (db_handle*) peek();
if (conn == NULL)
return NULL;
if (conn->dbopen(charset) == true)
return conn;
logger_error("open db failed");
put(conn, false);
return NULL;
logger_error("peek NULL");
return conn;
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -51,4 +51,10 @@ connect_client* mysql_pool::create_connect()
return NEW db_mysql(*conf_);
}
void mysql_pool::set_charset(const char* charset)
{
if (charset)
conf_->set_charset(charset);
}
} // namespace acl

View File

@ -33,4 +33,14 @@ connect_client* sqlite_pool::create_connect()
return NEW db_sqlite(dbfile_, charset_);
}
void sqlite_pool::set_charset(const char* charset)
{
if (charset == NULL || *charset == 0)
return;
if (charset_)
acl_myfree(charset_);
charset_ = acl_mystrdup(charset);
}
} // namespace acl

View File

@ -73,7 +73,7 @@ bool master_aio::run_alone(const char* addrs, const char* path /* = NULL */,
acl_assert(__handle == NULL);
daemon_mode_ = false;
#ifdef ACL_WINDOWS
acl_init();
acl_cpp_init();
#endif
std::vector<aio_listen_stream*> sstreams;
ACL_ARGV* tokens = acl_argv_split(addrs, ";,| \t");

View File

@ -88,7 +88,7 @@ bool master_proc::run_alone(const char* addrs, const char* path /* = NULL */,
acl_assert(addrs && *addrs);
#ifdef ACL_WINDOWS
acl_init();
acl_cpp_init();
#endif
ACL_EVENT* eventp = acl_event_new_select(1, 0);
set_event(eventp); // 调用基类方法设置事件引擎句柄

View File

@ -52,7 +52,7 @@ void master_trigger::run_alone(const char* path /* = NULL */,
has_called = true;
daemon_mode_ = false;
#ifdef ACL_WINDOWS
acl_init();
acl_cpp_init();
#endif
if (interval <= 0)
interval = 1;

View File

@ -88,7 +88,7 @@ bool master_udp::run_alone(const char* addrs, const char* path /* = NULL */,
acl_assert(addrs && *addrs);
#ifdef ACL_WINDOWS
acl_init();
acl_cpp_init();
#endif
ACL_EVENT* eventp = acl_event_new_select(1, 0);
set_event(eventp); // 设置基类的事件句柄

View File

@ -304,7 +304,7 @@ bool redis_hash::hincrbyfloat(const char* key, const char* name,
hash_slot(key);
build("HINCRBYFLOAT", key, names, values, 1);
if (get_string(buf, sizeof(buf)) == false)
if (get_string(buf, sizeof(buf)) <= 0)
return false;
if (result != NULL)

View File

@ -742,7 +742,7 @@ bool redis_string::incrbyfloat(const char* key, double inc,
hash_slot(key);
build_request(3, argv, lens);
if (get_string(buf, sizeof(buf)) == false)
if (get_string(buf, sizeof(buf)) <= 0)
return false;
if (result != NULL)

View File

@ -358,7 +358,7 @@ bool redis_zset::zincrby(const char* key, double inc,
hash_slot(key);
build_request(4, argv, lens);
int ret = get_string(score, sizeof(score));
if (ret < 0)
if (ret <= 0)
return false;
if (result)
*result = atof(score);
@ -782,7 +782,8 @@ int redis_zset::zrevrangebyscore_with_scores(const char* key, double min,
safe_snprintf(min_s, sizeof(min_s), "%.8f", min);
safe_snprintf(max_s, sizeof(max_s), "%.8f", max);
return zrangebyscore_with_scores(key, min_s, max_s, out, offset, count);
return zrevrangebyscore_with_scores(key, min_s, max_s,
out, offset, count);
}
int redis_zset::zrevrank(const char* key, const char* member, size_t len)

View File

@ -2,8 +2,8 @@
本网络协程库的协程部分是基于 Russ Cox (golang 的协程作者) 在 2005 年实现的 libtasklibtask 实现了协程编程的基本原型lib_fiber 一方面使协程编程接口更加简单易用(用户可以直接调用 acl_fiber_create 创建协程),另一方面 lib_fiber 实现了线程安全的协程库通过给每个线程一个独立的协程调度器从而方便用户使用多核此外lib_fiber 还增加了基于协程的信号量、协程局部变量等功能。
本网络协程库的异步 IO 事件部分基于 redis 中的 event 模块改造而来,增加了延迟删除、句柄缓存等功能。
下面是一个简单使用网络协程库编写的一个简单的高并发服务器:
###**示例一**
下面是一个简单使用网络协程库编写的一个**简单的高并发服务器**
```c++
#include <stdio.h>
#include <stdlib.h>
@ -217,8 +217,210 @@ int main(int argc, char *argv[])
return 0;
}
```
###**示例二**
上面的例子中因为使用了系统原生的网络 API所以感觉代码有些臃肿下面的例子使用 acl 库中提供的网络 API显得更为简单些
```c++
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
参考:
1、网络协程编程http://zsxxsz.iteye.com/blog/2312043
2、使用协程编写高并发网络服务http://zsxxsz.iteye.com/blog/2309654
3、使用协程方式编写高并发的WEB服务http://zsxxsz.iteye.com/blog/2309665
class fiber_client : public acl::fiber
{
public:
fiber_client(acl::socket_stream* conn) : conn_(conn) {}
protected:
// @override
void run(void)
{
printf("fiber-%d-%d running\r\n", get_id(), acl::fiber::self());
char buf[8192];
while (true)
{
int ret = conn_->read(buf, sizeof(buf), false);
if (ret == -1)
break;
if (conn_->write(buf, ret) == -1)
break;
}
delete conn_;
delete this;
}
private:
acl::socket_stream* conn_;
~fiber_client(void) {}
};
class fiber_server : public acl::fiber
{
public:
fiber_server(acl::server_socket& ss) : ss_(ss) {}
~fiber_server(void) {}
protected:
// @override
void run(void)
{
while (true)
{
acl::socket_stream* conn = ss_.accept();
if (conn == NULL)
{
printf("accept error %s\r\n", acl::last_serror());
break;
}
printf("accept ok, fd: %d\r\n", conn->sock_handle());
// create one fiber for one connection
fiber_client* fc = new fiber_client(conn);
// start the fiber
fc->start();
continue;
}
}
private:
acl::server_socket& ss_;
};
static void usage(const char* procname)
{
printf("usage: %s -h [help] -s listen_addr\r\n", procname);
}
int main(int argc, char *argv[])
{
int ch;
acl::acl_cpp_init();
acl::string addr("127.0.0.1:9006");
acl::log::stdout_open(true);
while ((ch = getopt(argc, argv, "hs:")) > 0)
{
switch (ch)
{
case 'h':
usage(argv[0]);
return 0;
case 's':
addr = optarg;
break;
default:
break;
}
}
acl::server_socket ss;
if (ss.open(addr) == false)
{
printf("listen %s error %s\r\n", addr.c_str(), acl::last_serror());
return 1;
}
printf("listen %s ok\r\n", addr.c_str());
fiber_server fs(ss);
fs.start(); // start listen fiber
acl::fiber::schedule(); // start fiber schedule
return 0;
}
```
###**示例三**
如果使用C++11的特性则示例二会更为简单如下
```c++
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
static void fiber_client(acl::socket_stream* conn)
{
printf("fiber-%d running\r\n", acl::fiber::self());
char buf[8192];
while (true)
{
int ret = conn->read(buf, sizeof(buf), false);
if (ret == -1)
break;
if (conn->write(buf, ret) == -1)
break;
}
delete conn;
}
static void fiber_server(acl::server_socket& ss)
{
while (true)
{
acl::socket_stream* conn = ss.accept();
if (conn == NULL)
{
printf("accept error %s\r\n", acl::last_serror());
break;
}
printf("accept ok, fd: %d\r\n", conn->sock_handle());
go[=] {
fiber_client(conn);
};
}
}
static void usage(const char* procname)
{
printf("usage: %s -h [help] -s listen_addr\r\n", procname);
}
int main(int argc, char *argv[])
{
int ch;
acl::acl_cpp_init();
acl::string addr("127.0.0.1:9006");
acl::log::stdout_open(true);
while ((ch = getopt(argc, argv, "hs:")) > 0)
{
switch (ch)
{
case 'h':
usage(argv[0]);
return 0;
case 's':
addr = optarg;
break;
default:
break;
}
}
acl::server_socket ss;
if (ss.open(addr) == false)
{
printf("listen %s error %s\r\n", addr.c_str(), acl::last_serror());
return 1;
}
printf("listen %s ok\r\n", addr.c_str());
go[&] {
fiber_server(ss);
};
acl::fiber::schedule(); // start fiber schedule
return 0;
}
```
###**参考**
- 网络协程编程http://zsxxsz.iteye.com/blog/2312043
- 用协程编写高并发网络服务http://zsxxsz.iteye.com/blog/2309654
- 使用协程方式编写高并发的WEB服务http://zsxxsz.iteye.com/blog/2309665

View File

@ -200,6 +200,7 @@ void fiber_save_errno(void)
}
#if defined(__x86_64__)
# if defined(__AVX__)
# define CLOBBER \
, "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7",\
@ -235,21 +236,50 @@ void fiber_save_errno(void)
# define LONGJMP(ctx) \
asm("movq (%%rax), %%rbx\n\t"\
"movq 8(%%rax), %%rbp\n\t"\
"movq 16(%%rax), %%r12\n\t"\
"movq 24(%%rax), %%rdx\n\t"\
"movq 32(%%rax), %%r13\n\t"\
"movq 40(%%rax), %%r14\n\t"\
"mov %%rdx, %%rsp\n\t"\
"movq 48(%%rax), %%r15\n\t"\
"movq 56(%%rax), %%rdx\n\t"\
"movq 64(%%rax), %%rdi\n\t"\
"movq 72(%%rax), %%rsi\n\t"\
"jmp *%%rdx\n\t"\
"movq 8(%%rax), %%rbp\n\t"\
"movq 16(%%rax), %%r12\n\t"\
"movq 24(%%rax), %%rdx\n\t"\
"movq 32(%%rax), %%r13\n\t"\
"movq 40(%%rax), %%r14\n\t"\
"mov %%rdx, %%rsp\n\t"\
"movq 48(%%rax), %%r15\n\t"\
"movq 56(%%rax), %%rdx\n\t"\
"movq 64(%%rax), %%rdi\n\t"\
"movq 72(%%rax), %%rsi\n\t"\
"jmp *%%rdx\n\t"\
: : "a" (ctx) : "rdx" \
)
#elif defined(__i386__)
# define SETJMP(ctx) ({\
int ret;\
asm("movl $LJMPRET%=, %%eax\n\t"\
"movl %%eax, (%%edx)\n\t"\
"movl %%ebx, 4(%%edx)\n\t"\
"movl %%esi, 8(%%edx)\n\t"\
"movl %%edi, 12(%%edx)\n\t"\
"movl %%ebp, 16(%%edx)\n\t"\
"movl %%esp, 20(%%edx)\n\t"\
"xorl %%eax, %%eax\n\t"\
"LJMPRET%=:\n\t"\
: "=a" (ret) : "d" (ctx) : "memory");\
ret;\
})
# define LONGJMP(ctx) \
asm("movl (%%eax), %%edx\n\t"\
"movl 4(%%eax), %%ebx\n\t"\
"movl 8(%%eax), %%esi\n\t"\
"movl 12(%%eax), %%edi\n\t"\
"movl 16(%%eax), %%ebp\n\t"\
"movl 20(%%eax), %%esp\n\t"\
"jmp *%%edx\n\t"\
: : "a" (ctx) : "edx" \
)
#else
# define SETJMP(ctx) \
sigsetjmp(ctx, 0)
# define LONGJMP(ctx) \

View File

@ -1,3 +1,8 @@
28) 2016.10.31
28.1) feature: fiber.c 中实现了 __i386__ 下 SETJMPLONGJMP 的汇编方式,从
libdill 借鉴而来
27) 2016.10.19
27.1) bugfix: fiber_io.c 中的 __thread_fiber->loop_fn 没有赋初值

View File

@ -268,7 +268,8 @@ int main(int argc, char *argv[])
.set_dbpass(dbpass)
.set_dblimit(cocurrent)
.set_conn_timeout(conn_timeout)
.set_rw_timeout(rw_timeout);
.set_rw_timeout(rw_timeout)
.set_charset("utf8");
// init mysql connections pool
acl::mysql_pool dbpool(dbconf);

View File

@ -0,0 +1,2 @@
include ../Makefile_cpp.in
PROG = server

View File

@ -0,0 +1,110 @@
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
class fiber_client : public acl::fiber
{
public:
fiber_client(acl::socket_stream* conn) : conn_(conn) {}
protected:
// @override
void run(void)
{
printf("fiber-%d-%d running\r\n", get_id(), acl::fiber::self());
char buf[8192];
while (true)
{
int ret = conn_->read(buf, sizeof(buf), false);
if (ret == -1)
break;
if (conn_->write(buf, ret) == -1)
break;
}
delete conn_;
delete this;
}
private:
acl::socket_stream* conn_;
~fiber_client(void) {}
};
class fiber_server : public acl::fiber
{
public:
fiber_server(acl::server_socket& ss) : ss_(ss) {}
~fiber_server(void) {}
protected:
// @override
void run(void)
{
while (true)
{
acl::socket_stream* conn = ss_.accept();
if (conn == NULL)
{
printf("accept error %s\r\n", acl::last_serror());
break;
}
printf("accept ok, fd: %d\r\n", conn->sock_handle());
// create one fiber for one connection
fiber_client* fc = new fiber_client(conn);
// start the fiber
fc->start();
continue;
}
}
private:
acl::server_socket& ss_;
};
static void usage(const char* procname)
{
printf("usage: %s -h [help] -s listen_addr\r\n", procname);
}
int main(int argc, char *argv[])
{
int ch;
acl::acl_cpp_init();
acl::string addr("127.0.0.1:9006");
acl::log::stdout_open(true);
while ((ch = getopt(argc, argv, "hs:")) > 0)
{
switch (ch)
{
case 'h':
usage(argv[0]);
return 0;
case 's':
addr = optarg;
break;
default:
break;
}
}
acl::server_socket ss;
if (ss.open(addr) == false)
{
printf("listen %s error %s\r\n", addr.c_str(), acl::last_serror());
return 1;
}
printf("listen %s ok\r\n", addr.c_str());
fiber_server fs(ss);
fs.start(); // start listen fiber
acl::fiber::schedule(); // start fiber schedule
return 0;
}

View File

@ -0,0 +1 @@
#include "stdafx.h"

View File

@ -0,0 +1,20 @@
// stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//
#pragma once
//#include <iostream>
//#include <tchar.h>
// TODO: 在此处引用程序要求的附加头文件
#include "lib_acl.h"
#include "acl_cpp/lib_acl.hpp"
#include "fiber/fiber.hpp"
#ifdef WIN32
#define snprintf _snprintf
#endif

View File

@ -0,0 +1,2 @@
include ../Makefile_cpp.in
PROG = server

View File

@ -0,0 +1,84 @@
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
static void fiber_client(acl::socket_stream* conn)
{
printf("fiber-%d running\r\n", acl::fiber::self());
char buf[8192];
while (true)
{
int ret = conn->read(buf, sizeof(buf), false);
if (ret == -1)
break;
if (conn->write(buf, ret) == -1)
break;
}
delete conn;
}
static void fiber_server(acl::server_socket& ss)
{
while (true)
{
acl::socket_stream* conn = ss.accept();
if (conn == NULL)
{
printf("accept error %s\r\n", acl::last_serror());
break;
}
printf("accept ok, fd: %d\r\n", conn->sock_handle());
go[=] {
fiber_client(conn);
};
}
}
static void usage(const char* procname)
{
printf("usage: %s -h [help] -s listen_addr\r\n", procname);
}
int main(int argc, char *argv[])
{
int ch;
acl::acl_cpp_init();
acl::string addr("127.0.0.1:9006");
acl::log::stdout_open(true);
while ((ch = getopt(argc, argv, "hs:")) > 0)
{
switch (ch)
{
case 'h':
usage(argv[0]);
return 0;
case 's':
addr = optarg;
break;
default:
break;
}
}
acl::server_socket ss;
if (ss.open(addr) == false)
{
printf("listen %s error %s\r\n", addr.c_str(), acl::last_serror());
return 1;
}
printf("listen %s ok\r\n", addr.c_str());
go[&] {
fiber_server(ss);
};
acl::fiber::schedule(); // start fiber schedule
return 0;
}

View File

@ -0,0 +1 @@
#include "stdafx.h"

View File

@ -0,0 +1,20 @@
// stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//
#pragma once
//#include <iostream>
//#include <tchar.h>
// TODO: 在此处引用程序要求的附加头文件
#include "lib_acl.h"
#include "acl_cpp/lib_acl.hpp"
#include "fiber/fiber.hpp"
#ifdef WIN32
#define snprintf _snprintf
#endif

View File

@ -1,202 +0,0 @@
SHELL = /bin/sh
CC = gcc
#CC = g++
CC = ${ENV_CC}
AR = ar
ARFL = rv
#ARFL = cru
RANLIB = ranlib
CFLAGS = -c -g -W \
-Wall \
-Wcast-qual \
-Waggregate-return \
-Wmissing-prototypes \
-Wpointer-arith \
-Wshadow \
-D_REENTRANT \
-D_POSIX_PTHREAD_SEMANTICS \
-D_USE_FAST_MACRO \
-Wno-long-long
#-pedantic
# -Wcast-align
#CFLAGS = -c -g -W -Wall -Wcast-qual -Wcast-align \
#-Waggregate-return -Wmissing-prototypes \
#-Wpointer-arith -Werror -Wshadow -O2 \
#-D_POSIX_PTHREAD_SEMANTICS -D_USE_FAST_MACRO
###########################################################
#Check system:
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
SYSLIB =
CHECKSYSRES = @echo "Unknow system type!";exit 1
UNIXNAME = $(shell uname -sm)
UNIXTYPE = LINUX
ifeq ($(CC),)
CC = gcc
endif
ifeq ($(findstring gcc, $(CC)), gcc)
CFLAGS += -Wstrict-prototypes
endif
ifeq ($(findstring clang, $(CC)), clang)
CFLAGS += -Wstrict-prototypes \
-Wno-invalid-source-encoding \
-Wno-extended-offsetof
endif
ifeq ($(findstring clang++, $(CC)), clang++)
CFLAGS += -Wno-invalid-source-encoding \
-Wno-extended-offsetof
endif
# For FreeBSD
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
CFLAGS += -DFREEBSD -fPIC -Werror
UNIXTYPE = FREEBSD
endif
# For Darwin
ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
CFLAGS += -DMACOSX -Wno-invalid-source-encoding \
-Wno-extended-offsetof -fPIC -Werror
UNIXTYPE = MACOSX
endif
# For Linux
ifeq ($(findstring Linux, $(UNIXNAME)), Linux)
CFLAGS += -DLINUX2 -fPIC -Werror
UNIXTYPE = LINUX
endif
# For MINGW
ifeq ($(findstring MINGW, $(UNIXNAME)), MINGW)
CFLAGS += -DLINUX2 -DMINGW
UNIXTYPE = LINUX
endif
# For SunOS
ifeq ($(findstring SunOS, $(UNIXNAME)), SunOS)
ifeq ($(findstring 86, $(UNIXNAME)), 86)
SYSLIB = -lsocket -lnsl -lrt
endif
ifeq ($(findstring sun4u, $(UNIXNAME)), sun4u)
SYSLIB = -lsocket -lnsl -lrt
endif
CFLAGS += -DSUNOS5 -fPIC -Werror
UNIXTYPE = SUNOS5
endif
# For HP-UX
ifeq ($(findstring HP-UX, $(UNIXNAME)), HP-UX)
CFLAGS += -DHP_UX -DHPUX11 -fPIC -Werror
UNIXTYPE = HPUX
endif
#Find system type.
ifneq ($(SYSPATH),)
CHECKSYSRES = @echo "System is $(shell uname -sm)"
endif
###########################################################
OUT_PATH = .
OBJ_PATH_DST = $(OUT_PATH)/debug
LIB_PATH_DST = $(OUT_PATH)/lib
BASE_PATH = .
INC_PATH_SRC = $(BASE_PATH)/include
SRC_PATH_SRC = $(BASE_PATH)/src
INC_COMPILE = -I$(INC_PATH_SRC) -I./src
CFLAGS += $(INC_COMPILE)
#Project's objs
BASE_SRC = $(wildcard $(SRC_PATH_SRC)/*.c)
HTTP_SRC = $(wildcard $(SRC_PATH_SRC)/http/*.c)
ICMP_SRC = $(wildcard $(SRC_PATH_SRC)/icmp/*.c)
SMTP_SRC = $(wildcard $(SRC_PATH_SRC)/smtp/*.c)
SOURCES_SRC = $(HTTP_SRC) $(ICMP_SRC) $(SMTP_SRC)
BASE_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(BASE_SRC)))
HTTP_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(HTTP_SRC)))
ICMP_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(ICMP_SRC)))
SMTP_OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(SMTP_SRC)))
OBJS_DST = $(BASE_OBJ) $(HTTP_OBJ) $(ICMP_OBJ) $(SMTP_OBJ)
###########################################################
LIB_ACL_PATH = ../lib_acl
CFLAGS += -I $(LIB_ACL_PATH)/include
STATIC_LIBNAME = lib_protocol.a
SHARED_LIBNAME = lib_protocol.so
###########################################################
.PHONY = static shared clean
COMPILE = $(CC) $(CFLAGS)
all: static shared
$(shell mkdir -p $(OBJ_PATH_DST))
static: $(OBJS_DST)
@echo 'creating $(LIB_PATH_DST)/$(STATIC_LIBNAME)'
$(AR) $(ARFL) $(LIB_PATH_DST)/$(STATIC_LIBNAME) $(OBJS_DST)
$(RANLIB) $(LIB_PATH_DST)/$(STATIC_LIBNAME)
@echo 'build $(LIB_PATH_DST)/$(STATIC_LIBNAME) ok!'
shared_ldflags = -l_acl -lrt -lpthread
shared: $(OBJS_DST)
@echo ''
@echo 'creating $(SHARED_LIBNAME)'
@if test -n "$(rpath)" && test "$(UNIXTYPE)" = "LINUX"; then \
echo "building for linux"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-L$(rpath) $(shared_ldflags) -Wl,-rpath,$(rpath); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "SUNOS5"; then \
echo "building for sunos5"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-R$(rpath) -L$(rpath) $(shared_ldflags); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "MACOSX"; then \
echo "building for Darwin"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-R$(rpath) -L$(rpath) -l_acl -lpthread; \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "FREEBSD"; then \
echo "building for FreeBSD"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \
-R$(rpath) -L$(rpath) -l_acl -lpthread; \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
else \
echo 'skip build $(SHARED_LIBNAME); usage: make shared rpath=xxx'; \
fi
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/%.c
$(COMPILE) $< -o $@
# http
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/http/%.c
$(COMPILE) $< -o $@
# icmp
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/icmp/%.c
$(COMPILE) $< -o $@
# smtp
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/smtp/%.c
$(COMPILE) $< -o $@
clean:
rm -f $(LIB_PATH_DST)/lib_protocol.a
rm -f $(LIB_PATH_DST)/lib_protocol.so
rm -f $(OBJS_DST)
all_lib: $(OBJS_DST)
@(cd debug; ar x ../../lib_acl/lib/lib_acl.a)
$(AR) $(ARFL) $(LIB_PATH_DST)/lib_protocol.a debug/*.o
$(RANLIB) $(LIB_PATH_DST)/lib_protocol.a
@(cd debug; rm -f `ar -t ../../lib_acl/lib/lib_acl.a`)

View File

@ -186,7 +186,7 @@ int main(int argc, char *argv[])
return (0);
*/
acl_init(); /* ³õʼ»¯ acl ¿â */
acl_lib_init(); /* ³õʼ»¯ acl ¿â */
ACL_SAFE_STRNCPY(method, "GET", sizeof(method));
url[0] = 0;

View File

@ -72,7 +72,7 @@ int main(int argc, char *argv[])
int ch, out = 0;
char url[256], dump[256], proxy[256], method[32];
acl_init(); /* ³õʼ»¯ acl ¿â */
acl_lib_init(); /* ³õʼ»¯ acl ¿â */
ACL_SAFE_STRNCPY(method, "GET", sizeof(method));
url[0] = 0;

View File

@ -23,7 +23,7 @@ int main(int argc, char *argv[])
int ch;
char url[256], dump[256];
acl_init(); /* ³õʼ»¯ acl ¿â */
acl_lib_init(); /* ³õʼ»¯ acl ¿â */
url[0] = 0;
dump[0] = 0;

View File

@ -5,12 +5,12 @@
static void init(void)
{
acl_init();
acl_lib_init();
}
static void end(void)
{
acl_end();
acl_lib_end();
}
static void thread_run(void *arg)

View File

@ -11,12 +11,12 @@ typedef struct {
static void init(void)
{
acl_init();
acl_lib_init();
}
static void end(void)
{
acl_end();
acl_lib_end();
}
static void thread_run(void *arg)

View File

@ -9,7 +9,7 @@ int main(int argc, char *argv[])
{
int ret, i;
acl_init();
acl_lib_init();
if (argc != 2) {
printf("usage: %s conf_file\n", argv[0]);