Browse Source

better apis and Makefiles

ithewei 5 years ago
parent
commit
7d614897a7
23 changed files with 218 additions and 143 deletions
  1. 3 0
      BUILD.md
  2. 36 10
      Makefile
  3. 54 49
      Makefile.in
  4. 17 19
      Makefile.vars
  5. 10 12
      README.md
  6. 1 1
      base/RAII.cpp
  7. 2 2
      base/hproc.h
  8. 1 1
      base/htime.c
  9. 1 1
      base/htime.h
  10. 4 4
      base/hversion.c
  11. 10 12
      base/hversion.h
  12. 0 0
      base/ifconfig.cpp
  13. 0 0
      base/ifconfig.h
  14. 26 0
      config.mk
  15. 5 4
      docs/apis.md
  16. 18 0
      event/hloop.c
  17. 20 0
      event/hloop.h
  18. 1 19
      event/iowatcher.h
  19. 2 2
      examples/hmain_test.cpp
  20. 2 2
      examples/httpd/httpd.cpp
  21. 1 1
      http/server/HttpServer.cpp
  22. 2 2
      utils/hmain.cpp
  23. 2 2
      winbuild/libhv/libhv.vcxproj

+ 3 - 0
BUILD.md

@@ -5,6 +5,9 @@
 
 gcc4.8+, msvc2013+
 
+## Dependencies
+modify config.mk
+
 ## Unix
 ```
 ./configure

+ 36 - 10
Makefile

@@ -1,23 +1,49 @@
+include config.mk
 include Makefile.vars
 
 MAKEF=$(MAKE) -f Makefile.in
 
+ALL_SRCDIRS=. base utils event protocol http http/client http/server consul examples
+
+LIBHV_SRCDIRS = . base utils event
+LIBHV_HEADERS = hv.h hconfig.h
+LIBHV_HEADERS += $(BASE_HEADERS) $(UTILS_HEADERS) $(EVENT_HEADERS)
+
+ifeq ($(WITH_PROTOCOL), yes)
+LIBHV_HEADERS += $(PROTOCOL_HEADERS)
+LIBHV_SRCDIRS += protocol
+endif
+
+ifeq ($(WITH_HTTP), yes)
+LIBHV_HEADERS += $(HTTP_HEADERS)
+LIBHV_SRCDIRS += http
+ifeq ($(WITH_HTTP_SERVER), yes)
+LIBHV_SRCDIRS += http/server
+endif
+ifeq ($(WITH_HTTP_CLIENT), yes)
+LIBHV_SRCDIRS += http/client
+ifeq ($(WITH_CONSUL), yes)
+LIBHV_SRCDIRS += consul
+endif
+endif
+endif
+
 default: all
 all: libhv examples
 examples: test timer loop tcp udp nc nmap httpd curl consul_cli
 
 clean:
-	$(MAKEF) clean SRCDIRS=". base utils event http http/client http/server protocol consul examples"
+	$(MAKEF) clean SRCDIRS="$(ALL_SRCDIRS)"
+	$(RM) include/hv
 
 prepare:
 	$(MKDIR) bin
 
 libhv:
 	$(MKDIR) lib
-	$(MAKEF) TARGET=$@ TARGET_TYPE=SHARED SRCDIRS=". base utils event http http/client http/server protocol"
-	$(MAKEF) TARGET=$@ TARGET_TYPE=STATIC SRCDIRS=". base utils event http http/client http/server protocol"
+	$(MAKEF) TARGET=$@ TARGET_TYPE="SHARED|STATIC" SRCDIRS="$(LIBHV_SRCDIRS)"
 	$(MKDIR) include/hv
-	$(CP) $(INSTALL_HEADERS) include/hv
+	$(CP) $(LIBHV_HEADERS) include/hv
 
 install:
 	$(MKDIR) $(INSTALL_INCDIR)
@@ -45,9 +71,9 @@ nc: prepare
 nmap: prepare
 ifeq ($(OS), Windows)
 	# for nmap on Windows platform, recommand EVENT_POLL, not EVENT_IOCP
-	$(MAKEF) TARGET=$@ SRCDIRS=". base event" SRCS="examples/nmap.cpp" DEFINES="$(DEFINES) PRINT_DEBUG EVENT_POLL"
+	$(MAKEF) TARGET=$@ SRCDIRS=". base event" SRCS="examples/nmap.cpp" DEFINES="PRINT_DEBUG EVENT_POLL"
 else
-	$(MAKEF) TARGET=$@ SRCDIRS=". base event" SRCS="examples/nmap.cpp" DEFINES="$(DEFINES) PRINT_DEBUG"
+	$(MAKEF) TARGET=$@ SRCDIRS=". base event" SRCS="examples/nmap.cpp" DEFINES="PRINT_DEBUG"
 endif
 
 httpd: prepare
@@ -56,10 +82,10 @@ httpd: prepare
 
 curl: prepare
 	$(MAKEF) TARGET=$@ SRCDIRS="$(CURL_SRCDIRS)" SRCDIRS=". base utils http http/client" SRCS="examples/curl.cpp"
-	#$(MAKEF) TARGET=$@ SRCDIRS="$(CURL_SRCDIRS)" SRCDIRS=". base utils http http/client" SRCS="examples/curl.cpp" DEFINES="$(DEFINES) WITH_CURL CURL_STATICLIB"
+	# $(MAKEF) TARGET=$@ SRCDIRS="$(CURL_SRCDIRS)" SRCDIRS=". base utils http http/client" SRCS="examples/curl.cpp" WITH_CURL=yes DEFINES="CURL_STATICLIB"
 
 consul_cli: prepare
-	$(MAKEF) TARGET=$@ SRCDIRS=". base utils http http/client consul" SRCS="examples/consul_cli.cpp" DEFINES="$(DEFINES) PRINT_DEBUG"
+	$(MAKEF) TARGET=$@ SRCDIRS=". base utils http http/client consul" SRCS="examples/consul_cli.cpp" DEFINES="PRINT_DEBUG"
 
 unittest: prepare
 	$(CC)  -g -Wall -std=c99   -I. -Ibase            -o bin/hmutex_test       unittest/hmutex_test.c        -pthread
@@ -70,11 +96,11 @@ unittest: prepare
 	$(CXX) -g -Wall -std=c++11 -I. -Ibase            -o bin/threadpool_test   unittest/threadpool_test.cpp  -pthread
 	$(CXX) -g -Wall -std=c++11 -I. -Ibase            -o bin/objectpool_test   unittest/objectpool_test.cpp  -pthread
 	$(CXX) -g -Wall -std=c++11 -I. -Ibase            -o bin/ls                unittest/listdir_test.cpp     base/hdir.cpp base/hbase.c
-	$(CXX) -g -Wall -std=c++11 -I. -Ibase -Iutils    -o bin/ifconfig          unittest/ifconfig_test.cpp    utils/ifconfig.cpp
+	$(CXX) -g -Wall -std=c++11 -I. -Ibase -Iutils    -o bin/ifconfig          unittest/ifconfig_test.cpp    base/ifconfig.cpp
 	$(CC)  -g -Wall -std=c99   -I. -Ibase -Iprotocol -o bin/nslookup          unittest/nslookup_test.c      protocol/dns.c
 	$(CC)  -g -Wall -std=c99   -I. -Ibase -Iprotocol -o bin/ping              unittest/ping_test.c          protocol/icmp.c base/hsocket.c base/htime.c -DPRINT_DEBUG
 	$(CC)  -g -Wall -std=c99   -I. -Ibase -Iprotocol -o bin/ftp               unittest/ftp_test.c           protocol/ftp.c  base/hsocket.c
-	$(CC)  -g -Wall -std=c99   -I. -Ibase -Iutils -Iprotocol -o bin/sendmail  unittest/sendmail_test.c  protocol/smtp.c base/hsocket.c utils/base64.c
+	$(CC)  -g -Wall -std=c99   -I. -Ibase -Iutils -Iprotocol -o bin/sendmail  unittest/sendmail_test.c      protocol/smtp.c base/hsocket.c utils/base64.c
 
 # UNIX only
 webbench: prepare

+ 54 - 49
Makefile.in

@@ -10,18 +10,24 @@
 # LDFLAGS  += $(addprefix -l, $(LIBS))
 #
 # Usage:
-# make all TARGET=libxx TARGET_TYPE=SHARED \
+# make all \
+# TARGET=libxx \
+# TARGET_TYPE=SHARED \
 # CROSS_COMPILE=arm-linux-androideabi- \
+# SRCDIRS="src/base src/event" \
+# INCDIRS="src/utils" \
+# SRCS="src/utils/hmain.cpp src/utils/iniparser.cpp" \
 # DEFINES=USE_OPENCV \
 # LIBS="opencv_core opencv_highgui"
 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+-include config.mk
 
 # VARIABLES
-TARGET=test
-#BUILD_TYPE=DEBUG,RELEASE
-BUILD_TYPE=RELEASE
-#TARGET_TYPE=EXECUTABLE,SHARED,STATIC
-TARGET_TYPE=EXECUTABLE
+TARGET ?= test
+# BUILD_TYPE=DEBUG,RELEASE
+BUILD_TYPE ?= RELEASE
+# TARGET_TYPE=EXECUTABLE,SHARED,STATIC,SHARED|STATIC
+TARGET_TYPE ?= EXECUTABLE
 
 # COMMANDS
 ifdef CROSS_COMPILE
@@ -33,8 +39,6 @@ LD	= $(CROSS_COMPILE)ld
 AR	= $(CROSS_COMPILE)ar
 NM	= $(CROSS_COMPILE)nm
 STRIP 	= $(CROSS_COMPILE)strip
-OBJCOPY	= $(CROSS_COMPILE)objcopy
-OBJDUMP	= $(CROSS_COMPILE)objdump
 endif
 
 MKDIR = -mkdir -p 2>/dev/null
@@ -62,39 +66,37 @@ endif
 ifeq ($(BUILD_TYPE), DEBUG)
 	DEFAULT_CFLAGS = -g -Wall
 endif
-DEFAULT_CFLAGS += -O3 -fPIC
+DEFAULT_CFLAGS += -O3
 
-ifndef CFLAGS
-CFLAGS := $(DEFAULT_CFLAGS) -std=c99
-else
+CFLAGS ?= $(DEFAULT_CFLAGS)
+CXXFLAGS ?= $(DEFAULT_CFLAGS)
+
+ifneq ($(OS), Windows)
 ifeq ($(findstring -fPIC, $(CFLAGS)), )
 override CFLAGS += -fPIC
 endif
-ifeq ($(findstring -std, $(CFLAGS)), )
-override CFLAGS += -std=c99
+ifeq ($(findstring -fPIC, $(CXXFLAGS)), )
+override CXXFLAGS += -fPIC
 endif
 endif
 
-ifndef CXXFLAGS
-CXXFLAGS := $(DEFAULT_CFLAGS) -std=c++11
-else
-ifeq ($(findstring -fPIC, $(CXXFLAGS)), )
-override CXXFLAGS += -fPIC
+ifeq ($(findstring -std, $(CFLAGS)), )
+override CFLAGS += -std=c99
 endif
+
 ifeq ($(findstring -std, $(CXXFLAGS)), )
 override CXXFLAGS += -std=c++11
 endif
-endif
 
-ifndef ARFLAGS
-ARFLAGS := cr
-endif
+ARFLAGS ?= cr
 
 # DIRS
-PREFIX = install
 ifeq ($(OS), Linux)
-	PREFIX = /usr/local
+	PREFIX ?= /usr/local
+else
+	PREFIX ?= install
 endif
+
 INCDIR = include
 LIBDIR = lib
 SRCDIR = src
@@ -102,7 +104,7 @@ BINDIR = bin
 DEPDIR = 3rd
 CONFDIR = etc
 DISTDIR = dist
-DOCDIR  = doc
+DOCDIR  = docs
 
 SRCDIRS += $(shell find $(SRCDIR) -type d)
 override INCDIRS += $(INCDIR) $(DEPDIR) $(DEPDIR)/include
@@ -116,10 +118,6 @@ ifeq ($(TARGET_TYPE), SHARED)
 endif
 endif
 
-ifeq ($(TARGET_TYPE), STATIC)
-	CPPFLAGS += -DHV_STATICLIB
-endif
-
 ifeq ($(BUILD_TYPE), DEBUG)
 	CPPFLAGS += -DDEBUG
 else
@@ -134,24 +132,32 @@ CPPFLAGS += $(addprefix -I, $(SRCDIRS))
 ifeq ($(OS), Windows)
 	LDFLAGS += -static-libgcc -static-libstdc++
 endif
-ifneq ($(findstring WITH_CURL, $(DEFINES)), )
-override LIBS += curl
+
+ifeq ($(WITH_CURL), yes)
+	CPPFLAGS += -DWITH_CURL
+	LDFLAGS += -lcurl
 ifeq ($(OS), Windows)
-LIBS += wldap32 advapi32 crypt32
+	LDFLAGS += -lwldap32 -ladvapi32 -lcrypt32
 endif
 endif
-ifneq ($(findstring WITH_NGHTTP2, $(DEFINES)), )
-override LIBS += nghttp2
+
+ifeq ($(WITH_NGHTTP2), yes)
+	CPPFLAGS += -DWITH_NGHTTP2
+	LDFLAGS += -lnghttp2
 endif
-ifneq ($(findstring WITH_OPENSSL, $(DEFINES)), )
-override LIBS += ssl crypto
+
+ifeq ($(WITH_OPENSSL), yes)
+	CPPFLAGS += -DWITH_OPENSSL
+	LDFLAGS += -lssl -lcrypto
 endif
+
 LDFLAGS += $(addprefix -L, $(LIBDIRS))
 LDFLAGS += $(addprefix -l, $(LIBS))
 
 ifeq ($(OS), Windows)
 	LDFLAGS += -lwinmm -liphlpapi -lws2_32
-ifneq ($(findstring WITH_WINDUMP, $(DEFINES)), )
+ifeq ($((ENABLE_WINDUMP), yes)
+	CPPFLAGS += -DENABLE_WINDUMP
 	LDFLAGS += -ldbghelp
 endif
 	LDFLAGS += -Wl,-Bstatic -lstdc++ -lpthread -lm
@@ -170,9 +176,9 @@ override SRCS += $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c $(dir)/*.cc $(
 ifeq ($(SRCS), )
 	SRCS = $(wildcard *.c *.cc *.cpp)
 endif
-#OBJS += $(patsubst %.c, %.o, $(SRCS))
-#OBJS += $(patsubst %.cc, %.o, $(SRCS))
-#OBJS += $(patsubst %.cpp, %.o, $(SRCS))
+# OBJS += $(patsubst %.c, %.o, $(SRCS))
+# OBJS += $(patsubst %.cc, %.o, $(SRCS))
+# OBJS += $(patsubst %.cpp, %.o, $(SRCS))
 OBJS := $(addsuffix .o, $(basename $(SRCS)))
 
 INSTALLED_INCS=$(addprefix $(PREFIX)/$(INCDIR)/, $(shell ls $(INCDIR)))
@@ -201,9 +207,9 @@ $(info BUILD_TYPE       = $(BUILD_TYPE))
 $(info SRCS=$(SRCS))
 $(info OBJS=$(OBJS))
 
-#$(info INSTALLED_INCS=$(INSTALLED_INCS))
-#$(info INSTALLED_LIBS=$(INSTALLED_LIBS))
-#$(info INSTALLED_BINS=$(INSTALLED_BINS))
+# $(info INSTALLED_INCS=$(INSTALLED_INCS))
+# $(info INSTALLED_LIBS=$(INSTALLED_LIBS))
+# $(info INSTALLED_BINS=$(INSTALLED_BINS))
 
 default: all
 
@@ -213,14 +219,15 @@ prepare:
 	$(MKDIR) $(BINDIR) $(LIBDIR)
 
 $(TARGET): $(OBJS)
-ifeq ($(TARGET_TYPE), SHARED)
+ifneq ($(findstring SHARED, $(TARGET_TYPE)), )
 ifeq ($(OS), Windows)
 	$(CC) -shared $^ -o $(LIBDIR)/$@.dll $(LDFLAGS) -Wl,--output-def,$(LIBDIR)/$(@).def
 else
 	$(CC) -shared $^ -o $(LIBDIR)/$@.so $(LDFLAGS)
 endif
-else
-ifeq ($(TARGET_TYPE), STATIC)
+endif
+
+ifneq ($(findstring STATIC, $(TARGET_TYPE)), )
 	$(AR) $(ARFLAGS) $(LIBDIR)/$@.a $^
 else
 ifeq ($(OS), Windows)
@@ -229,7 +236,6 @@ else
 	$(CC) $^ -o $(BINDIR)/$@ $(LDFLAGS)
 endif
 endif
-endif
 
 clean:
 	$(RM) $(OBJS)
@@ -254,4 +260,3 @@ undist:
 	$(RM) $(DISTDIR)
 
 .PHONY: default all prepare clean install uninstall dist undist
-

+ 17 - 19
Makefile.vars

@@ -5,10 +5,7 @@ RM = -rm -r 2>/dev/null
 INSTALL_INCDIR=/usr/local/include/hv
 INSTALL_LIBDIR=/usr/local/lib
 
-INSTALL_HEADERS=hv.h\
-				\
-				hconfig.h\
-				base/hplatform.h\
+BASE_HEADERS =  base/hplatform.h\
 				\
 				base/hdef.h\
 				base/hversion.h\
@@ -35,30 +32,31 @@ INSTALL_HEADERS=hv.h\
 				base/hscope.h\
 				base/hthreadpool.h\
 				base/hobjectpool.h\
-				\
-				utils/base64.h\
+				base/ifconfig.h\
+
+UTILS_HEADERS = utils/base64.h\
 				utils/md5.h\
 				utils/json.hpp\
 				utils/singleton.h\
-				utils/ifconfig.h\
 				utils/iniparser.h\
 				utils/hendian.h\
 				utils/hmain.h\
-				\
-				event/hloop.h\
+
+EVENT_HEADERS = event/hloop.h\
 				event/nlog.h\
 				event/nmap.h\
-				\
-				http/httpdef.h\
+
+PROTOCOL_HEADERS =  protocol/icmp.h\
+					protocol/dns.h\
+					protocol/ftp.h\
+					protocol/smtp.h
+
+HTTP_HEADERS =  http/httpdef.h\
 				http/http2def.h\
 				http/grpcdef.h\
 				http/http_content.h\
 				http/HttpMessage.h\
-				http/client/http_client.h\
-				http/server/HttpService.h\
-				http/server/HttpServer.h\
-				\
-				protocol/icmp.h\
-				protocol/dns.h\
-				protocol/ftp.h\
-				protocol/smtp.h
+
+HTTP_CLIENT_HEADERS = http/client/http_client.h
+
+HTTP_SERVER_HEADERS = http/server/HttpService.h http/server/HttpServer.h

+ 10 - 12
README.md

@@ -10,8 +10,8 @@ but simpler apis and richer protocols.
 
 - cross-platform (Linux, Windows, Mac)
 - event-loop (IO, timer, idle)
-- enable IPv6
-- with OpenSSL
+- ENABLE_IPV6
+- WITH_OPENSSL
 - http client/server (include https http1/x http2 grpc)
 - http web service, indexof service, api service (support RESTful API)
 - protocols
@@ -34,7 +34,7 @@ but simpler apis and richer protocols.
 
 ### HTTP
 #### http server
-see examples/httpd/httpd.cpp
+see `examples/httpd/httpd.cpp`
 ```c++
 #include "HttpServer.h"
 
@@ -56,7 +56,7 @@ int main() {
 }
 ```
 #### http client
-see examples/curl.cpp
+see `examples/curl.cpp`
 ```c++
 #include "http_client.h"
 
@@ -117,7 +117,7 @@ bin/webbench -c 2 -t 60 localhost:8080
 ![libhv-vs-nginx.png](html/downloads/libhv-vs-nginx.png)
 
 ### EventLoop
-see examples/tcp.c examples/udp.c
+see `examples/tcp.c` `examples/udp.c`
 ```c
 // TCP echo server
 #include "hloop.h"
@@ -201,7 +201,7 @@ https is the best example.
 ```
 sudo apt-get install openssl libssl-dev # ubuntu
 make clean
-make libhv httpd curl DEFINES=WITH_OPENSSL
+make libhv httpd curl WITH_OPENSSL=yes
 # editor etc/httpd.conf => ssl = on
 bin/httpd -d
 bin/curl -v https://localhost:8080
@@ -209,21 +209,19 @@ curl -v https://localhost:8080 --insecure
 ```
 
 #### compile WITH_CURL
-- make DEFINES="WITH_CURL CURL_STATICLIB"
+- make WITH_CURL=yes DEFINES="CURL_STATICLIB"
 
 #### compile WITH_NGHTTP2
 ```
 sudo apt-get install libnghttp2-dev # ubuntu
 make clean
-make libhv httpd curl DEFINES=WITH_NGHTTP2
+make libhv httpd curl WITH_NGHTTP2=yes
 bin/httpd -d
 bin/curl -v localhost:8080 --http2
 ```
 
 #### other options
-- ENABLE_IPV6
-- WITH_WINDUMP
-- USE_MULTIMAP
+see config.mk
 
 ### echo-servers
 ```shell
@@ -276,11 +274,11 @@ In general, the performance of these libraries are similar, each has its own adv
 - hscope.h:      作用域RAII机制
 - hthreadpool.h: 线程池
 - hobjectpool.h: 对象池
+- ifconfig.h:    ifconfig实现
 
 ### utils
 - hmain.h:       main_ctx: arg env
 - hendian.h:     大小端
-- ifconfig.h:    ifconfig实现
 - iniparser.h:   ini解析
 - singleton.h:   单例模式
 - md5.h

+ 1 - 1
base/RAII.cpp

@@ -1,7 +1,7 @@
 #include "hplatform.h"
 
 #ifdef OS_WIN
-#ifdef WITH_WINDUMP
+#ifdef ENABLE_WINDUMP
 #include <dbghelp.h>
 #ifdef _MSC_VER
 #pragma comment(lib,"dbghelp.lib")

+ 2 - 2
base/hproc.h

@@ -16,7 +16,7 @@ typedef struct proc_ctx_s {
 
 #ifdef OS_UNIX
 // unix use multi-processes
-static inline int spawn_proc(proc_ctx_t* ctx) {
+static inline int hproc_spawn(proc_ctx_t* ctx) {
     pid_t pid = fork();
     if (pid < 0) {
         perror("fork");
@@ -54,7 +54,7 @@ static void win_thread(void* userdata) {
         ctx->exit(ctx->exit_userdata);
     }
 }
-static inline int spawn_proc(proc_ctx_t* ctx) {
+static inline int hproc_spawn(proc_ctx_t* ctx) {
     HANDLE h = (HANDLE)_beginthread(win_thread, 0, ctx);
     if (h == NULL) {
         return -1;

+ 1 - 1
base/htime.c

@@ -249,7 +249,7 @@ const char* weekday_itoa(int weekday) {
     return s_weekdays[weekday];
 }
 
-datetime_t get_compile_datetime() {
+datetime_t hv_compile_datetime() {
     static datetime_t dt;
     char month[32];
     sscanf(__DATE__, "%s %d %d", month, &dt.day, &dt.year);

+ 1 - 1
base/htime.h

@@ -134,7 +134,7 @@ const char* month_itoa(int month);
 int weekday_atoi(const char* weekday);
 const char* weekday_itoa(int weekday);
 
-datetime_t get_compile_datetime();
+datetime_t hv_compile_datetime();
 
 #ifdef __cplusplus
 } // extern "C"

+ 4 - 4
base/hversion.c

@@ -2,11 +2,11 @@
 
 #include "htime.h"
 
-const char* get_compile_version() {
-    static char s_version[64] = {0};
-    datetime_t dt = get_compile_datetime();
+const char* hv_compile_version() {
+    static char s_version[16] = {0};
+    datetime_t dt = hv_compile_datetime();
     snprintf(s_version, sizeof(s_version), "%d.%d.%d.%d",
-        H_VERSION_MAJOR, dt.year%100, dt.month, dt.day);
+        HV_VERSION_MAJOR, dt.year%100, dt.month, dt.day);
     return s_version;
 }
 

+ 10 - 12
base/hversion.h

@@ -7,24 +7,22 @@ extern "C" {
 
 #include "hdef.h"
 
-#define H_VERSION_MAJOR   1
-#define H_VERSION_MINOR   18
-#define H_VERSION_MICRO   5
-#define H_VERSION_PATCH   2
+#define HV_VERSION_MAJOR    1
+#define HV_VERSION_MINOR    20
+#define HV_VERSION_PATCH    3
 
-#define H_VERSION_STRING    STRINGIFY(H_VERSION_MAJOR) "." \
-                            STRINGIFY(H_VERSION_MINOR) "." \
-                            STRINGIFY(H_VERSION_MICRO) "." \
-                            STRINGIFY(H_VERSION_PATCH)
+#define HV_VERSION_STRING   STRINGIFY(HV_VERSION_MAJOR) "." \
+                            STRINGIFY(HV_VERSION_MINOR) "." \
+                            STRINGIFY(HV_VERSION_PATCH)
 
-#define H_VERSION_NUMBER    (H_VERSION_MAJOR << 24) | (H_VERSION_MINOR << 16) | (H_VERSION_MICRO << 8) | H_VERSION_PATCH
+#define HV_VERSION_NUMBER   ((HV_VERSION_MAJOR << 16) | (HV_VERSION_MINOR << 8) | HV_VERSION_PATCH)
 
 
-static inline const char* get_static_version() {
-    return H_VERSION_STRING;
+static inline const char* hv_version() {
+    return HV_VERSION_STRING;
 }
 
-const char* get_compile_version();
+const char* hv_compile_version();
 
 // 1.2.3.4 => 0x01020304
 int version_atoi(const char* str);

+ 0 - 0
utils/ifconfig.cpp → base/ifconfig.cpp


+ 0 - 0
utils/ifconfig.h → base/ifconfig.h


+ 26 - 0
config.mk

@@ -0,0 +1,26 @@
+# modules
+# include icmp dns ftp smtp
+WITH_PROTOCOL=yes
+
+WITH_HTTP=yes
+WITH_HTTP_SERVER=yes
+WITH_HTTP_CLIENT=yes
+
+# WITH_CONSUL need WITH_HTTP_CLIENT=yes
+WITH_CONSUL=yes
+
+# features
+# base/hsocket.c: replace gethostbyname with getaddrinfo
+ENABLE_IPV6=no
+# base/RAII.cpp: Windows MiniDumpWriteDump
+ENABLE_WINDUMP=no
+# http/http_content.h: QueryParams,MultiPart
+USE_MULTIMAP=no
+
+# dependencies
+# for http/client
+WITH_CURL=no
+# for http2
+WITH_NGHTTP2=no
+# for SSL/TLS
+WITH_OPENSSL=no

+ 5 - 4
docs/apis.md

@@ -1,7 +1,8 @@
 #  c
 ## functions
 ### hversion.h
-- get_compile_version
+- hv_version
+- hv_compile_version
 - version_atoi
 - version_itoa
 
@@ -36,7 +37,7 @@
 - gethrtime
 - sleep
 - msleep
-- get_compile_datetime
+- hv_compile_datetime
 - days_of_month
 - month_atoi
 - month_itoa
@@ -88,7 +89,7 @@
 - so_rcvtimeo
 
 ### hproc.h
-- spawn_proc
+- hproc_spawn
 
 ### hthread.h
 - gettid
@@ -107,8 +108,8 @@
 - hloop_pause
 - hloop_resume
 - hloop_now
-- hloop_now_hrtime
 - hloop_now_ms
+- hloop_now_hrtime
 - hloop_update_time
 - hloop_set_userdata
 - hloop_userdata

+ 18 - 0
event/hloop.c

@@ -419,6 +419,24 @@ void htimer_del(htimer_t* timer) {
     EVENT_DEL(timer);
 }
 
+const char* hio_engine() {
+#ifdef EVENT_SELECT
+    return  "select";
+#elif defined(EVENT_POLL)
+    return  "poll";
+#elif defined(EVENT_EPOLL)
+    return  "epoll";
+#elif defined(EVENT_KQUEUE)
+    return  "kqueue";
+#elif defined(EVENT_IOCP)
+    return  "iocp";
+#elif defined(EVENT_PORT)
+    return  "evport";
+#else
+    return  "noevent";
+#endif
+}
+
 void hio_init(hio_t* io) {
     memset(io, 0, sizeof(hio_t));
     io->event_type = HEVENT_TYPE_IO;

+ 20 - 0
event/hloop.h

@@ -147,6 +147,26 @@ void        htimer_reset(htimer_t* timer);
 #define READ_EVENT  0x0001
 #define WRITE_EVENT 0x0004
 #define ALL_EVENTS  READ_EVENT|WRITE_EVENT
+/*
+const char* hio_engine() {
+#ifdef EVENT_SELECT
+    return  "select";
+#elif defined(EVENT_POLL)
+    return  "poll";
+#elif defined(EVENT_EPOLL)
+    return  "epoll";
+#elif defined(EVENT_KQUEUE)
+    return  "kqueue";
+#elif defined(EVENT_IOCP)
+    return  "iocp";
+#elif defined(EVENT_PORT)
+    return  "evport";
+#else
+    return  "noevent";
+#endif
+}
+*/
+const char* hio_engine();
 hio_t* hio_get(hloop_t* loop, int fd);
 int    hio_add(hio_t* io, hio_cb cb, int events DEFAULT(READ_EVENT));
 int    hio_del(hio_t* io, int events DEFAULT(ALL_EVENTS));

+ 1 - 19
event/iowatcher.h

@@ -12,7 +12,7 @@
     !defined(EVENT_PORT) &&     \
     !defined(EVENT_NOEVENT)
 #ifdef OS_WIN
-//#define EVENT_IOCP // IOCP improving
+// #define EVENT_IOCP // IOCP improving
 #define EVENT_POLL
 #elif defined(OS_LINUX)
 #define EVENT_EPOLL
@@ -25,24 +25,6 @@
 #endif
 #endif
 
-static inline const char* iowatcher_name() {
-#ifdef EVENT_SELECT
-    return  "select";
-#elif defined(EVENT_POLL)
-    return  "poll";
-#elif defined(EVENT_EPOLL)
-    return  "epoll";
-#elif defined(EVENT_KQUEUE)
-    return  "kqueue";
-#elif defined(EVENT_IOCP)
-    return  "iocp";
-#elif defined(EVENT_PORT)
-    return  "evport";
-#else
-    return  "noevent";
-#endif
-}
-
 int iowatcher_init(hloop_t* loop);
 int iowatcher_cleanup(hloop_t* loop);
 int iowatcher_add_event(hloop_t* loop, int fd, int events);

+ 2 - 2
examples/hmain_test.cpp

@@ -49,7 +49,7 @@ static const char detail_options[] = R"(
 )";
 
 void print_version() {
-    printf("%s version %s\n", g_main_ctx.program_name, get_compile_version());
+    printf("%s version %s\n", g_main_ctx.program_name, hv_compile_version());
 }
 
 void print_help() {
@@ -124,7 +124,7 @@ int parse_confile(const char* confile) {
         logger_enable_fsync(hlog, getboolean(str.c_str()));
     }
     // first log here
-    hlogi("%s version: %s", g_main_ctx.program_name, get_compile_version());
+    hlogi("%s version: %s", g_main_ctx.program_name, hv_compile_version());
     hlog_fsync();
 
     // worker_processes

+ 2 - 2
examples/httpd/httpd.cpp

@@ -38,7 +38,7 @@ static const char detail_options[] = R"(
 )";
 
 void print_version() {
-    printf("%s version %s\n", g_main_ctx.program_name, get_compile_version());
+    printf("%s version %s\n", g_main_ctx.program_name, hv_compile_version());
 }
 
 void print_help() {
@@ -86,7 +86,7 @@ int parse_confile(const char* confile) {
     if (!str.empty()) {
         hlog_set_remain_days(atoi(str.c_str()));
     }
-    hlogi("%s version: %s", g_main_ctx.program_name, get_compile_version());
+    hlogi("%s version: %s", g_main_ctx.program_name, hv_compile_version());
 
     // worker_processes
     int worker_processes = 0;

+ 1 - 1
http/server/HttpServer.cpp

@@ -131,7 +131,7 @@ handle_request:
     // Server:
     static char s_Server[64] = {'\0'};
     if (s_Server[0] == '\0') {
-        snprintf(s_Server, sizeof(s_Server), "httpd/%s", get_compile_version());
+        snprintf(s_Server, sizeof(s_Server), "httpd/%s", hv_compile_version());
     }
     res->headers["Server"] = s_Server;
     // Connection:

+ 2 - 2
utils/hmain.cpp

@@ -381,7 +381,7 @@ void signal_handler(int signo) {
             for (int i = 0; i < g_worker_processes_num; ++i) {
                 if (g_worker_processes[i].pid == pid) {
                     g_worker_processes[i].pid = -1;
-                    spawn_proc(&g_worker_processes[i]);
+                    hproc_spawn(&g_worker_processes[i]);
                     break;
                 }
             }
@@ -594,7 +594,7 @@ int master_workers_run(procedure_t worker_fn, void* worker_userdata,
         for (int i = 0; i < g_worker_processes_num; ++i, ++ctx) {
             ctx->init = worker_init;
             ctx->proc = worker_proc;
-            spawn_proc(ctx);
+            hproc_spawn(ctx);
             hlogi("workers[%d] start/running, pid=%d", i, ctx->pid);
         }
         g_main_ctx.pid = getpid();

+ 2 - 2
winbuild/libhv/libhv.vcxproj

@@ -159,6 +159,7 @@
     <ClInclude Include="..\..\base\hurl.h" />
     <ClInclude Include="..\..\base\hvar.h" />
     <ClInclude Include="..\..\base\hversion.h" />
+    <ClInclude Include="..\..\base\ifconfig.h" />
     <ClInclude Include="..\..\base\list.h" />
     <ClInclude Include="..\..\base\netinet.h" />
     <ClInclude Include="..\..\base\queue.h" />
@@ -197,7 +198,6 @@
     <ClInclude Include="..\..\utils\hgl.h" />
     <ClInclude Include="..\..\utils\hmain.h" />
     <ClInclude Include="..\..\utils\htask.h" />
-    <ClInclude Include="..\..\utils\ifconfig.h" />
     <ClInclude Include="..\..\utils\iniparser.h" />
     <ClInclude Include="..\..\utils\json.hpp" />
     <ClInclude Include="..\..\utils\md5.h" />
@@ -214,6 +214,7 @@
     <ClCompile Include="..\..\base\htime.c" />
     <ClCompile Include="..\..\base\hurl.cpp" />
     <ClCompile Include="..\..\base\hversion.c" />
+    <ClCompile Include="..\..\base\ifconfig.cpp" />
     <ClCompile Include="..\..\base\RAII.cpp" />
     <ClCompile Include="..\..\base\ssl_ctx.c" />
     <ClCompile Include="..\..\event\epoll.c" />
@@ -250,7 +251,6 @@
     <ClCompile Include="..\..\utils\base64.c" />
     <ClCompile Include="..\..\utils\hframe.cpp" />
     <ClCompile Include="..\..\utils\hmain.cpp" />
-    <ClCompile Include="..\..\utils\ifconfig.cpp" />
     <ClCompile Include="..\..\utils\iniparser.cpp" />
     <ClCompile Include="..\..\utils\md5.c" />
   </ItemGroup>