Ai
1 Star 0 Fork 0

丁旭升/Linux__cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Epoll.hpp 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
丁旭升 提交于 2023-03-29 12:47 +08:00 . epool代码---读
#pragma once
#include <iostream>
#include <sys/epoll.h>
#include <unistd.h>
#include "Sock.hpp"
class Epoll
{
static const int gsize = 256;
public:
int CreateEpoll()
{
int epollfd = epoll_create(gsize);
// 成功返回该epoll模型套接字
if(epollfd>0) return epollfd;
exit(5);
LogMessage(FATAL, "创建epoll模型失败 %d:%s", errno, strerror(errno));
}
bool CtlEpoll(int epollfd, int oper, int sock, uint32_t events)
{
struct epoll_event ev;
ev.events = events;
ev.data.fd = sock;
// 成功返回0,失败返回-1
int n = epoll_ctl(epollfd, oper, sock, &ev);
return n==0;
}
int WaitEpoll(int epollfd, struct epoll_event revs[], int num, int timeout)
{
// 1. 如果底层就绪的sock非常多,revs承装不下,怎么办??不影响!一次拿不完,就下一次再拿
// 2:关于epoll_wait的返回值问题:有几个fd上的事件就绪,就返回几,epoll返回的时候,会将所有
// 就绪的event按照顺序放入到revs数组中!一共有返回值个!
return epoll_wait(epollfd, revs, num, timeout);
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/ding-xushengyun/linux__cpp.git
git@gitee.com:ding-xushengyun/linux__cpp.git
ding-xushengyun
linux__cpp
Linux__cpp
master

搜索帮助