Releases: idealvin/coost
Releases · idealvin/coost
co v1.2.2
co v1.2.1
co 1.1 released
English
github
Changes
Code structure adjustment
- Put the header file in the include directory.
- The source files are placed in the src directory.
rpcgen
was renamed togen
.- Remove the
unitest/base
directory and put the unit test code directly under theunitest
directory. - Support subdirectories under
test
directory.
fast
- The definition of static variables in
fast.cc
is put into functions, and initialization is safer. fast::dtoa
deprecated the implementation based onLruMap
and replaced with the implementation of Milo Yip.- Added
fast::stream
class to provide basic streaming output operations.
fastream
- Inherited from
fast::stream
class. - Support move constructor.
- Added empty status.
fastream fs; // Define an empty fastream object without allocating memory
- Support append itself.
fastream fs; fs << "hello "<< 23; fs.append(fs); fs << fs; // <==> fs.append(fs)
fastring
- Like
fastream
, it inherits fromfast::stream
class, so it also supports streaming output operations.fastring s; s << "hello "<< 23;
- The memory structure of fastring and fastream is the same, the two can be converted seamlessly.
fastring s; fastream& fs = *(fastream*)&s
- Removed reference counting to make fastring's copying behavior similar to
std::string
, which is not easy to make mistakes.fastring s("hello"); fastring t(s); // Create a new string through memory copy
append
operation addsinside
check to fix logic bug on memory overlaps.fastring s("123"); s.append(s.c_str() + 1); // s -> "12323"
- Remove the
clone()
, it is no more needed as the reference count was removed.
str
str::dbg()
supportsstd::unordered_map
andstd::unordered_set
.
flag
- Optimize the parsing order of command line parameters and configuration files, first parse the configuration file, and then parse other command line parameters.
# 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
- Added built-in bool flag
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
- Command line parameters support multiple styles,
-x=y
can be written as-x y
orx=y
./xx -i=8 u=88 -s="hello world" ./xx -i 8 -u 88 -s "hello world"
- Optimize the way to specify the configuration file when the program starts.
./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
- When defining the flag, you can specify the level in the comment to control the order of the flag in the configuration file.
// 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");
log
- Some functions in the signal handler are changed to
async-signal-safe
version functions, which is safer.
coroutine
- Fixed bugs caused by io events registered in epoll(kevent, iocp) that were not removed in time.
- Fix the bug that the internal iterator is not updated correctly when Scheduler::add_timer() is called.
- Improve the implementation of
co::connect
,co::accept
, etc. to support ipv6. - Added
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. - Added
co::sched_id()
interface to get current scheduling thread id. - Added
coroutine_id()
interface to get the id of current coroutine. - Refactored Scheduler, the internal logic structure is clearer, and the code is more readable.
- Modify the parameters of the
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.
- Added
co::socket()
interface, which is consistent with the native API. - Fixed the initialization problem of some static global variables in the hook implementation.
- Optimized the internal implementation of
co::Event
. - Refactored
co::Pool
:- Users can specify callback
ccb
anddcb
, which are used to create and destroy an element respectively. - Users can specify the maximum capacity of the pool (only valid when dcb is set).
- Register cleanup callback with Scheduler in the internal implementation to ensure the cleanup of co::Pool at the end of the scheduling thread.
- Users can specify callback
co::Kakalot
was renamed toco::PoolGuard
.
json
- Internal reference counting, using atomic operations, copying Json objects is safe in multi-thread environment.
- Reconstruct the internal memory model of Json, and fix the bugs caused by the internal memory changes.
- A simple memory allocator
Jalloc
is added to improve the performance of Json. json::parse()
supports parsing of array objects.Json v = json::parse("[1, 2, 3]");
- Added
Json::dbg()
interface to convert Json object to debug string (longer strings in Json objects may be truncated). - The log library calls
Json::dbg()
to output Json objects, making the output log more streamlined.
rpc
- Simplify, remove some unnecessary configuration items.
- Optimize connection management, you can specify the timeout period of idle connections and the maximum number of idle connections through
rpc_conn_idle_sec
andrpc_max_idle_conn
.
hash
- Modify the implementation of
hash32()
, the 32-bit system uses the 32-bit version of murmur 2, the 64-bit system directly takes the lower 32 bits ofhash64
.
Compile
- Removed scons compilation script.
- Support xmake compilation.
- Support cmake compilation (contributed by izhengfan).
- Windows supports compilation with VS project files (automatically generated by xmake).
中文
github
Changes
代码结构调整
- 头文件放到 include 目录.
- 源文件放到 src 目录.
rpcgen
更名为gen
.- 移除
unitest/base
目录,单元测试代码直接放到unitest
目录下. test
目录下支持子目录.
fast
fast.cc
中静态变量的定义放到函数中,初始化更安全.fast::dtoa
弃用基于LruMap
的实现,换用 Milo Yip 的实现(miloyip/dtoa-benchmark).- 新增
fast::stream
类,提供基本的流式输出操作.
fastream
- 继承于
fast::stream
类. - 支持 move 构造函数.
- 增加空状态.
fastream fs; // 定义一个空的 fastream 对象,不分配内存
- 支持 append 自己.
fastream fs; fs << "hello " << 23; fs.append(fs); fs << fs; // <==> fs.append(fs)
fastring
- 与
fastream
一样,继承于fast::stream
类,因此也支持流式输出操作.fastring s; s << "hello " << 23;
- fastring 与 fastream 的内存结构相同,二者可以无缝转换.
fastring s; fastream& fs = *(fastream*)&s
- 移除引用计数,使 fastring 的复制行为与
std::string
类似,使用起来不容易出错.fastring s("hello"); fastring t(s); // 通过内存拷贝创建一个新的字符串
append
操作增加inside
检查,修复内存重叠时的逻辑漏洞.fastring s("123"); s.append(s.c_str() + 1); // s -> "12323"
- 删除
clone()
方法,移除引用计数后,此方法多余.
str
str::dbg()
支持std::unordered_map
与std::unordered_set
.
flag
- 优化命令行参数与配置文件的解析顺序,先解析配置文件,再解析其他命令行参数.
# 先解析配置文件 xx.conf,再解析其他命令行参数 # 命令行中 x, s 的值会覆盖 xx.conf 中的值,方便调试 ./xx -x -s="hello" -config=xx.conf
- Linux 平台增加内置 bool flag
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 # 配置文...