微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 inotify“事件”的对象保存在 c

如何解决将 inotify“事件”的对象保存在 c

我正在通过客户端到服务器的通信从 inotify 发送 Linux 中当前目录的更新。

这是 inotify 部分的代码

我展示了我对 /*??? ???*/ 担心的部分,因为我不知道在该部分正确地工作什么。

#define EVENT_STRUCT_SIZE sizeof(struct inotify_event) 
#define BUFFER_SIZE (10 * (EVENT_STRUCT_SIZE + NAME_MAX + 1))
char buffer_[BUFFER_SIZE];

/*???
int arr_to_server[BUFFER_SIZE] = {0};
???*/

int inotify_fd = inotify_init();
    if(inotify_fd == -1)
        return 1; // can't create the inotify fd,return 1 to os and exit

    int watch_des = inotify_add_watch(inotify_fd,".",IN_ALL_EVENTS);

    if(watch_des == -1)
        return 1; // can't create the watch descriptor,return 1 to os and exit

    // start to monitor
    while(1 == 1) {
        // read 
        int bytesRead = read(inotify_fd,buffer,BUFFER_SIZE),bytesProcessed = 0;
        if(bytesRead < 0) // read error
            return 1;
        
        while(bytesProcessed < bytesRead) {
            struct inotify_event* event = (struct inotify_event*)(buffer_inot + bytesProcessed);

           /*??? 
           
            arr_to_server[0] = event->mask;
            arr_to_server[1] = event->name;


           ???*/
           bytesProcessed += EVENT_STRUCT_SIZE + event->len;
            //send(sock,arr_to_server,strlen(arr_to_server),0);
        }
        
    }
    

所以本质上,event一个 struct,它有一些 objects在这些对象中,我想保存 event->name event->mask一个数组中,以便能够使用 arr_to_server 将数组从客户端发送到服务器。

基于我在 c 中的技能,我尝试了很多我知道的东西,但是当涉及到 c 中数据结构的非常复杂的细节时,我仍然无能为力。

任何帮助将不胜感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?