@@ -71,15 +71,16 @@ typedef struct aeApiState {
7171 int pending_masks [MAX_EVENT_BATCHSZ ]; /* pending fds' masks */
7272} aeApiState ;
7373
74- static int aeApiCreate (aeEventLoop * eventLoop ) {
74+ static aeApiState * aeApiCreate (int setsize ) {
75+ AE_NOTUSED (setsize );
7576 int i ;
7677 aeApiState * state = zmalloc (sizeof (aeApiState ));
77- if (!state ) return -1 ;
78+ if (!state ) return NULL ;
7879
7980 state -> portfd = port_create ();
8081 if (state -> portfd == -1 ) {
8182 zfree (state );
82- return -1 ;
83+ return NULL ;
8384 }
8485 anetCloexec (state -> portfd );
8586
@@ -90,20 +91,17 @@ static int aeApiCreate(aeEventLoop *eventLoop) {
9091 state -> pending_masks [i ] = AE_NONE ;
9192 }
9293
93- eventLoop -> apidata = state ;
94- return 0 ;
94+ return state ;
9595}
9696
97- static int aeApiResize (aeEventLoop * eventLoop , int setsize ) {
98- ( void ) eventLoop ;
99- ( void ) setsize ;
97+ static int aeApiResize (aeApiState * state , int setsize ) {
98+ AE_NOTUSED ( state ) ;
99+ AE_NOTUSED ( setsize ) ;
100100 /* Nothing to resize here. */
101101 return 0 ;
102102}
103103
104- static void aeApiFree (aeEventLoop * eventLoop ) {
105- aeApiState * state = eventLoop -> apidata ;
106-
104+ static void aeApiFree (aeApiState * state ) {
107105 close (state -> portfd );
108106 zfree (state );
109107}
@@ -144,19 +142,16 @@ static int aeApiAssociate(const char *where, int portfd, int fd, int mask) {
144142 return rv ;
145143}
146144
147- static int aeApiAddEvent (aeEventLoop * eventLoop , int fd , int mask ) {
148- aeApiState * state = eventLoop -> apidata ;
149- int fullmask , pfd ;
150-
151- if (evport_debug ) fprintf (stderr , "aeApiAddEvent: fd %d mask 0x%x\n" , fd , mask );
145+ static int aeApiAddEvent (aeApiState * state , int fd , int curr_mask , int add_mask ) {
146+ if (evport_debug ) fprintf (stderr , "aeApiAddEvent: fd %d mask 0x%x\n" , fd , add_mask );
152147
153148 /*
154149 * Since port_associate's "events" argument replaces any existing events, we
155150 * must be sure to include whatever events are already associated when
156151 * we call port_associate() again.
157152 */
158- fullmask = mask | eventLoop -> events [ fd ]. mask ;
159- pfd = aeApiLookupPending (state , fd );
153+ int mask = curr_mask | add_mask ;
154+ int pfd = aeApiLookupPending (state , fd );
160155
161156 if (pfd != -1 ) {
162157 /*
@@ -166,18 +161,17 @@ static int aeApiAddEvent(aeEventLoop *eventLoop, int fd, int mask) {
166161 * re-associated as usual when aeApiPoll is called again.
167162 */
168163 if (evport_debug ) fprintf (stderr , "aeApiAddEvent: adding to pending fd %d\n" , fd );
169- state -> pending_masks [pfd ] |= fullmask ;
164+ state -> pending_masks [pfd ] |= mask ;
170165 return 0 ;
171166 }
172167
173- return (aeApiAssociate ("aeApiAddEvent" , state -> portfd , fd , fullmask ));
168+ return (aeApiAssociate ("aeApiAddEvent" , state -> portfd , fd , mask ));
174169}
175170
176- static void aeApiDelEvent (aeEventLoop * eventLoop , int fd , int mask ) {
177- aeApiState * state = eventLoop -> apidata ;
171+ static void aeApiDelEvent (aeApiState * state , int fd , int curr_mask , int del_mask ) {
178172 int fullmask , pfd ;
179173
180- if (evport_debug ) fprintf (stderr , "del fd %d mask 0x%x\n" , fd , mask );
174+ if (evport_debug ) fprintf (stderr , "del fd %d mask 0x%x\n" , fd , del_mask );
181175
182176 pfd = aeApiLookupPending (state , fd );
183177
@@ -189,7 +183,7 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
189183 * associated with the port. All we need to do is update
190184 * pending_mask appropriately.
191185 */
192- state -> pending_masks [pfd ] &= ~mask ;
186+ state -> pending_masks [pfd ] &= ~del_mask ;
193187
194188 if (state -> pending_masks [pfd ] == AE_NONE ) state -> pending_fds [pfd ] = -1 ;
195189
@@ -199,13 +193,10 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
199193 /*
200194 * The fd is currently associated with the port. Like with the add case
201195 * above, we must look at the full mask for the file descriptor before
202- * updating that association. We don't have a good way of knowing what the
203- * events are without looking into the eventLoop state directly. We rely on
204- * the fact that our caller has already updated the mask in the eventLoop.
205196 */
206197
207- fullmask = eventLoop -> events [ fd ]. mask ;
208- if (fullmask == AE_NONE ) {
198+ int mask = curr_mask & ~ del_mask ;
199+ if (mask == AE_NONE ) {
209200 /*
210201 * We're removing *all* events, so use port_dissociate to remove the
211202 * association completely. Failure here indicates a bug.
@@ -216,7 +207,7 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
216207 perror ("aeApiDelEvent: port_dissociate" );
217208 abort (); /* will not return */
218209 }
219- } else if (aeApiAssociate ("aeApiDelEvent" , state -> portfd , fd , fullmask ) != 0 ) {
210+ } else if (aeApiAssociate ("aeApiDelEvent" , state -> portfd , fd , mask ) != 0 ) {
220211 /*
221212 * ENOMEM is a potentially transient condition, but the kernel won't
222213 * generally return it unless things are really bad. EAGAIN indicates
@@ -228,8 +219,10 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
228219 }
229220}
230221
231- static int aeApiPoll (aeEventLoop * eventLoop , struct timeval * tvp ) {
232- aeApiState * state = eventLoop -> apidata ;
222+ static int aeApiPoll (aeApiState * state , aeFiredEvent * fired , aeFileEvent * events , int setsize , int maxfd , struct timeval * tvp ) {
223+ AE_NOTUSED (events );
224+ AE_NOTUSED (setsize );
225+ AE_NOTUSED (maxfd );
233226 struct timespec timeout , * tsp ;
234227 uint_t mask , i ;
235228 uint_t nevents ;
@@ -282,8 +275,8 @@ static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
282275 if (event [i ].portev_events & POLLIN ) mask |= AE_READABLE ;
283276 if (event [i ].portev_events & POLLOUT ) mask |= AE_WRITABLE ;
284277
285- eventLoop -> fired [i ].fd = event [i ].portev_object ;
286- eventLoop -> fired [i ].mask = mask ;
278+ fired [i ].fd = event [i ].portev_object ;
279+ fired [i ].mask = mask ;
287280
288281 if (evport_debug ) fprintf (stderr , "aeApiPoll: fd %d mask 0x%x\n" , (int )event [i ].portev_object , mask );
289282
0 commit comments