Files
CProxy/lib/Channel.cpp
lzs123 7896117996 init
2022-02-05 00:14:15 +08:00

36 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "Channel.h"
#include <sys/epoll.h>
void Channel::handleEvents() {
// 将events设置为0默认不
events_ = 0;
if (!revents_) return;
// 对端close回复rst设置channel的quiting为true
if (revents_ & EPOLLHUP) {
printf("EPOLLHUP\n");
peerClosed_ = true;
}
// 本端操作一些动作触发了报错比如对端关闭后还继续往对端写write会成功返回但在wait时会收到这个事件
if (revents_ & EPOLLERR) {
printf("EPOLLERR\n");
errorHandler_();
}
// 对端调用close时本端会收到RDHUPEPOLLRDHUP想要被触发需要显式地在epoll_ctl调用时设置在events中此时本端可能还有数据可接收
if (revents_ & EPOLLRDHUP) {
printf("EPOLLRDHUP\n");
peerClosed_ = true;
}
// 数据可读
if (revents_ & (EPOLLIN | EPOLLPRI)) {
printf("EPOLLIN\n");
readHandler_();
}
// 当发送缓冲区可写且对端没关闭
if ((revents_ & EPOLLOUT) && !peerClosed_) {
printf("EPOLLOUT\n");
writeHandler_();
}
postHandler_();
}