问题描述
当epoll_wait
针对特定fd返回EPOLLERR
时,是否可以找到errno
?
Is there a way to find out the errno
when epoll_wait
returns EPOLLERR
for a particular fd?
是否有关于错误性质的更多信息?
Is there any further information about the nature of the error?
添加更多信息以防止歧义
Adding more information to prevent ambiguity
epoll_wait
等待许多文件描述符.调用epoll_wait
时,将其传递给epoll_event
结构数组:
epoll_wait
waits on a number of file descriptors. When you call epoll_wait
you pass it an array of epoll_event
structures:
struct epoll_event {
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
};
epoll_data_t
结构的详细信息与您使用epoll_ctl
向epoll添加文件描述符的结构相同:
The epoll_data_t
structure has the same details as the one you used with epoll_ctl
to add a file descriptor to epoll:
typedef union epoll_data {
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;
我正在寻找的是当epoll等待的文件描述符之一出现错误时会发生什么情况.
What I'm looking for is what happens when there is an error on one of the file descriptors that epoll is waiting on.
ie:(epoll_event.events & EPOLLERR) == 1
-有没有办法在文件描述符上找出错误的更多详细信息?
ie: (epoll_event.events & EPOLLERR) == 1
- is there a way to find out more details of the error on the file descriptor?
推荐答案
使用getsockopt和SO_ERROR在套接字上获取挂起的错误
Use getsockopt and SO_ERROR to get the pending error on the socket
int error = 0;
socklen_t errlen = sizeof(error);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errlen) == 0)
{
printf("error = %s\n", strerror(error));
}
这篇关于当epoll_wait返回EPOLLERR时,如何获取errno?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!