hewei преди 6 години
родител
ревизия
c6ae3cbcf2
променени са 60 файла, в които са добавени 331 реда и са изтрити 237 реда
  1. 1 1
      .clang-format
  2. 6 6
      Makefile
  3. 148 62
      README.md
  4. 3 3
      base/array.h
  5. 3 3
      base/hbase.h
  6. 3 3
      base/hbuf.h
  7. 3 3
      base/hdef.h
  8. 3 3
      base/hdir.h
  9. 3 3
      base/heap.h
  10. 1 1
      base/herr.c
  11. 4 4
      base/herr.h
  12. 3 3
      base/hfile.h
  13. 4 4
      base/hgui.h
  14. 3 3
      base/hlog.h
  15. 3 3
      base/hmath.h
  16. 3 3
      base/hmutex.h
  17. 3 3
      base/hobj.h
  18. 3 3
      base/hobjectpool.h
  19. 3 3
      base/hplatform.h
  20. 3 3
      base/hproc.h
  21. 3 3
      base/hscope.h
  22. 3 3
      base/hsocket.h
  23. 3 3
      base/hstring.h
  24. 3 3
      base/hthread.h
  25. 3 3
      base/hthreadpool.h
  26. 3 3
      base/htime.h
  27. 3 3
      base/hurl.h
  28. 3 3
      base/hvar.h
  29. 3 3
      base/hversion.h
  30. 3 3
      base/netinet.h
  31. 3 3
      base/queue.h
  32. 3 3
      base/ssl_ctx.h
  33. 3 3
      configure
  34. 3 3
      event/hevent.h
  35. 3 3
      event/hloop.h
  36. 3 3
      event/nlog.h
  37. 3 3
      event/nmap.h
  38. 3 3
      event/overlapio.h
  39. 1 1
      examples/httpd.cpp
  40. 3 3
      hconfig.h
  41. 3 3
      http/server/FileCache.h
  42. 1 1
      http/server/HttpServer.cpp
  43. 11 8
      hv.h
  44. 1 1
      main.cpp.tmpl
  45. 3 3
      protocol/dns.h
  46. 3 3
      protocol/ftp.h
  47. 3 3
      protocol/icmp.h
  48. 3 3
      protocol/smtp.h
  49. 3 3
      sqlite/sql.h
  50. 4 4
      utils/hbytearray.h
  51. 3 3
      utils/hendian.h
  52. 3 3
      utils/hframe.h
  53. 3 3
      utils/hgl.h
  54. 3 3
      utils/hmain.h
  55. 3 3
      utils/htask.h
  56. 3 3
      utils/ifconfig.h
  57. 3 3
      utils/iniparser.h
  58. 5 0
      utils/md5.h
  59. 3 3
      utils/singleton.h
  60. 3 3
      utils/task_queue.h

+ 1 - 1
.clang-format

@@ -82,7 +82,7 @@ SpaceAfterCStyleCast: false
 SpaceBeforeAssignmentOperators: true
 SpaceBeforeParens: ControlStatements
 SpaceInEmptyParentheses: false
-SpacesBeforeTrailingComments: 2
+SpacesBeforeTrailingComments: 1
 SpacesInAngles:  false
 SpacesInContainerLiterals: true
 SpacesInCStyleCastParentheses: false

+ 6 - 6
Makefile

@@ -3,17 +3,17 @@ TMPDIR=tmp
 
 default: all
 
-all: libhw test timer loop tcp udp nc nmap httpd curl
+all: libhv test timer loop tcp udp nc nmap httpd curl
 
 clean:
-	$(MAKEF) clean SRCDIRS=". base utils event http http/client http/server examples $(TMPDIR)"
+	$(MAKEF) clean SRCDIRS=". base utils event http http/client http/server protocol examples $(TMPDIR)"
 
 prepare:
 	-mkdir -p $(TMPDIR) lib bin
 	-rm base/RAII.o
 
-libhw:
-	$(MAKEF) TARGET=$@ TARGET_TYPE=STATIC SRCDIRS=". base utils event http http/client http/server"
+libhv: prepare
+	$(MAKEF) TARGET=$@ TARGET_TYPE=STATIC SRCDIRS=". base utils event http http/client http/server protocol"
 
 test: prepare
 	-rm $(TMPDIR)/*.o $(TMPDIR)/*.h $(TMPDIR)/*.c $(TMPDIR)/*.cpp
@@ -49,7 +49,7 @@ nmap: prepare
 	-rm $(TMPDIR)/*.o $(TMPDIR)/*.h $(TMPDIR)/*.c $(TMPDIR)/*.cpp
 	cp examples/nmap.cpp $(TMPDIR)
 ifeq ($(OS), Windows)
-	# for nmap, on Windows platform, we suggest EVENT_POLL, not EVENT_IOCP
+	# for nmap on Windows platform, recommand EVENT_POLL, not EVENT_IOCP
 	$(MAKEF) TARGET=$@ SRCDIRS=". base event $(TMPDIR)" DEFINES="$(DEFINES) PRINT_DEBUG EVENT_POLL"
 else
 	$(MAKEF) TARGET=$@ SRCDIRS=". base event $(TMPDIR)" DEFINES="$(DEFINES) PRINT_DEBUG"
@@ -84,4 +84,4 @@ unittest: prepare
 webbench: prepare
 	$(CC) -o bin/webbench unittest/webbench.c
 
-.PHONY: clean prepare libhw test timer loop tcp udp nc nmap httpd curl unittest webbench
+.PHONY: clean prepare libhv test timer loop tcp udp nc nmap httpd curl unittest webbench

+ 148 - 62
README.md

@@ -1,29 +1,38 @@
-[![Build Status](https://travis-ci.org/ithewei/hw.svg?branch=master)](https://travis-ci.org/ithewei/hw)
+[![Build Status](https://travis-ci.org/ithewei/libhv.svg?branch=master)](https://travis-ci.org/ithewei/libhv)
 
 ## Intro
 
-hw 是一套跨平台c/c++基础组件,函数名/类名以h/H开头
-
-## OS (passed)
-
-- Linux
-- Windows
-- Mac
-
-## Compiler (passed)
-
-- gcc
-- clang
-- msvc
-
-## Required
-
-- c++11
+Like `libevent, libev, and libuv`,
+`libhv` provides event-loop with non-blocking IO and timer,
+but simpler apis and richer protocols.
+
+## Features
+
+- cross-platform (Linux, Windows, Mac)
+- event-loop (IO, timer, idle)
+- http client/server (include https http1/x http2 grpc websocket)
+- protocols
+    - dns
+    - ftp
+    - smtp
+- apps
+    - ls
+    - ifconfig
+    - ping
+    - nc
+    - nmap
+    - nslookup
+    - ftp
+    - sendmail
+    - httpd
+    - curl
 
 ## Getting Started
+
+### http
 ```shell
-git clone https://github.com/ithewei/hw.git
-cd hw
+git clone https://github.com/ithewei/libhv.git
+cd libhv
 make httpd curl
 
 bin/httpd -d
@@ -37,8 +46,116 @@ bin/curl -v localhost:8080/downloads/
 
 # http api service
 bin/curl -v -X POST localhost:8080/v1/api/json -H "Content-Type:application/json" -d '{"user":"admin","pswd":"123456"}'
+
+# webbench (linux only)
+make webbench
+bin/webbench -c 2 -t 60 localhost:8080
 ```
 
+### event-loop
+see examples/tcp.c
+```
+#include "hloop.h"
+#include "hsocket.h"
+
+#define RECV_BUFSIZE    8192
+static char recvbuf[RECV_BUFSIZE];
+
+void on_close(hio_t* io) {
+    printf("on_close fd=%d error=%d\n", hio_fd(io), hio_error(io));
+}
+
+void on_recv(hio_t* io, void* buf, int readbytes) {
+    printf("on_recv fd=%d readbytes=%d\n", hio_fd(io), readbytes);
+    char localaddrstr[SOCKADDR_STRLEN] = {0};
+    char peeraddrstr[SOCKADDR_STRLEN] = {0};
+    printf("[%s] <=> [%s]\n",
+            SOCKADDR_STR(hio_localaddr(io), localaddrstr),
+            SOCKADDR_STR(hio_peeraddr(io), peeraddrstr));
+    printf("< %s\n", buf);
+    // echo
+    printf("> %s\n", buf);
+    hio_write(io, buf, readbytes);
+}
+
+void on_accept(hio_t* io) {
+    printf("on_accept connfd=%d\n", hio_fd(io));
+    char localaddrstr[SOCKADDR_STRLEN] = {0};
+    char peeraddrstr[SOCKADDR_STRLEN] = {0};
+    printf("accept connfd=%d [%s] <= [%s]\n", hio_fd(io),
+            SOCKADDR_STR(hio_localaddr(io), localaddrstr),
+            SOCKADDR_STR(hio_peeraddr(io), peeraddrstr));
+
+    hio_setcb_close(io, on_close);
+    hio_setcb_read(io, on_recv);
+    hio_set_readbuf(io, recvbuf, RECV_BUFSIZE);
+    hio_read(io);
+}
+
+int main(int argc, char** argv) {
+    if (argc < 2) {
+        printf("Usage: cmd port\n");
+        return -10;
+    }
+    int port = atoi(argv[1]);
+
+    hloop_t* loop = hloop_new(0);
+    hio_t* listenio = create_tcp_server(loop, "0.0.0.0", port, on_accept);
+    if (listenio == NULL) {
+        return -20;
+    }
+    printf("listenfd=%d\n", hio_fd(listenio));
+    hloop_run(loop);
+    hloop_free(&loop);
+    return 0;
+}
+```
+```
+make tcp udp nc
+bin/tcp 1111
+bin/nc 1111
+
+bin/udp 2222
+bin/nc -u 2222
+```
+
+## BUILD
+
+### lib
+- make libhv
+
+### examples
+- make test # master-workers model
+- make timer # timer add/del/reset
+- make loop # event-loop(include idle, timer, io)
+- make tcp  # tcp server
+- make udp  # udp server
+- make nc   # network client
+- make nmap # host discovery
+- make httpd # http server
+- make curl # http client
+
+### unittest
+- make unittest
+
+### compile options
+#### compile with print debug info
+- make DEFINES=PRINT_DEBUG
+
+#### compile WITH_OPENSSL
+- make DEFINES=WITH_OPENSSL
+
+#### compile WITH_CURL
+- make DEFINES="WITH_CURL CURL_STATICLIB"
+
+#### compile WITH_NGHTTP2
+- make DEFINES=WITH_NGHTTP2
+
+#### other options
+- ENABLE_IPV6
+- WITH_WINDUMP
+- USE_MULTIMAP
+
 ## Module
 
 ### data-structure
@@ -58,18 +175,20 @@ bin/curl -v -X POST localhost:8080/v1/api/json -H "Content-Type:application/json
 - htime.h:       时间
 - herr.h:        错误码
 - hlog.h:        日志
+- hmutex.h:     同步锁
+- hthread.h:    线程
 - hsocket.h:     socket操作
+- hbuf.h:        缓存类
+- hurl.h:        URL转义
+- hgui.h:        gui相关定义
 - hstring.h:     字符串
 - hvar.h:        var变量
 - hobj.h:        对象基类
-- hgui.h:        gui相关定义
-- hbuf.h:        缓存类
 - hfile.h:       文件类
 - hdir.h:        ls实现
 - hscope.h:      作用域RAII机制
-- hmutex.h:     同步锁
-- hthread.h:    线程
-- hthreadpool.h:线程池
+- hthreadpool.h: 线程池
+- hobjectpool.h: 对象池
 
 ### utils
 - hmain.h:       main_ctx: arg env
@@ -77,6 +196,9 @@ bin/curl -v -X POST localhost:8080/v1/api/json -H "Content-Type:application/json
 - ifconfig.h:    ifconfig实现
 - iniparser.h:   ini解析
 - singleton.h:   单例模式
+- md5.h
+- base64.h
+- json.hpp
 
 ### event
 - hloop.h:       事件循环
@@ -94,43 +216,7 @@ bin/curl -v -X POST localhost:8080/v1/api/json -H "Content-Type:application/json
 
 ### other
 
-- h.h:          总头文件
+- hv.h:         总头文件
 - Makefile.in:   通用Makefile模板
 - main.cpp.tmpl: 通用main.cpp模板
 
-## BUILD
-
-### examples
-
-- make all
-- make test:  服务端master-workers model
-- make timer: 定时器测试
-- make loop:  事件循环(包含timer、io、idle)
-- make tcp:   tcp server
-- make udp:   udp server
-- make nc:    network client
-- make nmap:  host discovery
-- make httpd: http服务(包含web service和api service)
-- make curl:  基于libcurl封装http客户端
-
-### tests
-- make webbench: http服务压力测试程序
-- make unittest: 单元测试
-
-### compile options
-#### compile with print debug info
-- make DEFINES=PRINT_DEBUG
-
-#### compile WITH_OPENSSL
-- make DEFINES=WITH_OPENSSL
-
-#### compile WITH_CURL
-- make DEFINES="WITH_CURL CURL_STATICLIB"
-
-#### compile WITH_NGHTTP2
-- make DEFINES=WITH_NGHTTP2
-
-#### other features
-- USE_MULTIMAP
-- WITH_WINDUMP
-- ENABLE_IPV6

+ 3 - 3
base/array.h

@@ -1,5 +1,5 @@
-#ifndef HW_ARRAY_H_
-#define HW_ARRAY_H_
+#ifndef HV_ARRAY_H_
+#define HV_ARRAY_H_
 
 /*
  * array
@@ -146,4 +146,4 @@ static inline void atype##_swap(atype* p, int pos1, int pos2) {\
     p->ptr[pos2] = tmp;\
 }\
 
-#endif
+#endif // HV_ARRAY_H_

+ 3 - 3
base/hbase.h

@@ -1,5 +1,5 @@
-#ifndef HW_BASE_H_
-#define HW_BASE_H_
+#ifndef HV_BASE_H_
+#define HV_BASE_H_
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -75,4 +75,4 @@ bool getboolean(const char* str);
 } // extern "C"
 #endif
 
-#endif // HW_BASE_H_
+#endif // HV_BASE_H_

+ 3 - 3
base/hbuf.h

@@ -1,5 +1,5 @@
-#ifndef HW_BUF_H_
-#define HW_BUF_H_
+#ifndef HV_BUF_H_
+#define HV_BUF_H_
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -238,4 +238,4 @@ private:
 };
 #endif
 
-#endif  // HW_BUF_H_
+#endif // HV_BUF_H_

+ 3 - 3
base/hdef.h

@@ -1,5 +1,5 @@
-#ifndef HW_DEF_H_
-#define HW_DEF_H_
+#ifndef HV_DEF_H_
+#define HV_DEF_H_
 
 #include "hplatform.h"
 
@@ -338,4 +338,4 @@ struct s
 
 #endif // __cplusplus
 
-#endif  // HW_DEF_H_
+#endif // HV_DEF_H_

+ 3 - 3
base/hdir.h

@@ -1,5 +1,5 @@
-#ifndef HW_DIR_H_
-#define HW_DIR_H_
+#ifndef HV_DIR_H_
+#define HV_DIR_H_
 
 /*
  *@code
@@ -52,4 +52,4 @@ typedef struct hdir_s {
 // listdir: same as ls on unix, dir on win
 int listdir(const char* dir, std::list<hdir_t>& dirs);
 
-#endif // HW_DIR_H_
+#endif // HV_DIR_H_

+ 3 - 3
base/heap.h

@@ -1,5 +1,5 @@
-#ifndef HW_HEAP_H_
-#define HW_HEAP_H_
+#ifndef HV_HEAP_H_
+#define HV_HEAP_H_
 
 #include <assert.h>
 
@@ -170,4 +170,4 @@ static inline void heap_dequeue(struct heap* heap) {
     heap_remove(heap, heap->root);
 }
 
-#endif // HW_HEAP_H_
+#endif // HV_HEAP_H_

+ 1 - 1
base/herr.c

@@ -3,7 +3,7 @@
 #include <string.h> // for strerror
 
 // errcode => errmsg
-const char* get_errmsg(int err) {
+const char* hv_strerror(int err) {
     if (err > 0 && err <= SYS_NERR) {
         return strerror(err);
     }

+ 4 - 4
base/herr.h

@@ -1,5 +1,5 @@
-#ifndef HW_ERR_H_
-#define HW_ERR_H_
+#ifndef HV_ERR_H_
+#define HV_ERR_H_
 
 #include <errno.h>
 
@@ -119,10 +119,10 @@ extern "C" {
 #endif
 
 // errcode => errmsg
-const char* get_errmsg(int err);
+const char* hv_strerror(int err);
 
 #ifdef __cplusplus
 } // extern "C"
 #endif
 
-#endif  // HW_ERR_H_
+#endif // HV_ERR_H_

+ 3 - 3
base/hfile.h

@@ -1,5 +1,5 @@
-#ifndef HW_FILE_H_
-#define HW_FILE_H_
+#ifndef HV_FILE_H_
+#define HV_FILE_H_
 
 #include <string>
 
@@ -86,4 +86,4 @@ public:
     FILE* _fp;
 };
 
-#endif  // HW_FILE_H_
+#endif // HV_FILE_H_

+ 4 - 4
base/hgui.h

@@ -1,5 +1,5 @@
-#ifndef HW_GUI_H_
-#define HW_GUI_H_
+#ifndef HV_GUI_H_
+#define HV_GUI_H_
 
 typedef unsigned int HColor;  // 0xAARRGGBB
 
@@ -39,7 +39,7 @@ typedef struct hsize_s {
         this->h = h;
     }
 #endif
-}HSize;
+} HSize;
 
 typedef struct hrect_s {
     int x;
@@ -66,4 +66,4 @@ typedef struct hrect_s {
 #endif
 } HRect;
 
-#endif  // HW_GUI_H_
+#endif // HV_GUI_H_

+ 3 - 3
base/hlog.h

@@ -1,5 +1,5 @@
-#ifndef HW_LOG_H_
-#define HW_LOG_H_
+#ifndef HV_LOG_H_
+#define HV_LOG_H_
 
 /*
  * hlog is thread-safe
@@ -125,4 +125,4 @@ logger_t* default_logger();
 } // extern "C"
 #endif
 
-#endif  // HW_LOG_H_
+#endif // HV_LOG_H_

+ 3 - 3
base/hmath.h

@@ -1,5 +1,5 @@
-#ifndef HW_MATH_H_
-#define HW_MATH_H_
+#ifndef HV_MATH_H_
+#define HV_MATH_H_
 #include <math.h>
 
 static inline unsigned long floor2e(unsigned long num) {
@@ -22,4 +22,4 @@ static inline unsigned long ceil2e(unsigned long num) {
     return ret;
 }
 
-#endif // HW_MATH_H_
+#endif // HV_MATH_H_

+ 3 - 3
base/hmutex.h

@@ -1,5 +1,5 @@
-#ifndef HW_MUTEX_H_
-#define HW_MUTEX_H_
+#ifndef HV_MUTEX_H_
+#define HV_MUTEX_H_
 
 #include "hplatform.h"
 
@@ -150,4 +150,4 @@ protected:
 };
 #endif
 
-#endif  // HW_MUTEX_H_
+#endif // HV_MUTEX_H_

+ 3 - 3
base/hobj.h

@@ -1,5 +1,5 @@
-#ifndef HW_OBJ_H_
-#define HW_OBJ_H_
+#ifndef HV_OBJ_H_
+#define HV_OBJ_H_
 
 #include <string>
 #include <map>
@@ -98,4 +98,4 @@ class HObj {
     std::list<HObj*> _children;
 };
 
-#endif  // HW_OBJ_H_
+#endif // HV_OBJ_H_

+ 3 - 3
base/hobjectpool.h

@@ -1,5 +1,5 @@
-#ifndef HW_OBJECT_POOL_H_
-#define HW_OBJECT_POOL_H_
+#ifndef HV_OBJECT_POOL_H_
+#define HV_OBJECT_POOL_H_
 
 #include <list>
 #include <memory>
@@ -112,4 +112,4 @@ private:
     std::condition_variable cond_;
 };
 
-#endif // HW_OBJECT_POOL_H_
+#endif // HV_OBJECT_POOL_H_

+ 3 - 3
base/hplatform.h

@@ -1,5 +1,5 @@
-#ifndef HW_PLATFORM_H_
-#define HW_PLATFORM_H_
+#ifndef HV_PLATFORM_H_
+#define HV_PLATFORM_H_
 
 #include "hconfig.h"
 
@@ -200,4 +200,4 @@ typedef unsigned __int64    uint64_t;
 #include <pthread.h>
 #endif
 
-#endif  // HW_PLATFORM_H_
+#endif // HV_PLATFORM_H_

+ 3 - 3
base/hproc.h

@@ -1,5 +1,5 @@
-#ifndef HW_PROC_H_
-#define HW_PROC_H_
+#ifndef HV_PROC_H_
+#define HV_PROC_H_
 
 #include "hplatform.h"
 #include "hdef.h"
@@ -65,4 +65,4 @@ static inline int spawn_proc(proc_ctx_t* ctx) {
 }
 #endif
 
-#endif // HW_PROC_H_
+#endif // HV_PROC_H_

+ 3 - 3
base/hscope.h

@@ -1,5 +1,5 @@
-#ifndef HW_SCOPE_H_
-#define HW_SCOPE_H_
+#ifndef HV_SCOPE_H_
+#define HV_SCOPE_H_
 
 #include <functional>
 typedef std::function<void()> Function;
@@ -76,4 +76,4 @@ private:
     T& _mutex;
 };
 
-#endif  // HW_SCOPE_H_
+#endif // HV_SCOPE_H_

+ 3 - 3
base/hsocket.h

@@ -1,5 +1,5 @@
-#ifndef HW_SOCKET_H_
-#define HW_SOCKET_H_
+#ifndef HV_SOCKET_H_
+#define HV_SOCKET_H_
 
 #include "hplatform.h"
 #include "hdef.h"
@@ -218,4 +218,4 @@ static inline int so_rcvtimeo(int sockfd, int timeout) {
 
 END_EXTERN_C
 
-#endif // HW_SOCKET_H_
+#endif // HV_SOCKET_H_

+ 3 - 3
base/hstring.h

@@ -1,5 +1,5 @@
-#ifndef HW_STRING_H_
-#define HW_STRING_H_
+#ifndef HV_STRING_H_
+#define HV_STRING_H_
 
 #include <string>
 #include <vector>
@@ -38,4 +38,4 @@ string dirname(const string& str);
 string filename(const string& str);
 string suffixname(const string& str);
 
-#endif  // HW_STRING_H_
+#endif // HV_STRING_H_

+ 3 - 3
base/hthread.h

@@ -1,5 +1,5 @@
-#ifndef HW_THREAD_H_
-#define HW_THREAD_H_
+#ifndef HV_THREAD_H_
+#define HV_THREAD_H_
 
 #include "hplatform.h"
 #include "hdef.h"
@@ -180,4 +180,4 @@ class HThread {
 };
 #endif
 
-#endif  // HW_THREAD_H_
+#endif // HV_THREAD_H_

+ 3 - 3
base/hthreadpool.h

@@ -1,5 +1,5 @@
-#ifndef HW_THREAD_POOL_H_
-#define HW_THREAD_POOL_H_
+#ifndef HV_THREAD_POOL_H_
+#define HV_THREAD_POOL_H_
 
 #include <vector>
 #include <thread>
@@ -136,4 +136,4 @@ protected:
     std::condition_variable _cond;
 };
 
-#endif  // HW_THREAD_POOL_H_
+#endif // HV_THREAD_POOL_H_

+ 3 - 3
base/htime.h

@@ -1,5 +1,5 @@
-#ifndef HW_TIME_H_
-#define HW_TIME_H_
+#ifndef HV_TIME_H_
+#define HV_TIME_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -129,4 +129,4 @@ datetime_t get_compile_datetime();
 } // extern "C"
 #endif
 
-#endif  // HW_TIME_H_
+#endif // HV_TIME_H_

+ 3 - 3
base/hurl.h

@@ -1,9 +1,9 @@
-#ifndef HW_URL_H_
-#define HW_URL_H_
+#ifndef HV_URL_H_
+#define HV_URL_H_
 
 #include <string>
 
 std::string url_escape(const char* istr);
 std::string url_unescape(const char* istr);
 
-#endif // HW_URL_H_
+#endif // HV_URL_H_

+ 3 - 3
base/hvar.h

@@ -1,5 +1,5 @@
-#ifndef HW_VAR_H_
-#define HW_VAR_H_
+#ifndef HV_VAR_H_
+#define HV_VAR_H_
 
 #include <stdlib.h>
 #include <string.h>
@@ -53,4 +53,4 @@ class HVar {
     void*   toPointer() {return data.ptr;}
 };
 
-#endif  // HW_VAR_H_
+#endif // HV_VAR_H_

+ 3 - 3
base/hversion.h

@@ -1,5 +1,5 @@
-#ifndef HW_VERSION_H_
-#define HW_VERSION_H_
+#ifndef HV_VERSION_H_
+#define HV_VERSION_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -36,4 +36,4 @@ void version_itoa(int hex, char* str);
 } // extern "C"
 #endif
 
-#endif  // HW_VERSION_H_
+#endif // HV_VERSION_H_

+ 3 - 3
base/netinet.h

@@ -1,5 +1,5 @@
-#ifndef HW_NETINET_H_
-#define HW_NETINET_H_
+#ifndef HV_NETINET_H_
+#define HV_NETINET_H_
 
 #include "hplatform.h"
 
@@ -191,4 +191,4 @@ static inline uint16_t checksum(uint8_t* buf, int len) {
     return (uint16_t)(~sum);
 };
 
-#endif // HW_NETINET_H_
+#endif // HV_NETINET_H_

+ 3 - 3
base/queue.h

@@ -1,5 +1,5 @@
-#ifndef HW_QUEUE_H_
-#define HW_QUEUE_H_
+#ifndef HV_QUEUE_H_
+#define HV_QUEUE_H_
 
 /*
  * queue
@@ -99,4 +99,4 @@ static inline void qtype##_pop_back(qtype* p) {\
     p->size--;\
 }\
 
-#endif // HW_QUEUE_H_
+#endif // HV_QUEUE_H_

+ 3 - 3
base/ssl_ctx.h

@@ -1,5 +1,5 @@
-#ifndef HW_SSL_CTX_H
-#define HW_SSL_CTX_H
+#ifndef HV_SSL_CTX_H
+#define HV_SSL_CTX_H
 
 #ifdef __cplusplus
 extern "C" {
@@ -14,4 +14,4 @@ int ssl_ctx_destory();
 }
 #endif
 
-#endif // HW_SSL_CTX_H
+#endif // HV_SSL_CTX_H

+ 3 - 3
configure

@@ -3,8 +3,8 @@
 confile=hconfig.h
 # start confile
 cat << END > $confile
-#ifndef HW_CONFIG_H_
-#define HW_CONFIG_H_
+#ifndef HV_CONFIG_H_
+#define HV_CONFIG_H_
 
 END
 
@@ -127,7 +127,7 @@ function=pthread_mutex_timedlock && header=pthread.h && check_funtion
 
 # end confile
 cat << END >> $confile
-#endif  // HW_CONFIG_H_
+#endif // HV_CONFIG_H_
 END
 
 echo "configure done."

+ 3 - 3
event/hevent.h

@@ -1,5 +1,5 @@
-#ifndef HW_EVENT_H_
-#define HW_EVENT_H_
+#ifndef HV_EVENT_H_
+#define HV_EVENT_H_
 
 #include "array.h"
 #include "list.h"
@@ -159,4 +159,4 @@ struct hio_s {
         ev->pending = 0;\
     } while(0)
 
-#endif // HW_EVENT_H_
+#endif // HV_EVENT_H_

+ 3 - 3
event/hloop.h

@@ -1,5 +1,5 @@
-#ifndef HW_LOOP_H_
-#define HW_LOOP_H_
+#ifndef HV_LOOP_H_
+#define HV_LOOP_H_
 
 #include "hdef.h"
 
@@ -202,4 +202,4 @@ hio_t* create_udp_client (hloop_t* loop, const char* host, int port);
 
 END_EXTERN_C
 
-#endif // HW_LOOP_H_
+#endif // HV_LOOP_H_

+ 3 - 3
event/nlog.h

@@ -1,5 +1,5 @@
-#ifndef HW_NLOG_H_
-#define HW_NLOG_H_
+#ifndef HV_NLOG_H_
+#define HV_NLOG_H_
 
 // nlog: extend hlog use hloop
 
@@ -25,4 +25,4 @@
 void network_logger(int loglevel, const char* buf, int len);
 hio_t* nlog_listen(hloop_t* loop, int port);
 
-#endif // HW_NLOG_H_
+#endif // HV_NLOG_H_

+ 3 - 3
event/nmap.h

@@ -1,5 +1,5 @@
-#ifndef HW_NMAP_H_
-#define HW_NMAP_H_
+#ifndef HV_NMAP_H_
+#define HV_NMAP_H_
 
 #include <map>
 #include "hsocket.h"
@@ -16,4 +16,4 @@ int nmap_discovery(Nmap* nmap);
 int segment_discovery(const char* segment16, Nmap* nmap);
 int host_discovery(const char* segment24, Nmap* nmap);
 
-#endif // HW_NMAP_H_
+#endif // HV_NMAP_H_

+ 3 - 3
event/overlapio.h

@@ -1,5 +1,5 @@
-#ifndef HW_OVERLAPPED_H_
-#define HW_OVERLAPPED_H_
+#ifndef HV_OVERLAPPED_H_
+#define HV_OVERLAPPED_H_
 
 #include "iowatcher.h"
 
@@ -30,4 +30,4 @@ int post_recv(hio_t* io, hoverlapped_t* hovlp);
 
 #endif
 
-#endif // HW_OVERLAPPED_H_
+#endif // HV_OVERLAPPED_H_

+ 1 - 1
examples/httpd.cpp

@@ -1,4 +1,4 @@
-#include "h.h"
+#include "hv.h"
 #include "hmain.h"
 #include "iniparser.h"
 

+ 3 - 3
hconfig.h

@@ -1,5 +1,5 @@
-#ifndef HW_CONFIG_H_
-#define HW_CONFIG_H_
+#ifndef HV_CONFIG_H_
+#define HV_CONFIG_H_
 
 #ifndef HAVE_STDINT_H
 #define HAVE_STDINT_H 1
@@ -53,4 +53,4 @@
 #define HAVE_PTHREAD_MUTEX_TIMEDLOCK 0
 #endif
 
-#endif  // HW_CONFIG_H_
+#endif // HV_CONFIG_H_

+ 3 - 3
http/server/FileCache.h

@@ -1,5 +1,5 @@
-#ifndef HW_FILE_CACHE_H_
-#define HW_FILE_CACHE_H_
+#ifndef HV_FILE_CACHE_H_
+#define HV_FILE_CACHE_H_
 
 #include <map>
 #include <string>
@@ -71,4 +71,4 @@ protected:
     file_cache_t* Get(const char* filepath);
 };
 
-#endif // HW_FILE_CACHE_H_
+#endif // HV_FILE_CACHE_H_

+ 1 - 1
http/server/HttpServer.cpp

@@ -1,6 +1,6 @@
 #include "HttpServer.h"
 
-#include "h.h"
+#include "hv.h"
 #include "hmain.h"
 #include "hloop.h"
 

+ 11 - 8
h.h → hv.h

@@ -1,16 +1,17 @@
-#ifndef HW_H_
-#define HW_H_
+#ifndef HV_H_
+#define HV_H_
 
 /**
  * @copyright 2018 HeWei, all rights reserved.
  */
 
 // platform
+#include "hconfig.h"
 #include "hplatform.h"
-#include "hdef.h"
-#include "hversion.h"
 
 // c
+#include "hdef.h"
+#include "hversion.h"
 #include "hbase.h"
 #include "hsysinfo.h"
 #include "hproc.h"
@@ -19,20 +20,22 @@
 #include "herr.h"
 #include "hlog.h"
 #include "hmutex.h"
+#include "hthread.h"
 #include "hsocket.h"
+#include "hbuf.h"
+#include "hurl.h"
+#include "hgui.h"
 
 // cpp
 #ifdef __cplusplus
 #include "hstring.h"
 #include "hvar.h"
 #include "hobj.h"
-#include "hgui.h"
-#include "hbuf.h"
 #include "hfile.h"
 #include "hdir.h"
 #include "hscope.h"
-#include "hthread.h"
 #include "hthreadpool.h"
+#include "hobjectpool.h"
 #endif
 
-#endif  // HW_H_
+#endif  // HV_H_

+ 1 - 1
main.cpp.tmpl

@@ -1,4 +1,4 @@
-#include "h.h"
+#include "hv.h"
 #include "hmain.h"
 #include "iniparser.h"
 

+ 3 - 3
protocol/dns.h

@@ -1,5 +1,5 @@
-#ifndef HW_DNS_H_
-#define HW_DNS_H_
+#ifndef HV_DNS_H_
+#define HV_DNS_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -105,4 +105,4 @@ int nslookup(const char* domain, uint32_t* addrs, int naddr, const char* nameser
 }
 #endif
 
-#endif // HW_DNS_H_
+#endif // HV_DNS_H_

+ 3 - 3
protocol/ftp.h

@@ -1,5 +1,5 @@
-#ifndef HW_FTP_H_
-#define HW_FTP_H_
+#ifndef HV_FTP_H_
+#define HV_FTP_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -95,4 +95,4 @@ int ftp_download_with_cb(ftp_handle_t* hftp, const char* filepath, ftp_download_
 }
 #endif
 
-#endif // HW_FTP_H_
+#endif // HV_FTP_H_

+ 3 - 3
protocol/icmp.h

@@ -1,5 +1,5 @@
-#ifndef HW_ICMP_H_
-#define HW_ICMP_H_
+#ifndef HV_ICMP_H_
+#define HV_ICMP_H_
 
 #include "hdef.h"
 
@@ -16,4 +16,4 @@ int ping(const char* host, int cnt DEFAULT(4));
 }
 #endif
 
-#endif // HW_ICMP_H_
+#endif // HV_ICMP_H_

+ 3 - 3
protocol/smtp.h

@@ -1,5 +1,5 @@
-#ifndef HW_SMTP_H_
-#define HW_SMTP_H_
+#ifndef HV_SMTP_H_
+#define HV_SMTP_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -73,4 +73,4 @@ int sendmail(const char* smtp_server,
 }
 #endif
 
-#endif // HW_SMTP_H_
+#endif // HV_SMTP_H_

+ 3 - 3
sqlite/sql.h

@@ -1,5 +1,5 @@
-#ifndef HW_SQL_H_
-#define HW_SQL_H_
+#ifndef HV_SQL_H_
+#define HV_SQL_H_
 
 #include <string>
 #include <map>
@@ -18,4 +18,4 @@ void sql_update(std::string& sql, const char* table_name, const char* set, const
 // delete from $table_name where $where;
 void sql_delete(std::string& sql, const char* table_name, const char* where = NULL);
 
-#endif // HW_SQL_H_
+#endif // HV_SQL_H_

+ 4 - 4
utils/hbytearray.h

@@ -1,5 +1,5 @@
-#ifndef HW_BYTE_ARRAY_H_
-#define HW_BYTE_ARRAY_H_
+#ifndef HV_BYTE_ARRAY_H_
+#define HV_BYTE_ARRAY_H_
 
 #include "hbuf.h"
 #include "base64.h"
@@ -19,8 +19,8 @@ public:
     bool decodeBase64(const char* base64) {
         int out_len = BASE64_DECODE_OUT_SIZE(strlen(base64));
         resize(out_len);
-        return base64_decode(base64, strlen(base64), data()) == BASE64_OK;
+        return base64_decode(base64, strlen(base64), (unsigned char*)data()) == BASE64_OK;
     }
 };
 
-#endif  // HW_BYTE_ARRAY_H_
+#endif  // HV_BYTE_ARRAY_H_

+ 3 - 3
utils/hendian.h

@@ -1,5 +1,5 @@
-#ifndef HW_ENDIAN_H_
-#define HW_ENDIAN_H_
+#ifndef HV_ENDIAN_H_
+#define HV_ENDIAN_H_
 
 #include <stdio.h>
 #include <string.h>
@@ -53,4 +53,4 @@ uint8_t* deserialize(uint8_t* buf, T* value, int host_endian = LITTLE_ENDIAN, in
     return buf+size;
 }
 
-#endif  // HW_ENDIAN_H_
+#endif // HV_ENDIAN_H_

+ 3 - 3
utils/hframe.h

@@ -1,5 +1,5 @@
-#ifndef HW_FRAME_H_
-#define HW_FRAME_H_
+#ifndef HV_FRAME_H_
+#define HV_FRAME_H_
 
 #include <deque>
 #include <mutex>
@@ -86,4 +86,4 @@ class HFrameBuf : public HRingBuf {
     std::mutex         mutex;
 };
 
-#endif  // HW_FRAME_H_
+#endif // HV_FRAME_H_

+ 3 - 3
utils/hgl.h

@@ -1,5 +1,5 @@
-#ifndef HW_GL_H_
-#define HW_GL_H_
+#ifndef HV_GL_H_
+#define HV_GL_H_
 
 #include <GL/glew.h>
 
@@ -24,4 +24,4 @@ typedef struct GLTexture_s {
     HFrame frame;
 } GLTexture;
 
-#endif  // HW_GL_H_
+#endif // HV_GL_H_

+ 3 - 3
utils/hmain.h

@@ -1,5 +1,5 @@
-#ifndef H_MAIN_H_
-#define H_MAIN_H_
+#ifndef HV_MAIN_H_
+#define HV_MAIN_H_
 
 #include "hplatform.h"
 #include "hdef.h"
@@ -84,4 +84,4 @@ extern main_ctx_t   g_main_ctx;
 extern int          g_worker_processes_num;
 extern proc_ctx_t*  g_worker_processes;
 
-#endif // H_MAIN_H_
+#endif // HV_MAIN_H_

+ 3 - 3
utils/htask.h

@@ -1,5 +1,5 @@
-#ifndef H_TASK_H_
-#define H_TASK_H_
+#ifndef HV_TASK_H_
+#define HV_TASK_H_
 
 #include <mutex>
 #include <condition_variable>
@@ -90,4 +90,4 @@ protected:
     time_t timeout_;
 };
 
-#endif // H_TASK_H_
+#endif // HV_TASK_H_

+ 3 - 3
utils/ifconfig.h

@@ -1,5 +1,5 @@
-#ifndef IFCONFIG_H_
-#define IFCONFIG_H_
+#ifndef HV_IFCONFIG_H_
+#define HV_IFCONFIG_H_
 
 #include <vector>
 
@@ -24,4 +24,4 @@ typedef struct ifconfig_s {
  */
 int ifconfig(std::vector<ifconfig_t>& ifcs);
 
-#endif // IFCONFIG_H_
+#endif // HV_IFCONFIG_H_

+ 3 - 3
utils/iniparser.h

@@ -1,5 +1,5 @@
-#ifndef HW_INI_PARSER_H_
-#define HW_INI_PARSER_H_
+#ifndef HV_INI_PARSER_H_
+#define HV_INI_PARSER_H_
 
 #include <list>
 #include <string>
@@ -124,4 +124,4 @@ class IniParser {
     IniNode* root_;
 };
 
-#endif  // HW_INI_PARSER_H_
+#endif // HV_INI_PARSER_H_

+ 5 - 0
utils/md5.h

@@ -22,6 +22,9 @@ These notices must be retained in any copies of any part of this
 documentation and/or software.
  */
 
+#ifndef __MD5_H__
+#define __MD5_H__
+
 /* POINTER defines a generic pointer type */
 typedef unsigned char *POINTER;
 
@@ -49,3 +52,5 @@ void MD5Final(unsigned char [16], MD5_CTX *);
 #ifdef __cplusplus
 }
 #endif
+
+#endif // __MD5_H__

+ 3 - 3
utils/singleton.h

@@ -1,5 +1,5 @@
-#ifndef SINGLETON_H_
-#define SINGLETON_H_
+#ifndef HV_SINGLETON_H_
+#define HV_SINGLETON_H_
 
 #define DISABLE_COPY(Class) \
     Class(const Class &) = delete; \
@@ -28,4 +28,4 @@
         }   \
     }
 
-#endif  // SINGLETON_H_
+#endif // HV_SINGLETON_H_

+ 3 - 3
utils/task_queue.h

@@ -1,5 +1,5 @@
-#ifndef TASK_QUEUE_H_
-#define TASK_QUEUE_H_
+#ifndef HV_TASK_QUEUE_H_
+#define HV_TASK_QUEUE_H_
 
 #include <memory>
 #include <list>
@@ -86,4 +86,4 @@ protected:
     std::mutex                           mutex_;
 };
 
-#endif // TASK_QUEUE_H_
+#endif // HV_TASK_QUEUE_H_