Skip to content

所有的资源都通过RAII管理,业务类不可持有裸资源 #1

@shediao

Description

@shediao

统一 handle/fd RAII

你现在代码里:

Windows HANDLE
Unix fd
pipe fd
process handle
thread handle

生命周期还比较分散。

第一步:建立统一 native_handle wrapper

例如:
class unique_fd;
class unique_handle;

要求:
move only
自动 close
release/reset
bool 有效性
native_handle()

然后:pipe,process, thread, stdin/stdout/stderr

全部使用它。

因为 subprocess 最大问题永远是:
early return
exception
partial init failure
timeout cleanup

只要 RAII 没统一:后面所有优化都危险

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions