当前位置:网站首页>Gossip about redis source code 81
Gossip about redis source code 81
2022-07-03 23:24:00 【Tao song remains the same】
fd_set It is a very important structure in network programming ,rfds Is read description set , wfds Is to write a description set , This is the use needs to be very clear , Look at the last select, Know how it is :
#include <sys/select.h>
#include <string.h>
typedef struct aeApiState {
fd_set rfds, wfds;
/* We need to have a copy of the fd sets as it's not safe to reuse
* FD sets after select(). */
fd_set _rfds, _wfds;
} aeApiState;
static int aeApiCreate(aeEventLoop *eventLoop) {
aeApiState *state = zmalloc(sizeof(aeApiState));
if (!state) return -1;
FD_ZERO(&state->rfds);
FD_ZERO(&state->wfds);
eventLoop->apidata = state;
return 0;
}
static int aeApiResize(aeEventLoop *eventLoop, int setsize) {
/* Just ensure we have enough room in the fd_set type. */
if (setsize >= FD_SETSIZE) return -1;
return 0;
}
static void aeApiFree(aeEventLoop *eventLoop) {
zfree(eventLoop->apidata);
}
static int aeApiAddEvent(aeEventLoop *eventLoop, int fd, int mask) {
aeApiState *state = eventLoop->apidata;
if (mask & AE_READABLE) FD_SET(fd,&state->rfds);
if (mask & AE_WRITABLE) FD_SET(fd,&state->wfds);
return 0;
}
static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
aeApiState *state = eventLoop->apidata;
if (mask & AE_READABLE) FD_CLR(fd,&state->rfds);
if (mask & AE_WRITABLE) FD_CLR(fd,&state->wfds);
}
static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
aeApiState *state = eventLoop->apidata;
int retval, j, numevents = 0;
memcpy(&state->_rfds,&state->rfds,sizeof(fd_set));
memcpy(&state->_wfds,&state->wfds,sizeof(fd_set));
retval = select(eventLoop->maxfd+1,
&state->_rfds,&state->_wfds,NULL,tvp);
if (retval > 0) {
for (j = 0; j <= eventLoop->maxfd; j++) {
int mask = 0;
aeFileEvent *fe = &eventLoop->events[j];
if (fe->mask == AE_NONE) continue;
if (fe->mask & AE_READABLE && FD_ISSET(j,&state->_rfds))
mask |= AE_READABLE;
if (fe->mask & AE_WRITABLE && FD_ISSET(j,&state->_wfds))
mask |= AE_WRITABLE;
eventLoop->fired[numevents].fd = j;
eventLoop->fired[numevents].mask = mask;
numevents++;
}
}
return numevents;
}
static char *aeApiName(void) {
return "select";
}
边栏推荐
- D29:post Office (post office, translation)
- Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
- Amway by head has this project management tool to improve productivity in a straight line
- 在恒泰证券开户怎么样?安全吗?
- Opengauss database log management guide
- Ramble 72 of redis source code
- . Net ADO splicing SQL statement with parameters
- Unsafe and CAS principle
- 2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
- Selenium check box
猜你喜欢

How to understand the gain bandwidth product operational amplifier gain

Hcip day 14 notes

Esp-idf turns off serial port log output.

Interpretation of corolla sub low configuration, three cylinder power configuration, CVT fuel saving and smooth, safety configuration is in place

The difference between single power amplifier and dual power amplifier

SDMU OJ#P19. Stock trading

Shiftvit uses the precision of swing transformer to outperform the speed of RESNET, and discusses that the success of Vit does not lie in attention!

Blue Bridge Cup -- guess age
![[network security] what is emergency response? What indicators should you pay attention to in emergency response?](/img/ff/c733ffbb922760910ab09af3ae2886.jpg)
[network security] what is emergency response? What indicators should you pay attention to in emergency response?

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
随机推荐
Summary of fluent systemchrome
Go error collection | talk about the difference between the value type and pointer type of the method receiver
Firefox set up proxy server
Actual combat | use composite material 3 in application
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Recursion and recursion
Learning notes of raspberry pie 4B - IO communication (SPI)
Bufferpool caching mechanism for executing SQL in MySQL
What are the securities companies with the lowest Commission for stock account opening? Would you recommend it? Is it safe to open an account on your mobile phone
SDMU OJ#P19. Stock trading
Opengauss database log management guide
Overview of Yunxi database executor
Schematic diagram of crystal oscillator clock and PCB Design Guide
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Comparable interface and comparator interface
How to understand the gain bandwidth product operational amplifier gain
Qtoolbutton - menu and popup mode
finalize finalization finally final
股票开户最低佣金炒股开户免费,网上开户安全吗
X Opencv feature point detection and matching