Event priority. Backend socket has higher prio.
This commit is contained in:
parent
f511cb0030
commit
7e1a00669c
7 changed files with 89 additions and 48 deletions
|
|
@ -66,6 +66,7 @@
|
|||
#include "clixon_err.h"
|
||||
#include "clixon_sig.h"
|
||||
#include "clixon_proc.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_event.h"
|
||||
|
||||
/*
|
||||
|
|
@ -77,13 +78,14 @@
|
|||
* Types
|
||||
*/
|
||||
struct event_data{
|
||||
struct event_data *e_next; /* next in list */
|
||||
int (*e_fn)(int, void*); /* function */
|
||||
enum {EVENT_FD, EVENT_TIME} e_type; /* type of event */
|
||||
int e_fd; /* File descriptor */
|
||||
struct timeval e_time; /* Timeout */
|
||||
void *e_arg; /* function argument */
|
||||
char e_string[EVENT_STRLEN]; /* string for debugging */
|
||||
struct event_data *e_next; /* Next in list */
|
||||
int (*e_fn)(int, void*); /* Callback function */
|
||||
enum {EVENT_FD, EVENT_TIME} e_type; /* Type of event */
|
||||
int e_fd; /* File descriptor */
|
||||
int e_prio; /* 1: high-prio FD:s only*/
|
||||
struct timeval e_time; /* Timeout */
|
||||
void *e_arg; /* Function argument */
|
||||
char e_string[EVENT_STRLEN]; /* String for debugging */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -168,10 +170,11 @@ clicon_sig_ignore_get(void)
|
|||
|
||||
/*! Register a callback function to be called on input on a file descriptor.
|
||||
*
|
||||
* @param[in] fd File descriptor
|
||||
* @param[in] fn Function to call when input available on fd
|
||||
* @param[in] arg Argument to function fn
|
||||
* @param[in] str Describing string for logging
|
||||
* @param[in] fd File descriptor
|
||||
* @param[in] fn Function to call when input available on fd
|
||||
* @param[in] arg Argument to function fn
|
||||
* @param[in] str Describing string for logging
|
||||
* @param[in] prio Priority (0 or 1)
|
||||
* @code
|
||||
* int fn(int fd, void *arg){
|
||||
* }
|
||||
|
|
@ -180,10 +183,11 @@ clicon_sig_ignore_get(void)
|
|||
* @see clixon_event_unreg_fd
|
||||
*/
|
||||
int
|
||||
clixon_event_reg_fd(int fd,
|
||||
int (*fn)(int, void*),
|
||||
void *arg,
|
||||
char *str)
|
||||
clixon_event_reg_fd_prio(int fd,
|
||||
int (*fn)(int, void*),
|
||||
void *arg,
|
||||
char *str,
|
||||
int prio)
|
||||
{
|
||||
struct event_data *e;
|
||||
|
||||
|
|
@ -197,12 +201,22 @@ clixon_event_reg_fd(int fd,
|
|||
e->e_fn = fn;
|
||||
e->e_arg = arg;
|
||||
e->e_type = EVENT_FD;
|
||||
e->e_prio = prio;
|
||||
e->e_next = ee;
|
||||
ee = e;
|
||||
clixon_debug(CLIXON_DBG_EVENT | CLIXON_DBG_DETAIL, "registering %s", e->e_string);
|
||||
clixon_debug(CLIXON_DBG_EVENT, "registering %s", e->e_string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
clixon_event_reg_fd(int fd,
|
||||
int (*fn)(int, void*),
|
||||
void *arg,
|
||||
char *str)
|
||||
{
|
||||
return clixon_event_reg_fd_prio(fd, fn, arg, str, 0);
|
||||
}
|
||||
|
||||
/*! Deregister a file descriptor callback
|
||||
*
|
||||
* @param[in] s File descriptor
|
||||
|
|
@ -217,9 +231,9 @@ int
|
|||
clixon_event_unreg_fd(int s,
|
||||
int (*fn)(int, void*))
|
||||
{
|
||||
struct event_data *e;
|
||||
struct event_data **e_prev;
|
||||
struct event_data *e;
|
||||
int found = 0;
|
||||
struct event_data **e_prev;
|
||||
|
||||
e_prev = ⅇ
|
||||
for (e = ee; e; e = e->e_next){
|
||||
|
|
@ -315,8 +329,9 @@ int
|
|||
clixon_event_unreg_timeout(int (*fn)(int, void*),
|
||||
void *arg)
|
||||
{
|
||||
struct event_data *e, **e_prev;
|
||||
int found = 0;
|
||||
struct event_data *e;
|
||||
int found = 0;
|
||||
struct event_data **e_prev;
|
||||
|
||||
e_prev = &ee_timers;
|
||||
for (e = ee_timers; e; e = e->e_next){
|
||||
|
|
@ -365,13 +380,13 @@ int
|
|||
clixon_event_loop(clixon_handle h)
|
||||
{
|
||||
struct event_data *e;
|
||||
struct event_data *e_next;
|
||||
int n;
|
||||
struct timeval t;
|
||||
struct timeval t0;
|
||||
struct timeval tnull = {0,};
|
||||
fd_set fdset;
|
||||
int retval = -1;
|
||||
struct event_data *e_next;
|
||||
|
||||
while (clixon_exit_get() != 1){
|
||||
FD_ZERO(&fdset);
|
||||
|
|
@ -409,7 +424,7 @@ clixon_event_loop(clixon_handle h)
|
|||
* New select loop is called
|
||||
* (3) Other signals result in an error and return -1.
|
||||
*/
|
||||
clixon_debug(CLIXON_DBG_EVENT | CLIXON_DBG_DETAIL, "select: %s", strerror(errno));
|
||||
clixon_debug(CLIXON_DBG_EVENT, "select: %s", strerror(errno));
|
||||
if (clixon_exit_get() == 1){
|
||||
clixon_err(OE_EVENTS, errno, "select");
|
||||
retval = 0;
|
||||
|
|
@ -443,13 +458,33 @@ clixon_event_loop(clixon_handle h)
|
|||
free(e);
|
||||
}
|
||||
_ee_unreg = 0;
|
||||
for (e=ee; e; e=e_next){
|
||||
if (clixon_exit_get() == 1){
|
||||
break;
|
||||
if (clicon_option_bool(h, "CLICON_SOCK_PRIO")){
|
||||
for (e=ee; e; e=e_next) {
|
||||
if (clixon_exit_get() == 1)
|
||||
break;
|
||||
e_next = e->e_next;
|
||||
if (e->e_type == EVENT_FD && FD_ISSET(e->e_fd, &fdset) && e->e_prio){
|
||||
clixon_debug(CLIXON_DBG_EVENT, "FD_ISSET: %s prio:%d", e->e_string, e->e_prio);
|
||||
if ((*e->e_fn)(e->e_fd, e->e_arg) < 0){
|
||||
clixon_debug(CLIXON_DBG_EVENT, "Error in: %s", e->e_string);
|
||||
goto err;
|
||||
}
|
||||
if (_ee_unreg){
|
||||
_ee_unreg = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Unprio
|
||||
* Note that without prio, round-robin fairness is ensured, not with prio */
|
||||
for (e=ee; e; e=e_next){
|
||||
if (clixon_exit_get() == 1)
|
||||
break;
|
||||
e_next = e->e_next;
|
||||
if(e->e_type == EVENT_FD && FD_ISSET(e->e_fd, &fdset)){
|
||||
clixon_debug(CLIXON_DBG_EVENT | CLIXON_DBG_DETAIL, "FD_ISSET: %s", e->e_string);
|
||||
if (e->e_type == EVENT_FD && FD_ISSET(e->e_fd, &fdset) && e->e_prio==0){
|
||||
clixon_debug(CLIXON_DBG_EVENT, "FD_ISSET: %s", e->e_string);
|
||||
if ((*e->e_fn)(e->e_fd, e->e_arg) < 0){
|
||||
clixon_debug(CLIXON_DBG_EVENT, "Error in: %s", e->e_string);
|
||||
goto err;
|
||||
|
|
@ -458,6 +493,8 @@ clixon_event_loop(clixon_handle h)
|
|||
_ee_unreg = 0;
|
||||
break;
|
||||
}
|
||||
if (clicon_option_bool(h, "CLICON_SOCK_PRIO"))
|
||||
break;
|
||||
}
|
||||
}
|
||||
clixon_exit_decr(); /* If exit is set and > 1, decrement it (and exit when 1) */
|
||||
|
|
@ -475,7 +512,8 @@ clixon_event_loop(clixon_handle h)
|
|||
int
|
||||
clixon_event_exit(void)
|
||||
{
|
||||
struct event_data *e, *e_next;
|
||||
struct event_data *e;
|
||||
struct event_data *e_next;
|
||||
|
||||
e_next = ee;
|
||||
while ((e = e_next) != NULL){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue