@@ -126,10 +126,10 @@ static int ev_api_get_event_type(struct ev_ctx *ctx, int idx)
126
126
{
127
127
struct epoll_api * e_api = ctx -> api ;
128
128
int events = e_api -> events [idx ].events ;
129
- int ev_mask = ctx -> events_monitored [e_api -> events [idx ].data .fd ].mask ;
129
+ int ev_mask = ctx -> monitored [e_api -> events [idx ].data .fd ].mask ;
130
130
// We want to remember the previous events only if they're not of type
131
131
// CLOSE or TIMER
132
- int mask = ev_mask & (EV_CLOSEFD | EV_TIMERFD ) ? ev_mask : EV_NONE ;
132
+ int mask = ev_mask & (EV_CLOSEFD | EV_TIMERFD ) ? ev_mask : EV_NONE ;
133
133
if (events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP ))
134
134
mask |= EV_DISCONNECT ;
135
135
if (events & EPOLLIN )
@@ -189,7 +189,7 @@ static inline struct ev *ev_api_fetch_event(const struct ev_ctx *ctx, int idx,
189
189
int mask )
190
190
{
191
191
int fd = ((struct epoll_api * )ctx -> api )-> events [idx ].data .fd ;
192
- return ctx -> events_monitored + fd ;
192
+ return ctx -> monitored + fd ;
193
193
}
194
194
195
195
#elif defined(POLL )
@@ -212,18 +212,18 @@ static inline struct ev *ev_api_fetch_event(const struct ev_ctx *ctx, int idx,
212
212
213
213
struct poll_api {
214
214
int nfds ;
215
- int events_monitored ;
215
+ int monitored ;
216
216
struct pollfd * fds ;
217
217
};
218
218
219
219
static int ev_api_init (struct ev_ctx * ctx , int events_nr )
220
220
{
221
- struct poll_api * p_api = try_alloc (sizeof (* p_api ));
222
- p_api -> nfds = 0 ;
223
- p_api -> fds = try_calloc (events_nr , sizeof (struct pollfd ));
224
- p_api -> events_monitored = events_nr ;
225
- ctx -> api = p_api ;
226
- ctx -> maxfd = events_nr ;
221
+ struct poll_api * p_api = try_alloc (sizeof (* p_api ));
222
+ p_api -> nfds = 0 ;
223
+ p_api -> fds = try_calloc (events_nr , sizeof (struct pollfd ));
224
+ p_api -> monitored = events_nr ;
225
+ ctx -> api = p_api ;
226
+ ctx -> maxfd = events_nr ;
227
227
return EV_OK ;
228
228
}
229
229
@@ -236,7 +236,7 @@ static void ev_api_destroy(struct ev_ctx *ctx)
236
236
static int ev_api_get_event_type (struct ev_ctx * ctx , int idx )
237
237
{
238
238
struct poll_api * p_api = ctx -> api ;
239
- int ev_mask = ctx -> events_monitored [p_api -> fds [idx ].fd ].mask ;
239
+ int ev_mask = ctx -> monitored [p_api -> fds [idx ].fd ].mask ;
240
240
// We want to remember the previous events only if they're not of type
241
241
// CLOSE or TIMER
242
242
int mask = ev_mask & (EV_CLOSEFD | EV_TIMERFD ) ? ev_mask : 0 ;
@@ -270,10 +270,10 @@ static int ev_api_watch_fd(struct ev_ctx *ctx, int fd)
270
270
p_api -> fds [p_api -> nfds ].fd = fd ;
271
271
p_api -> fds [p_api -> nfds ].events = POLLIN ;
272
272
p_api -> nfds ++ ;
273
- if (p_api -> nfds >= p_api -> events_monitored ) {
274
- p_api -> events_monitored *= 2 ;
275
- p_api -> fds = try_realloc ( p_api -> fds , p_api -> events_monitored *
276
- sizeof (struct pollfd ));
273
+ if (p_api -> nfds >= p_api -> monitored ) {
274
+ p_api -> monitored *= 2 ;
275
+ p_api -> fds =
276
+ try_realloc ( p_api -> fds , p_api -> monitored * sizeof (struct pollfd ));
277
277
}
278
278
return EV_OK ;
279
279
}
@@ -307,10 +307,10 @@ static int ev_api_register_event(struct ev_ctx *ctx, int fd, int mask)
307
307
if (mask & EV_WRITE )
308
308
p_api -> fds [p_api -> nfds ].events |= POLLOUT ;
309
309
p_api -> nfds ++ ;
310
- if (p_api -> nfds >= p_api -> events_monitored ) {
311
- p_api -> events_monitored *= 2 ;
312
- p_api -> fds = try_realloc ( p_api -> fds , p_api -> events_monitored *
313
- sizeof (struct pollfd ));
310
+ if (p_api -> nfds >= p_api -> monitored ) {
311
+ p_api -> monitored *= 2 ;
312
+ p_api -> fds =
313
+ try_realloc ( p_api -> fds , p_api -> monitored * sizeof (struct pollfd ));
314
314
}
315
315
return EV_OK ;
316
316
}
@@ -334,7 +334,7 @@ static int ev_api_fire_event(struct ev_ctx *ctx, int fd, int mask)
334
334
static inline struct ev * ev_api_fetch_event (const struct ev_ctx * ctx , int idx ,
335
335
int mask )
336
336
{
337
- return ctx -> events_monitored + ((struct poll_api * )ctx -> api )-> fds [idx ].fd ;
337
+ return ctx -> monitored + ((struct poll_api * )ctx -> api )-> fds [idx ].fd ;
338
338
}
339
339
340
340
#elif defined(SELECT )
@@ -380,7 +380,7 @@ static void ev_api_destroy(struct ev_ctx *ctx) { free_memory(ctx->api); }
380
380
static int ev_api_get_event_type (struct ev_ctx * ctx , int idx )
381
381
{
382
382
struct select_api * s_api = ctx -> api ;
383
- int ev_mask = ctx -> events_monitored [idx ].mask ;
383
+ int ev_mask = ctx -> monitored [idx ].mask ;
384
384
// We want to remember the previous events only if they're not of type
385
385
// CLOSE or TIMER
386
386
int mask = ev_mask & (EV_CLOSEFD | EV_TIMERFD ) ? ev_mask : 0 ;
@@ -477,7 +477,7 @@ static int ev_api_fire_event(struct ev_ctx *ctx, int fd, int mask)
477
477
static inline struct ev * ev_api_fetch_event (const struct ev_ctx * ctx , int idx ,
478
478
int mask )
479
479
{
480
- return ctx -> events_monitored + idx ;
480
+ return ctx -> monitored + idx ;
481
481
}
482
482
483
483
#elif defined(KQUEUE )
@@ -523,10 +523,10 @@ static int ev_api_get_event_type(struct ev_ctx *ctx, int idx)
523
523
{
524
524
struct kqueue_api * k_api = ctx -> api ;
525
525
int events = k_api -> events [idx ].flags ;
526
- int ev_mask = ctx -> events_monitored [k_api -> events [idx ].ident ].mask ;
526
+ int ev_mask = ctx -> monitored [k_api -> events [idx ].ident ].mask ;
527
527
// We want to remember the previous events only if they're not of type
528
528
// CLOSE or TIMER
529
- int mask = ev_mask & (EV_CLOSEFD | EV_TIMERFD ) ? ev_mask : EV_NONE ;
529
+ int mask = ev_mask & (EV_CLOSEFD | EV_TIMERFD ) ? ev_mask : EV_NONE ;
530
530
if (events & (EV_EOF | EV_ERROR ))
531
531
mask |= EV_DISCONNECT ;
532
532
if (events & EVFILT_READ )
@@ -551,7 +551,7 @@ static int ev_api_del_fd(struct ev_ctx *ctx, int fd)
551
551
{
552
552
struct kqueue_api * k_api = ctx -> api ;
553
553
struct kevent ke ;
554
- int ev_mask = ctx -> events_monitored [fd ].mask ;
554
+ int ev_mask = ctx -> monitored [fd ].mask ;
555
555
int mask = 0 ;
556
556
if (ev_mask & EV_READ )
557
557
mask |= EVFILT_READ ;
@@ -610,13 +610,13 @@ static inline struct ev *ev_api_fetch_event(const struct ev_ctx *ctx, int idx,
610
610
{
611
611
(void )mask ; // silence compiler warning
612
612
int fd = ((struct kqueue_api * )ctx -> api )-> events [idx ].ident ;
613
- return ctx -> events_monitored + fd ;
613
+ return ctx -> monitored + fd ;
614
614
}
615
615
616
616
#endif // KQUEUE
617
617
618
618
/*
619
- * Process the event at the position idx in the events_monitored array. Read or
619
+ * Process the event at the position idx in the monitored array. Read or
620
620
* write events can be executed on the same iteration, differentiating just
621
621
* on EV_CLOSEFD or EV_EVENTFD.
622
622
* Returns the number of fired callbacks.
@@ -670,8 +670,7 @@ static int ev_process_event(struct ev_ctx *ctx, int idx, int mask)
670
670
* context.
671
671
*/
672
672
static void ev_add_monitored (struct ev_ctx * ctx , int fd , int mask ,
673
- void (* callback )(struct ev_ctx * , void * ),
674
- void * ptr )
673
+ ev_callback cb , void * ptr )
675
674
{
676
675
/*
677
676
* TODO check for fd <= 1024 if using SELECT
@@ -682,21 +681,21 @@ static void ev_add_monitored(struct ev_ctx *ctx, int fd, int mask,
682
681
int i = ctx -> maxevents ;
683
682
ctx -> maxevents = fd ;
684
683
if (fd > ctx -> events_nr ) {
685
- ctx -> events_monitored = try_realloc ( ctx -> events_monitored ,
686
- (fd + 1 ) * sizeof (struct ev ));
684
+ ctx -> monitored =
685
+ try_realloc ( ctx -> monitored , (fd + 1 ) * sizeof (struct ev ));
687
686
for (; i < ctx -> maxevents ; ++ i )
688
- ctx -> events_monitored [i ].mask = EV_NONE ;
687
+ ctx -> monitored [i ].mask = EV_NONE ;
689
688
}
690
689
}
691
- ctx -> events_monitored [fd ].fd = fd ;
692
- ctx -> events_monitored [fd ].mask |= mask ;
690
+ ctx -> monitored [fd ].fd = fd ;
691
+ ctx -> monitored [fd ].mask |= mask ;
693
692
if (mask & EV_READ ) {
694
- ctx -> events_monitored [fd ].rdata = ptr ;
695
- ctx -> events_monitored [fd ].rcallback = callback ;
693
+ ctx -> monitored [fd ].rdata = ptr ;
694
+ ctx -> monitored [fd ].rcallback = cb ;
696
695
}
697
696
if (mask & EV_WRITE ) {
698
- ctx -> events_monitored [fd ].wdata = ptr ;
699
- ctx -> events_monitored [fd ].wcallback = callback ;
697
+ ctx -> monitored [fd ].wdata = ptr ;
698
+ ctx -> monitored [fd ].wcallback = cb ;
700
699
}
701
700
}
702
701
@@ -710,22 +709,22 @@ int ev_init(struct ev_ctx *ctx, int events_nr)
710
709
int err = ev_api_init (ctx , events_nr );
711
710
if (err < 0 )
712
711
return err ;
713
- ctx -> stop = 0 ;
714
- ctx -> fired_events = 0 ;
715
- ctx -> maxevents = events_nr ;
716
- ctx -> events_nr = events_nr ;
717
- ctx -> events_monitored = try_calloc (events_nr , sizeof (struct ev ));
712
+ ctx -> stop = 0 ;
713
+ ctx -> fired_events = 0 ;
714
+ ctx -> maxevents = events_nr ;
715
+ ctx -> events_nr = events_nr ;
716
+ ctx -> monitored = try_calloc (events_nr , sizeof (struct ev ));
718
717
return EV_OK ;
719
718
}
720
719
721
- void ev_destroy (struct ev_ctx * ctx )
720
+ void ev_free (struct ev_ctx * ctx )
722
721
{
723
722
for (int i = 0 ; i < ctx -> maxevents ; ++ i ) {
724
- if (!(ctx -> events_monitored [i ].mask & EV_CLOSEFD ) &&
725
- ctx -> events_monitored [i ].mask != EV_NONE )
726
- ev_del_fd (ctx , ctx -> events_monitored [i ].fd );
723
+ if (!(ctx -> monitored [i ].mask & EV_CLOSEFD ) &&
724
+ ctx -> monitored [i ].mask != EV_NONE )
725
+ ev_delete (ctx , ctx -> monitored [i ].fd );
727
726
}
728
- free_memory (ctx -> events_monitored );
727
+ free_memory (ctx -> monitored );
729
728
ev_api_destroy (ctx );
730
729
}
731
730
@@ -761,15 +760,15 @@ int ev_run(struct ev_ctx *ctx)
761
760
762
761
void ev_stop (struct ev_ctx * ctx ) { ctx -> stop = 1 ; }
763
762
764
- int ev_watch_fd (struct ev_ctx * ctx , int fd , int mask )
763
+ int ev_watch (struct ev_ctx * ctx , int fd , int mask )
765
764
{
766
765
ev_add_monitored (ctx , fd , mask , NULL , NULL );
767
766
return ev_api_watch_fd (ctx , fd );
768
767
}
769
768
770
- int ev_del_fd (struct ev_ctx * ctx , int fd )
769
+ int ev_delete (struct ev_ctx * ctx , int fd )
771
770
{
772
- memset (ctx -> events_monitored + fd , 0x00 , sizeof (struct ev ));
771
+ memset (ctx -> monitored + fd , 0x00 , sizeof (struct ev ));
773
772
return ev_api_del_fd (ctx , fd );
774
773
}
775
774
@@ -785,10 +784,10 @@ int ev_del_fd(struct ev_ctx *ctx, int fd)
785
784
* - callback: is a function pointer to the routine we want to execute
786
785
* - data: an opaque pointer to the arguments for the callback.
787
786
*/
788
- int ev_register_event (struct ev_ctx * ctx , int fd , int mask ,
789
- void ( * callback )( struct ev_ctx * , void * ), void * data )
787
+ int ev_register_event (struct ev_ctx * ctx , int fd , int mask , ev_callback cb ,
788
+ void * data )
790
789
{
791
- ev_add_monitored (ctx , fd , mask , callback , data );
790
+ ev_add_monitored (ctx , fd , mask , cb , data );
792
791
int ret = 0 ;
793
792
ret = ev_api_register_event (ctx , fd , mask );
794
793
if (ret < 0 )
@@ -807,8 +806,7 @@ int ev_register_event(struct ev_ctx *ctx, int fd, int mask,
807
806
* loop, specifying, seconds and/or nanoseconds defining how often the callback
808
807
* should be executed.
809
808
*/
810
- int ev_register_cron (struct ev_ctx * ctx ,
811
- void (* callback )(struct ev_ctx * , void * ), void * data ,
809
+ int ev_register_cron (struct ev_ctx * ctx , ev_callback cb , void * data ,
812
810
long long s , long long ns )
813
811
{
814
812
#ifdef __linux__
@@ -825,14 +823,14 @@ int ev_register_cron(struct ev_ctx *ctx,
825
823
return - EV_ERR ;
826
824
827
825
// Add the timer to the event loop
828
- ev_add_monitored (ctx , timerfd , EV_TIMERFD | EV_READ , callback , data );
826
+ ev_add_monitored (ctx , timerfd , EV_TIMERFD | EV_READ , cb , data );
829
827
return ev_api_watch_fd (ctx , timerfd );
830
828
#else
831
829
struct kqueue_api * k_api = ctx -> api ;
832
830
// milliseconds
833
831
unsigned period = (s * 1000 ) + (ns / 100 );
834
832
int fd = socket (AF_INET , SOCK_STREAM , 0 );
835
- ev_add_monitored (ctx , fd , EV_TIMERFD | EV_READ , callback , data );
833
+ ev_add_monitored (ctx , fd , EV_TIMERFD | EV_READ , cb , data );
836
834
struct kevent ke ;
837
835
EV_SET (& ke , fd , EVFILT_TIMER , EV_ADD | EV_ENABLE , 0 , period , 0 );
838
836
if (kevent (k_api -> fd , & ke , 1 , NULL , 0 , NULL ) == -1 )
@@ -853,11 +851,10 @@ int ev_register_cron(struct ev_ctx *ctx,
853
851
* - callback: is a function pointer to the routine we want to execute
854
852
* - data: an opaque pointer to the arguments for the callback.
855
853
*/
856
- int ev_fire_event (struct ev_ctx * ctx , int fd , int mask ,
857
- void (* callback )(struct ev_ctx * , void * ), void * data )
854
+ int ev_add (struct ev_ctx * ctx , int fd , int mask , ev_callback cb , void * data )
858
855
{
859
856
int ret = 0 ;
860
- ev_add_monitored (ctx , fd , mask , callback , data );
857
+ ev_add_monitored (ctx , fd , mask , cb , data );
861
858
ret = ev_api_fire_event (ctx , fd , mask );
862
859
if (ret < 0 )
863
860
return - EV_ERR ;
0 commit comments