A tiny boost library in C++11.
disconnect()
of tcp::Client
.unitest/co
for testing internal logic of coroutine schedulers.http::Server
class.http::Client
class.so::easy(...)
interface for quickly creating a static web server.size_t murmur_hash(...)
interface.Support std::hash<fastring>
, now std::unordered_map
can take fastring
as its key.
std::unordered_map<fastring, fastring> um;
LruMap<fastring, fastring> lm;
Added lshift()
interface for left shifting the string.
fastring s = "hello";
s.lshift(2); // s -> "llo";
s.lshift(8); // s -> "";
Added shrink()
interface, similar to shrink_to_fit()
of std::string
, for reducing the capacity of fastring.
fastring s(4096); // cap -> 4096
s.shrink(); // cap <4096
_test
suffix in the file name of the test/unitest code.http::Server
类.http::Client
类.so::easy(...)
接口,用于快速创建静态 web server.size_t murmur_hash(...)
接口.支持 std::hash<fastring>
,std::unordered_map
可以使用 fastring
作为 key.
std::unordered_map<fastring, fastring> um;
LruMap<fastring, fastring> lm;
新增 lshift()
接口,将字符串左移若干字节.
fastring s = "hello";
s.lshift(2); // s -> "llo";
s.lshift(8); // s -> "";
新增 shrink()
接口,与 std::string
的 shrink_to_fit()
类似,用于缩减 fastring 的容量.
fastring s(4096); // cap -> 4096
s.shrink(); // cap < 4096
_test
后缀.rpcgen
was renamed to gen
.unitest/base
directory and put the unit test code directly under the unitest
directory.test
directory.fast.cc
is put into functions, and initialization is safer.fast::dtoa
deprecated the implementation based on LruMap
and replaced with the implementation of Milo Yip.fast::stream
class to provide basic streaming output operations.fast::stream
class.fastream fs; // Define an empty fastream object without allocating memory
fastream fs;
fs << "hello "<< 23;
fs.append(fs);
fs << fs; // <==> fs.append(fs)
fastream
, it inherits from fast::stream
class, so it also supports streaming output operations.
fastring s;
s << "hello "<< 23;
fastring s;
fastream& fs = *(fastream*)&s
std::string
, which is not easy to make mistakes.
fastring s("hello");
fastring t(s); // Create a new string through memory copy
append
operation adds inside
check to fix logic bug on memory overlaps.
fastring s("123");
s.append(s.c_str() + 1); // s -> "12323"
clone()
, it is no more needed as the reference count was removed.str::dbg()
supports std::unordered_map
and std::unordered_set
.# First parse the configuration file xx.conf, then parse other command line parameters
# The values of x and s in the command line will override the values in xx.conf for easy debugging
./xx -x -s="hello" -config=xx.conf
daemon
on Linux platform to support background running programs
# add -daemon in the command line parameters
# or set in the configuration file: daemon = true
./xx -daemon
-x=y
can be written as -x y
or x=y
./xx -i=8 u=88 -s="hello world"
./xx -i 8 -u 88 -s "hello world"
./xx config=xx.conf # Use flag config to display the specified
./xx xx.conf # The configuration file name ends with .conf or config
# and is the first non-flag parameter, then config= can be omitted
./xx -x xx.conf # -x is the flag, xx.conf is the first non-flag parameter
// Use #3 at the beginning of the comment to specify level 3
// The supported level is 0-99, the default is 10
// When using --mkconf to automatically generate a configuration file, the flags are sorted by level, file name, and number of lines of code
DEF_bool(b, false, "#3 xxx");
async-signal-safe
version functions, which is safer.co::connect
, co::accept
, etc. to support ipv6.co::max_sched_num()
interface to get the maximum number of scheduling threads supported, which is currently the number of CPU cores in the system.co::sched_id()
interface to get current scheduling thread id.coroutine_id()
interface to get the id of current coroutine.co::tcp_socket()
, co::udp_socket()
interface to address family, deprecating the earlier way of specifying ipv4 and ipv6 with 4 and 6.
sock_t tcp_socket(int af=AF_INET); // @af: address family, AF_INET, AF_INET6, etc.
sock_t udp_socket(int af=AF_INET); // @af: address family, AF_INET, AF_INET6, etc.
co::socket()
interface, which is consistent with the native API.co::Event
.co::Pool
:
ccb
and dcb
, which are used to create and destroy an element respectively.co::Kakalot
was renamed to co::PoolGuard
.Jalloc
is added to improve the performance of Json.json::parse()
supports parsing of array objects.
Json v = json::parse("[1, 2, 3]");
Json::dbg()
interface to convert Json object to debug string (longer strings in Json objects may be truncated).Json::dbg()
to output Json objects, making the output log more streamlined.rpc_conn_idle_sec
and rpc_max_idle_conn
.hash32()
, the 32-bit system uses the 32-bit version of murmur 2, the 64-bit system directly takes the lower 32 bits of hash64
.rpcgen
更名为 gen
.unitest/base
目录,单元测试代码直接放到 unitest
目录下.test
目录下支持子目录.fast.cc
中静态变量的定义放到函数中,初始化更安全.fast::dtoa
弃用基于 LruMap
的实现,换用 Milo Yip 的实现(miloyip/dtoa-benchmark).fast::stream
类,提供基本的流式输出操作.fast::stream
类.fastream fs; // 定义一个空的 fastream 对象,不分配内存
fastream fs;
fs << "hello " << 23;
fs.append(fs);
fs << fs; // <==> fs.append(fs)
fastream
一样,继承于 fast::stream
类,因此也支持流式输出操作.
fastring s;
s << "hello " << 23;
fastring s;
fastream& fs = *(fastream*)&s
std::string
类似,使用起来不容易出错.
fastring s("hello");
fastring t(s); // 通过内存拷贝创建一个新的字符串
append
操作增加 inside
检查,修复内存重叠时的逻辑漏洞.
fastring s("123");
s.append(s.c_str() + 1); // s -> "12323"
clone()
方法,移除引用计数后,此方法多余.str::dbg()
支持 std::unordered_map
与 std::unordered_set
.# 先解析配置文件 xx.conf,再解析其他命令行参数
# 命令行中 x, s 的值会覆盖 xx.conf 中的值,方便调试
./xx -x -s="hello" -config=xx.conf
daemon
,以支持后台运行程序
# 可在命令行参数中带上 -daemon
# 也可在配置文件中设置: daemon = true
./xx -daemon
-x=y
可以写成 -x y
或者 x=y
./xx -i=8 u=88 -s="hello world"
./xx -i 8 -u 88 -s "hello world"
./xx config=xx.conf # 用 flag config 显示指定
./xx xx.conf # 配置文件名以 .conf 或 config 结尾,且是程序命令行的第一个非 flag 参数,则可省略 config=
./xx -x xx.conf # -x 是 flag,xx.conf 是第一个非 flag 参数
// 在注释开头用 #3 指定级别为 3
// 支持的级别为 0-99,默认为 10
// 使用 --mkconf 自动生成配置文件时,flag 按级别、文件名、代码行数排序
DEF_bool(b, false, "#3 xxx");
async-signal-safe
版本的函数,更安全.co::connect
, co::accept
等的实现,以支持 ipv6.co::max_sched_num()
接口,获取支持的最大调度线程数,目前为系统 cpu 核数.co::sched_id()
接口,获取当前的调度线程 id.coroutine_id()
接口,获取当前协程的 id.co::tcp_socket()
, co::udp_socket()
接口的参数为 address family,弃用早期用 4 与 6 指定 ipv4 与 ipv6 的方式.
sock_t tcp_socket(int af=AF_INET); // @af: address family, AF_INET, AF_INET6, etc.
sock_t udp_socket(int af=AF_INET); // @af: address family, AF_INET, AF_INET6, etc.
co::socket()
接口,与原生 api 保持一致.co::Event
的内部实现.co::Pool
:
ccb
与 dcb
,分别用于创建、销毁元素.co::Kakalot
重命名为 co::PoolGuard
.Jalloc
,提升 Json 的性能.json::parse()
支持数组对象的解析.
Json v = json::parse("[1, 2, 3]");
Json::dbg()
接口,将 Json 对象转换为 debug string (Json 对象中较长的字符串可能被截断).Json::dbg()
输出 Json 对象,使得输出的日志更精简.rpc_conn_idle_sec
与 rpc_max_idle_conn
指定空闲连接的超时时间、最大的空闲连接数.hash32()
的实现,32 位系统使用 murmur 2 的 32 位版本,64 位系统直接取 hash64
的低 32 位.