OpenBMC:BmcWeb app.run

1.监听用户移除signal

cpp 复制代码
//src\webserver_run.cpp
int run()
{
    ...
    bmcweb::registerUserRemovedSignal();

    ...
}
cpp 复制代码
//include\user_monitor.hpp
inline void onUserRemoved(sdbusplus::message_t& msg)
{
    sdbusplus::message::object_path p;
    msg.read(p);
    std::string username = p.filename();
    persistent_data::SessionStore::getInstance().removeSessionsByUsername(
        username);
}

inline void registerUserRemovedSignal()
{
    std::string userRemovedMatchStr =
        sdbusplus::bus::match::rules::interfacesRemoved(
            "/xyz/openbmc_project/user");

    static sdbusplus::bus::match_t userRemovedMatch(
        *crow::connections::systemBus, userRemovedMatchStr, onUserRemoved);
}

关于注册signal,可以参考

sdbusplus:监听属性的变化_sdbusplus::bus::match::match-CSDN博客

这部分的作用是当发现某个用户被移除后,删除该用户的session

session部分后续再介绍

2.app.run获取socket

cpp 复制代码
//src\webserver_run.cpp
int run()
{
    ...
    app.run();

    systemBus->request_name("xyz.openbmc_project.bmcweb");

    io.run();

    crow::connections::systemBus = nullptr;

    return 0;
}

其中app.run的定义如下:

cpp 复制代码
//http\app.hpp
void run()
{
    validate();

    std::vector<Acceptor> acceptors = setupSocket();

    server.emplace(this, std::move(acceptors));
    server->run();
}

validate();是用于检验route,这个后续跟路由一起解释

cpp 复制代码
//http\http_server.hpp
struct Acceptor
{
    boost::asio::ip::tcp::acceptor acceptor;
    HttpType httpType;
};
cpp 复制代码
//http\http_connect_types.hpp
enum class HttpType
{
    HTTPS, // Socket supports HTTPS only
    HTTP,  // Socket supports HTTP only
    BOTH   // Socket supports both HTTPS and HTTP, with HTTP Redirect
};

static std::vector<Acceptor> setupSocket() 的作用是获取socket,这个后续再详细解释

3.app.run构造server对象

cpp 复制代码
//http\http_server.hpp
template <typename Handler, typename Adaptor = boost::asio::ip::tcp::socket>
class Server
{
public:
    Server(Handler* handlerIn, std::vector<Acceptor>&& acceptorsIn) :
        acceptors(std::move(acceptorsIn)),

        // NOLINTNEXTLINE(misc-include-cleaner)
        signals(getIoContext(), SIGINT, SIGTERM, SIGHUP), handler(handlerIn)
    {}
    ...
private:
    std::vector<Acceptor> acceptors;
    Handler* handler;
}

OpenBMC:BmcWeb实例化App-CSDN博客

介绍了server类,但是当时没有构造server类的实例,

构造server类的实例是在app.run中

server.emplace(this, std::move(acceptors));完成的

将App做为handle传入Server,用于反向指回app对象

将setupSocket()获取的socket也传入了Server,用于后续接受连接请求。

相关推荐
深紫色的三北六号5 小时前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash8 小时前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI18 小时前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行1 天前
Linux和window共享文件夹
linux
木心月转码ing2 天前
WSL+Cpp开发环境配置
linux
崔小汤呀3 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应3 天前
vi编辑器使用
linux·后端·操作系统
何中应3 天前
Linux进程无法被kill
linux·后端·操作系统
何中应3 天前
rm-rf /命令操作介绍
linux·后端·操作系统
何中应3 天前
Linux常用命令
linux·操作系统