kore load 模块的一些功能

目前此玩法官方文档暂时没介绍,但是示例中包含,感觉比较有意思,所以说明下

参考使用

  • 配置
    如下,就是包含了一个共享模块的路径以及一个字符串,这个字符串实际上是模块中的一个方法,可以实现一个当模块加载时候的任务
 
load        ./memtag.so init
  • 参考代码
#include <kore/kore.h>
#include <kore/http.h>
 
/*
 * This example demonstrates how dynamically reloadable modules
 * can use the memory tagging system in Kore in order to restore
 * the global pointers in the module.
 */
 
/* Some unique value. */
#define MEM_TAG_HELLO        100
 
int        init(int);
int        page(struct http_request *);
 
/* Global pointer, gets initialized to NULL when module loads/reloads. */
char        *fixed_ptr = NULL;
// 属于标准的签名格式
int
init(int state)
{
    /* Ignore unload(s). */
    if (state == KORE_MODULE_UNLOAD)
        return (KORE_RESULT_OK);
 
    printf("fixed_ptr: %p\n", (void *)fixed_ptr);
 
    /* Attempt to lookup the original pointer. */
    if ((fixed_ptr = kore_mem_lookup(MEM_TAG_HELLO)) == NULL) {
        /* Failed, grab a new chunk of memory and tag it. */
        printf("  allocating fixed_ptr for the first time\n");
        fixed_ptr = kore_malloc_tagged(6, MEM_TAG_HELLO);
        kore_strlcpy(fixed_ptr, "hello", 6);
    } else {
        printf("  fixed_ptr address resolved\n");
    }
 
    printf("  fixed_ptr: %p\n", (void *)fixed_ptr);
    printf("  value    : %s\n", fixed_ptr);
 
    return (KORE_RESULT_OK);
}
 
int
page(struct http_request *req)
{
    http_response(req, 200, fixed_ptr, strlen(fixed_ptr));
    return (KORE_RESULT_OK);
}

参考加载处理

  • config.c
static int
configure_load(char *options)
{
    char        *argv[3];
 
    kore_split_string(options, " ", argv, 3);
    if (argv[0] == NULL)
        return (KORE_RESULT_ERROR);
    // 此处会构建kore 的模块,特别类似nginx 的module
    kore_module_load(argv[0], argv[1], KORE_MODULE_NATIVE);
    return (KORE_RESULT_OK);
}

参考资料

https://github.com/jorisvink/kore/blob/master/src/module.c#L69
https://github.com/jorisvink/kore/blob/master/examples/memtag/conf/memtag.conf#L7

posted on   荣锋亮  阅读(14)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-11-29 lavinmq cloudamqp 开源的amqp server
2022-11-29 一些不错的开源内网穿透工具
2022-11-29 一个历史k8s维护碰到的一些网络问题说明
2020-11-29 healthcheck一个不错的 Kubernetes liveness && readiness prob handler 实现
2020-11-29 proxysql proxy 集成golang-mysqlserver
2020-11-29 vernemq 典型的部署模型
2019-11-29 streamsets 官方默认镜像中文支持问题

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示