mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-03 07:31:54 +00:00
Conf: Yielding from cf_read
This commit is contained in:
parent
4ec43aa137
commit
4cf2818c98
14
conf/conf.c
14
conf/conf.c
@ -215,11 +215,17 @@ config_parse(struct conf_order *order)
|
|||||||
coro_resume(ctx->coro);
|
coro_resume(ctx->coro);
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_yield(struct cf_context *ctx)
|
void config_yield(struct conf_order *order)
|
||||||
{
|
{
|
||||||
DBG("Conf: Yield\n");
|
if (order->flags & CO_SYNC)
|
||||||
ev_schedule(ctx->ev_resume);
|
return;
|
||||||
DBG("Conf: Yield resumed\n");
|
|
||||||
|
ASSERT(order->ctx);
|
||||||
|
ASSERT(order->ctx->ev_resume);
|
||||||
|
DBG("Conf %p: Yield\n", order);
|
||||||
|
ev_schedule(order->ctx->ev_resume);
|
||||||
|
coro_suspend();
|
||||||
|
DBG("Conf %p: Resumed\n", order);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,6 +104,9 @@ void config_parse(struct conf_order *order);
|
|||||||
/** Callback for returning error from parser hooks */
|
/** Callback for returning error from parser hooks */
|
||||||
void cf_error(struct cf_context *, const char *msg, ...) NORET;
|
void cf_error(struct cf_context *, const char *msg, ...) NORET;
|
||||||
|
|
||||||
|
/** Yield callable from conf_order callbacks */
|
||||||
|
void config_yield(struct conf_order *order);
|
||||||
|
|
||||||
void config_free(struct config *);
|
void config_free(struct config *);
|
||||||
int config_commit(struct config *, int type, uint timeout);
|
int config_commit(struct config *, int type, uint timeout);
|
||||||
int config_confirm(void);
|
int config_confirm(void);
|
||||||
|
@ -110,6 +110,7 @@ sysdep_commit(struct config *new, struct config *old UNUSED)
|
|||||||
|
|
||||||
#define MAX_INCLUDE_DEPTH 8
|
#define MAX_INCLUDE_DEPTH 8
|
||||||
#define UCO struct unix_conf_order *uco = (struct unix_conf_order *) co
|
#define UCO struct unix_conf_order *uco = (struct unix_conf_order *) co
|
||||||
|
#define YIELD_AFTER 1048576
|
||||||
|
|
||||||
struct unix_conf_order {
|
struct unix_conf_order {
|
||||||
struct conf_order co; /* First field of struct conf_order is resource r; */
|
struct conf_order co; /* First field of struct conf_order is resource r; */
|
||||||
@ -119,6 +120,7 @@ struct unix_conf_order {
|
|||||||
event *ev; /* Start event if called from CLI */
|
event *ev; /* Start event if called from CLI */
|
||||||
int type; /* Type of reconfig */
|
int type; /* Type of reconfig */
|
||||||
uint timeout; /* Config timeout */
|
uint timeout; /* Config timeout */
|
||||||
|
uint bytecount; /* Have read this number of bytes since last yield */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -150,9 +152,14 @@ static int
|
|||||||
unix_cf_read(struct conf_order *co, byte *dest, uint len)
|
unix_cf_read(struct conf_order *co, byte *dest, uint len)
|
||||||
{
|
{
|
||||||
UCO;
|
UCO;
|
||||||
|
|
||||||
ASSERT(uco->ifs->state == co->state);
|
ASSERT(uco->ifs->state == co->state);
|
||||||
|
|
||||||
|
if (uco->bytecount > YIELD_AFTER)
|
||||||
|
{
|
||||||
|
uco->bytecount -= YIELD_AFTER;
|
||||||
|
config_yield(co);
|
||||||
|
}
|
||||||
|
|
||||||
if (uco->ifs->fd == -1)
|
if (uco->ifs->fd == -1)
|
||||||
uco->ifs->fd = open(co->state->name, O_RDONLY);
|
uco->ifs->fd = open(co->state->name, O_RDONLY);
|
||||||
|
|
||||||
@ -169,6 +176,8 @@ unix_cf_read(struct conf_order *co, byte *dest, uint len)
|
|||||||
int l = read(uco->ifs->fd, dest, len);
|
int l = read(uco->ifs->fd, dest, len);
|
||||||
if (l < 0)
|
if (l < 0)
|
||||||
cf_error(co->ctx, "Read error: %m");
|
cf_error(co->ctx, "Read error: %m");
|
||||||
|
|
||||||
|
uco->bytecount += l;
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user