ubus [1] - ubusd

ubusd是ubus守护进程,本文详细介绍了其数据结构,包括objects、obj_types、path等AVL tree,以及处理流程。ubusd_proto部分详细讲解了不同消息处理,如UBUS_MSG_PING、UBUS_MSG_ADD_OBJECT等。ubusd_event部分涉及事件处理,包括数据结构、处理流程及对外接口。ubusd_id和ubusd_object则阐述了对象ID管理和对象操作。
摘要由CSDN通过智能技术生成

ubusd

数据结构

struct ubus_msg_buf {
    uint32_t refcount; /* ~0: uses external data buffer */
    struct ubus_msghdr hdr;
    struct blob_attr *data;
    int fd;            /** 发送msg端进程传过来的fd,用于UBUS_MSG_STATUS消息 */
    int len;
};

struct ubus_client {
    struct ubus_id id;
    struct uloop_fd sock;

    struct list_head objects;

    struct ubus_msg_buf *tx_queue[UBUSD_CLIENT_BACKLOG];
    /**
     * txq_cur  - tx队列未处理头结点
     * txq_tail - tx队列可用结点头
     * txq_ofs  - 当前结点已发送offset
     */
    unsigned int txq_cur, txq_tail, txq_ofs;

    struct ubus_msg_buf *pending_msg;
    int pending_msg_offset;
    int pending_msg_fd;     /** 对端进程传过来的fd */
    struct {
        struct ubus_msghdr hdr;
        struct blob_attr data;
    } hdrbuf;                /** 报文格式头 */
};

struct ubus_path {
    struct list_head list;
    const char name[];
};

处理流程

ubusd启动时自动调用初始化函数ubusd_obj_init(void)分别创建objectsobj_typespath三个AVL tree头节点,同时调用ubusd_event_init()函数初始化patterns AVL tree头节点,创建event_obj全局事件对象,对象ID等于1(UBUS_SYSTEM_OBJECT_EVENT)

Server_fd监听函数server_cb注册到uloop中

  • 新client连接时
    创建struct ubus_client数据结构,初始化client fd回调函数client_cb,并加入到全局clients avl_tree中进行维护,最后把此client注册到uloop中

  • 收到client报文时
    如果发送队列中存在数据,则尽量把队列中所有内容发出
    先收取报文头部数据,以确定整个报文内容长度,报文头部数据结构如下

struct {
     
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值