将 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.JdbcOdbc...