最近在不同的环境编译epoll程序的时候总是有问题,看了下系统epoll.h,原来是两个不同的版本。
其中有些宏定义老版的没有,而在老版中定义
struct epoll_event
{
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
} __attribute__ ((__packed__));
epoll_data_t是一个64位的union,定义
typedef union epoll_data
{
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;
查了下__attribute__ ((__packed__))这个,这个是gcc取消内存对齐的编译参数,加上这个
结构体大小为12字节,而不加则是16字节events后面会补齐。