Skip to content

Releases: idealvin/coost

co v1.2.2

30 Jul 11:14
442d4c4
Compare
Choose a tag to compare

co v1.2.1

19 Jul 12:26
a3a4ca8
Compare
Choose a tag to compare
  • fix bug due to CancelIo is too late on io timeout for windows

co 1.1 released

02 Jul 12:39
c266382
Compare
Choose a tag to compare

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 to gen.
  • Remove the unitest/base directory and put the unit test code directly under the unitest 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 on LruMap 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 from fast::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 adds inside 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() supports std::unordered_map and std::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 or x=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 and dcb, 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.
  • co::Kakalot was renamed to co::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 and rpc_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 of hash64.

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_mapstd::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         # 配置文...
Read more