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,用于后续接受连接请求。

相关推荐
Sumlll_27 分钟前
Ubuntu系统下QEMU的安装与RISC-V的测试
linux·ubuntu·risc-v
猫头虎39 分钟前
2025最新OpenEuler系统安装MySQL的详细教程
linux·服务器·数据库·sql·mysql·macos·openeuler
晚风吹人醒.2 小时前
SSH远程管理及访问控制
linux·运维·ssh·scp·xshell·访问控制·远程管理
Uncertainty!!4 小时前
Linux多用户情况下个别用户输入密码后黑屏
linux·远程连接
necessary6534 小时前
使用Clion查看linux环境中的PG源码
linux·运维·服务器
小猪佩奇TONY5 小时前
Linux 内核学习(14) --- linux x86-32 虚拟地址空间
linux·学习
Lam㊣5 小时前
Centos 7 系统docker:更换镜像源
linux·docker·centos
FL16238631296 小时前
win11+WSL+Ubuntu-xrdp+远程桌面闪退+黑屏闪退解决
linux·运维·ubuntu
石头5306 小时前
Kubernetes监控全栈解决方案:从零搭建Prometheus+Grafana监控体系
linux
ha20428941946 小时前
Linux操作系统学习记录之---TcpSocket
linux·网络·c++·学习