zoukankan      html  css  js  c++  java
  • libubox

    libubox

    It's one of the core libraries used within openwrt because it's a set of utilities, mostly wrappers, that are present usually in programs and that have been coded in a flexible and reusable way to avoid wasting time.

    The library consists mostly on independent functionalities, ones higher level than others.

    Simple utility functions. Endian conversion, bitfield operations, compiler attribute wrapping, sequential memory allocation function (calloc_a), static array size macro, assertion/bug utility function, clock get time wrapper for apple compatibility, base64 encoding decoding.

    This is a really simple library encouraged to be a wrapper to avoid all those socket api library calls. You can create TCPUDP and UNIX sockets, clients and servers, ipv4/v6 and non/blocking.

    The idea is to call usock() and have your fd returned.

    The most used part. Uloop is a loop runner for i/o. Gets in charge of polling the different file descriptors you have added to it, gets in charge of running timers, and helps you manage child processes. Supports epoll and kqueue as event running backends.

    The fd management part is set up with the uloop_fd struct, just adding the fd and the callback function you want called when an event arises. The rest of the structure is for internal use.

    The timeout management part is mostly prepared to do simple things, if you have the idea of doing something comples, you might want to have a look on libubox/runqueue.h which implements interesting functionality on top of uloop.

    Timeout structure should be initialized with just the callback and pending=false (timeout={.cb=cb_func} does the work), and added to uloop using uloop_timeout_set(), do not use the other _add() function because then you will need to set up the time yourself calling time.h functions. _set() uses _add() internally.

    TBDN: Process management part

    This part is a helper to pass data in binary. There are several supported datatypes, and it creates blobs that could be sent over any socket, as endianess is taken care in the library itself.

    The method is to create a type-value chained data, supporting nested data. This part basically covers putting and getting datatypes. Further functionality is implemented in blobmsg.h

    Blobmsg sits on top of blob.h, providing tables and arrays, providing it's own but parallel datatypes.

    Utility to create lists. A way to create lists of structures just by adding struct list_head to your structures. It comes with a lot of iterator macros, with some of them allowing deletion on iteration (the ones ending in _safe). It also has some list operations like slicing, moving, and inserting in different points. It is a double linked list implementation (just in case). Uses the same API as the one present in the linux kernel.

    Uses list.h to provide protection against recursive iteration with deletes.

    Key value lists, allowing duplicate elements. Keys are meant to be strings, values can be any datatype, the user has to provide a data measuring function though. If you are using strings or blobs (from blob.h), there are two measuring functions already, kvlist_strlen and kvlist_blob_len respectively.

    kvlist.h implementation uses avl.h.

  • 相关阅读:
    输人10个学生5门课的成绩,分别用函数实现下列功能:①计算每个学生的平均分; ②计算每门课的平均分; ③找出所有50个分数中最高的分数所对应的学生和课程; ④计算平均分方差: 其中,x;为某一学生的平均分。
    用递归方法求n阶勒让德多项式的值,递归公式为
    用牛顿迭代法求根。方程为ax^3+bx^2 +cx+d=0,系数a,b,c,d的值依次为1,2,3,4,由主函数输人。求x在1附近的一个实根。求出根后由主函数输出
    写一个函数,用起泡法对输人的10个字符按由小到大顺序排列
    写一个函数,输人一行字符,将此字符串中最长的单词输出
    HEX文件格式
    Linux .bashrc
    Linux dd烧写系统
    以太坊代币与账户交易
    记录智能合约solidity编译的坑
  • 原文地址:https://www.cnblogs.com/LiuYanYGZ/p/14201394.html
Copyright © 2011-2022 走看看