inotify 中, 在 read 其 struct inotify_event 时, 缓冲区必须大于读取的结构体的大小
来源:互联网 发布:php环境安装包 编辑:程序博客网 时间:2024/05/29 04:23
linux中监控文件的 inotify 提供了以下几个编程函数, inotify_init(), inotify_add_watch(),
inotify_rm_watch(). 从 inotify_init() 返回的文件描述符 read, 读取监听到的事件.
事件的结构为:
struct inotify_event { int wd; /* Watch descriptor */ uint32_t mask; /* Mask of events */ uint32_t cookie; /* Unique cookie associating related events (for rename(2)) */ uint32_t len; /* Size of ’name’ field */ char name[]; /* Optional null-terminated name */ };因为每个文件名的长度不定, 所以每个事件占用的内存大小也不一定相等.
假设 EVENT_LEN = sizeof(sturct inotify_event), NAME_LEN = len (事件结构体中的len, 为保持内存对齐, 可能大于 strlen(name));
假设inotify的事件队列中有很多未读取的, 读取事件 ret = read(fd, buf, BUF_LEN);
如果 BUF_LEN < EVENT_LEN + NAME_LEN, ret = 0;
如果 EVENT_LEN + NAME_LEN <= BUF_LEN < 2 * (EVENT_LEN + NAME_LEN ), ret = EVENT_LEN + NAME_LEN;
如果 2 * (EVENT_LEN + NAME_LEN) <= BUF_LEN < 3* (EVENT_LEN + NAME_LEN _, ret = 2 * (EVENT_LEN + NAME_LEN );
......
也就是, 只能整个的读取 struct inotify_event, 不能读取部分结构.
- - - - - - - -
以上是我个人的测试.
- inotify 中, 在 read 其 struct inotify_event 时, 缓冲区必须大于读取的结构体的大小
- struct 结构体的大小
- struct结构体的大小
- struct结构的大小
- 结构体(struct) 的 sizeof 大小
- struct 结构体大小的判断
- struct 结构体类型的大小计算
- struct结构体的大小计算:
- 结构体(struct) 的 sizeof 大小
- struct 结构体类型的大小计算
- struct结构大小的问题
- 【Struct(结构体)杂谈之七】Struct中0元素数组的意义在哪里?
- struct中sizeof的大小
- 结构体大小struct
- #pragma预处理分析 和 struct 结构体大小的计算
- golang 获取一个结构体 struct 大小的代码
- 类/结构体指针 描述其大小的内存位置
- 结构体的大小与内存对其
- Ogre处理顶点/索引数据
- Jsp 应用之自定义标签库(taglib)及配置
- [Ljava.lang.String和getParamterMap()
- 享受寂寞
- 移位
- inotify 中, 在 read 其 struct inotify_event 时, 缓冲区必须大于读取的结构体的大小
- WCF系列:Binding模型 信道监听器(Channel Listener)
- [Ext.Net] 1.2.0_Ext.Net.TreePanel 勾选“纠结”发送给服务器端的方法
- buffer cache —— free buffer waits
- pptp 能连接 但是不能上网
- WCF系列:Binding模型 信道工厂(Channel Factory)
- JAVA设计模式——单例(Singleton)模式 多种实现方法
- Handler线程操作
- configure的交叉编译问题