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

相关推荐
dishugj1 天前
【linux】Redhat 6.3系统安装zabbix-agent软件包,无法使用YUM源问题
linux·运维·zabbix
无奈笑天下1 天前
【麒麟镜像vmtools异常排查指导书】
linux·运维·经验分享·云计算·kylin
Xの哲學1 天前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
QT 小鲜肉1 天前
【Linux命令大全】001.文件管理之mmove命令(实操篇)
linux·服务器·前端·chrome·笔记
Winner13001 天前
查看rk3566摄像头设备、能力、支持格式
linux·网络·人工智能
QT 小鲜肉1 天前
【Linux命令大全】001.文件管理之mdel命令(实操篇)
linux·运维·服务器·chrome·笔记
大聪明-PLUS1 天前
如何从零开始开发 Linux 驱动程序
linux·嵌入式·arm·smarc
物随心转1 天前
input子系统工作原理
linux
一只旭宝1 天前
Linux专题六:进程替换详解加五种进程间通讯方式(套接字放到tcp通信编程上讲述)
linux
开压路机1 天前
Linux的基本指令
linux·服务器