如何解决将 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 举报,一经查实,本站将立刻删除。