epoll_ctl - 一个epoll的描述符的控制接口
内容简介
#includeint epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
描述
Control an%uA0epollꃞscriptor,%uA0epfd, by requesting that the operation%uA0opꂾ performed on the target file descriptor,%uA0fd. The%uA0eventꃞscribes the object linked to the file descriptorfd. The%uA0struct epoll_event%uA0is defined as :
typedef union epoll_data { void *ptr int fd __uint32_t u32 __uint64_t u64 } epoll_data_t struct epoll_event { __uint32_t events /* Epoll events */ epoll_data_t data /* User data variable */ }
该事件成员是位集由使用下列可用的事件类型:
错误码 | 描述 | ||||||||
---|---|---|---|---|---|---|---|---|---|
EPOLLIN | The associated file is available forread(2) operations. | ||||||||
EPOLLOUT | The associated file is available for%uA0write(2) operations. | ||||||||
EPOLLRDHUP | Stream socket peer closed connection, or shut down writing half of connection. (This flag is especially useful for writing simple code to detect peer shutdown when using Edge Triggered monitoring.) | ||||||||
EPOLLPRI | There is urgent data available for%uA0read(2) operations. | ||||||||
EPOLLERR | Error condition happened on the associated file descriptor.epoll_wait(2) will always wait for this event it is not necessary to set it in%uA0events. | ||||||||
EPOLLHUP | Hang up happened on the associated file descriptor.epoll_wait(2) will always wait for this event it is not necessary to set it in%uA0events. | ||||||||
EPOLLET | Sets the Edge Triggered behaviour for the associated file descriptor. The default behaviour for%uA0epoll%uA0is Level Triggered. See%uA0epoll(7) for more detailed information about Edge and Level Triggered event distribution architectures. | ||||||||
EPOLLONESHOT(since kernel 2.6.2) | Sets the one-shot behaviour for the associated file descriptor. This means that after an event is pulled out with%uA0epoll_wait(2) the associated file descriptor is internally disabled and no other events will be reported by the%uA0epoll%uA0interface. The user must callepoll_ctl(2) with%uA0EPOLL_CTL_MOD%uA0to re-enable the file descriptor with a new event mask. | ||||||||
The%uA0epoll%uA0interface supports all file descriptors that support%uA0poll(2). Valid values for the%uA0op%uA0parameter are : | |||||||||
%uA0 |
|
返回值
When successful,%uA0epoll_ctl(2) returns zero. When an error occurs,%uA0epoll_ctl(2) returns -1 and%uA0errno%uA0is set appropriately.
错误
错误码 | 描述 |
---|---|
EBADF | epfd%uA0or%uA0fd%uA0is not a valid file descriptor. |
EEXIST | op%uA0was EPOLL_CTL_ADD, and the supplied file descriptor%uA0fd%uA0is already in%uA0epfd. |
EINVAL | epfd%uA0is not an%uA0epoll%uA0file descriptor, or%uA0fd%uA0is the same as%uA0epfd, or the requested operation%uA0op%uA0is not supported by this interface. |
ENOENT | op%uA0was EPOLL_CTL_MOD or EPOLL_CTL_DEL, and%uA0fd%uA0is not inepfd. |
ENOMEM | There was insufficient memory to handle the requested%uA0opcontrol operation. |
EPERM | The target file%uA0fd%uA0does not support%uA0epoll. |
遵循于
epoll_ctl(2) is a new API introduced in Linux kernel 2.5.44. The interface should be finalized by Linux kernel 2.5.66.
BUG
In kernel versions before 2.6.9, the%uA0EPOLL_CTL_DEL%uA0operation required a non-NULL pointer in%uA0event, even though this argument is ignored. Since kernel 2.6.9,%uA0eventꃊn be specified as NULL when using%uA0EPOLL_CTL_DEL.