当前位置:网站首页>漫话Redis源码之一百一二十
漫话Redis源码之一百一二十
2022-06-22 18:33:00 【涛歌依旧】
掩码的使用,还真得会:
/*
* Helper function to invoke port_associate for the given fd and mask.
*/
static int aeApiAssociate(const char *where, int portfd, int fd, int mask) {
int events = 0;
int rv, err;
if (mask & AE_READABLE)
events |= POLLIN;
if (mask & AE_WRITABLE)
events |= POLLOUT;
if (evport_debug)
fprintf(stderr, "%s: port_associate(%d, 0x%x) = ", where, fd, events);
rv = port_associate(portfd, PORT_SOURCE_FD, fd, events,
(void *)(uintptr_t)mask);
err = errno;
if (evport_debug)
fprintf(stderr, "%d (%s)\n", rv, rv == 0 ? "no error" : strerror(err));
if (rv == -1) {
fprintf(stderr, "%s: port_associate: %s\n", where, strerror(err));
if (err == EAGAIN)
fprintf(stderr, "aeApiAssociate: event port limit exceeded.");
}
return rv;
}
static int aeApiAddEvent(aeEventLoop *eventLoop, int fd, int mask) {
aeApiState *state = eventLoop->apidata;
int fullmask, pfd;
if (evport_debug)
fprintf(stderr, "aeApiAddEvent: fd %d mask 0x%x\n", fd, mask);
/*
* Since port_associate's "events" argument replaces any existing events, we
* must be sure to include whatever events are already associated when
* we call port_associate() again.
*/
fullmask = mask | eventLoop->events[fd].mask;
pfd = aeApiLookupPending(state, fd);
if (pfd != -1) {
/*
* This fd was recently returned from aeApiPoll. It should be safe to
* assume that the consumer has processed that poll event, but we play
* it safer by simply updating pending_mask. The fd will be
* re-associated as usual when aeApiPoll is called again.
*/
if (evport_debug)
fprintf(stderr, "aeApiAddEvent: adding to pending fd %d\n", fd);
state->pending_masks[pfd] |= fullmask;
return 0;
}
return (aeApiAssociate("aeApiAddEvent", state->portfd, fd, fullmask));
}
边栏推荐
- Initial experience of ABAQUS using RSG drawing plug-in
- 数字经济加速落地,能为中小企业带来什么?
- 0.0 - Solidworks如何才能卸载干净?
- Xintang nuc980 usage record: basic description of development environment preparation and compilation configuration
- 小甲鱼老师《带你学C带你飞》的后续课程补充
- 修改隐含参数造成SQL性能下降案例之一
- Metu stability and operation and maintenance guarantee scheme
- 斐波那契查找(黄金分割)
- [compréhension approfondie de la technologie tcaplusdb] exploitation et entretien de tcaplusdb - inspection quotidienne des patrouilles
- Mysql database knowledge points (III)
猜你喜欢

84. (cesium chapter) movement of cesium model on terrain

编译报错:/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata‘

51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭

如何用银灿IS903主控DIY自己的U盘?(练习BGA焊接的好项目)

Nlp-d57-nlp competition D26 & skimming questions D13 & reading papers & finding bugs for more than an hour

详解openGauss多线程架构启动过程

Openpnp调试 ------ 0816飞达推0402编带

0816飞达的缺点(改进方向)

Agent model of structured model

华为云招募工业智能领域合作伙伴,强力扶持+商业变现
随机推荐
第一篇 热身--隐式类型转换还是其他?
B树代码(C语言)
MySQL数据库DQL查询操作
康考迪亚大学|图卷积循环网络用于强化学习中的奖励生成
0.0 - how can SolidWorks be uninstalled cleanly?
Tree, forest and transformation of binary tree
Div horizontal layout
[in depth understanding of tcapulusdb technology] tcapulusdb regular documents
Follow up course supplement of little turtle teacher "take you to learn C and take you to fly"
51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
Altium Designer中off grid pin解决方法
二叉排序树的查找、插入和删除
Peking University - robust task representation for off-line meta reinforcement learning through contrastive learning
商业智能BI数据仓库中的指标、维度和模型到底是什么?
元宇宙怎么就这么火,市场喊起来的10万亿是吹嘘还是真相?
Georgia Institute of technology - coordinated coverage and tracking planning of multi UAV wildfire with service quality assurance
K8s deploy MySQL
Download files through Base64 (convert Base64 to BLOB)
1.3-----Simplify 3D切片软件简单设置
卡尔加里大学|基于强化学习的推荐系统综述