通过项目跨平台编译的不断打磨,总结的一套跨平台C/C++基础库,可跨linux、windows、mac平台,
可方便用于实际项目中,也可供爱好造轮子的同学参考学习;
提供了时间日期、字符串、日志、线程、线程池、同步锁、缓存buf等基础API;
实现了非阻塞IO的事件驱动框架,类似libevent、libev、libuv;
实现了http客户端和服务端,支持扩展ssl、http2、grpc;
实现了dns、ftp、smtp等常见协议;
提供类似nginx的master-workers进程模型;
收集了base64、md5、crc、sha等编码数字摘要算法;
提供了ls、ping、nc、nmap、ifconfig、nslookup、sendmail等实现;
Intro
hw 是一套跨平台c/c++基础组件,函数名/类名以h/H开头
platform
gcc
mingw
msvc
required
c++11
Getting Started
git clone https://github.com/ithewei/hw.git
cd hw
make httpd curl
bin/httpd -d
ps aux | grep httpd
# http web service
bin/curl -v localhost:8080
# indexof
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"}'
Module
data-structure
array.h: 动态数组
list.h: 链表
queue.h: 队列
heap.h: 堆
base
hplatform.h: 平台相关宏
hdef.h: 宏定义
hversion.h: 版本
hbase.h: 基本接口
hsysinfo.h: 系统信息
hproc.h: 子进程/线程类
hmath.h: math扩展函数
htime.h: 时间
herr.h: 错误码
hlog.h: 日志
hsocket.h: socket操作
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:线程池
utils
hmain.h: main_ctx: arg env
hendian.h: 大小端
ifconfig.h: ifconfig实现
iniparser.h: ini解析
singleton.h: 单例模式
event
hloop.h: 事件循环
iowatcher
EVENT_SELECT
EVENT_POLL
EVENT_EPOLL (linux only)
EVENT_KQUEUE (mac/bsd)
EVENT_IOCP (windows only)
http
http_client.h: http客户端
HttpServer.h: http服务端
other
h.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