Skip to content

Commit db5fe24

Browse files
committed
Add application flags in the reactor fd map
The new app flags allow the code using a reactor to mark and check the existing fds, without interfering with the reactor internals
1 parent 65af0b5 commit db5fe24

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

io_wait.c

+29
Original file line numberDiff line numberDiff line change
@@ -756,3 +756,32 @@ void fix_poll_method( enum poll_types *poll_method )
756756
}
757757

758758

759+
int io_set_app_flag( io_wait_h *h , int type, int app_flag)
760+
{
761+
int i;
762+
int res=0;
763+
764+
for( i=0 ; i<h->fd_no ; i++) {
765+
if (h->fd_hash[i].fd<=0 && h->fd_hash[i].type==type) {
766+
h->fd_hash[i].app_flags |= app_flag;
767+
res = 1;
768+
}
769+
}
770+
return res;
771+
}
772+
773+
774+
int io_check_app_flag( io_wait_h *h , int app_flag)
775+
{
776+
int i;
777+
778+
for( i=0 ; i<h->fd_no ; i++) {
779+
if ( h->fd_hash[i].fd<=0 &&
780+
(h->fd_hash[i].app_flags & app_flag) )
781+
return 1;
782+
}
783+
/* nothing found, return false*/
784+
return 0;
785+
786+
}
787+

io_wait.h

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ struct fd_map {
109109
int flags; /* so far used to indicate whether we should
110110
* read, write or both ; last 4 are reserved for
111111
* internal usage */
112+
int app_flags; /* flags to be used by upper layer apps, not by
113+
* the reactor */
112114
};
113115

114116

@@ -838,5 +840,9 @@ int init_io_wait(io_wait_h* h, char *name, int max_fd,
838840
/*! \brief destroys everything init_io_wait allocated */
839841
void destroy_io_wait(io_wait_h* h);
840842

843+
int io_set_app_flag( io_wait_h *h , int type, int app_flag);
844+
845+
int io_check_app_flag( io_wait_h *h , int app_flag);
846+
841847

842848
#endif

reactor_defs.h

+6
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,11 @@ int init_reactor_size(void);
101101
#define reactor_is_empty() \
102102
(_worker_io.fd_no==0)
103103

104+
#define reactor_set_app_flag( _type, _app_flag) \
105+
io_set_app_flag( &_worker_io , _type, _app_flag)
106+
107+
#define reactor_check_app_flag(_app_flag) \
108+
io_check_app_flag( &_worker_io , _app_flag)
109+
104110
#endif
105111

0 commit comments

Comments
 (0)