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

相关推荐
彩色的黑'''8 小时前
[root@localhost ~]#,Linux系统的命令提示符为啥现在变成-bash-4.2#了,哪里设置的
linux·运维·bash
源远流长jerry8 小时前
Linux 网络发送机制深度解析:从应用到网线
linux·服务器·网络·网络协议·tcp/ip
南境十里·墨染春水9 小时前
linux学习进展 shell编程
linux·运维·学习
goyeer9 小时前
【ITIL4】32服务实践 - 问题管理(Problem Management)
linux·运维·服务器·企业数字化·it管理·itil·it治理
怀旧,10 小时前
【Linux网络编程】8. 网络层协议 IP
linux·网络·tcp/ip
RH23121110 小时前
2026.5.12 Linux
java·linux·数据结构
cen__y10 小时前
Linux11(网络编程)
linux·运维·服务器·c语言·网络·网络协议·tcp/ip
ITKEY_10 小时前
archlinux x11桌面 部分程序识别成Wayland
linux
怀旧,11 小时前
【Linux网络编程】9. 数据链路层
linux·服务器·网络
用户23678298016811 小时前
Linux watch 命令深度解析:从实时监控到变化检测的完整实现
linux