2015-04-13 15:11:11 +00:00
|
|
|
/*
|
|
|
|
* Functions managing applets
|
|
|
|
*
|
|
|
|
* Copyright 2000-2015 Willy Tarreau <w@1wt.eu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <common/config.h>
|
|
|
|
#include <common/mini-clist.h>
|
|
|
|
#include <proto/applet.h>
|
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 16:30:18 +00:00
|
|
|
#include <proto/channel.h>
|
2015-04-19 07:59:31 +00:00
|
|
|
#include <proto/stream.h>
|
|
|
|
#include <proto/stream_interface.h>
|
2018-05-25 14:58:52 +00:00
|
|
|
#include <proto/task.h>
|
2015-04-13 15:11:11 +00:00
|
|
|
|
2016-12-06 08:13:22 +00:00
|
|
|
unsigned int nb_applets = 0;
|
2017-06-19 10:38:55 +00:00
|
|
|
|
2018-05-25 14:58:52 +00:00
|
|
|
struct task *task_run_applet(struct task *t, void *context, unsigned short state)
|
2015-04-19 07:59:31 +00:00
|
|
|
{
|
2018-05-25 14:58:52 +00:00
|
|
|
struct appctx *app = context;
|
|
|
|
struct stream_interface *si = app->owner;
|
2015-04-19 07:59:31 +00:00
|
|
|
|
2018-05-25 14:58:52 +00:00
|
|
|
if (app->state & APPLET_WANT_DIE) {
|
|
|
|
__appctx_free(app);
|
|
|
|
return NULL;
|
2017-06-26 14:36:53 +00:00
|
|
|
}
|
2018-05-25 14:58:52 +00:00
|
|
|
/* Now we'll try to allocate the input buffer. We wake up the
|
|
|
|
* applet in all cases. So this is the applet responsibility to
|
|
|
|
* check if this buffer was allocated or not. This let a chance
|
|
|
|
* for applets to do some other processing if needed. */
|
2018-10-25 08:21:41 +00:00
|
|
|
if (!si_alloc_ibuf(si, &app->buffer_wait))
|
2018-05-25 14:58:52 +00:00
|
|
|
si_applet_cant_put(si);
|
|
|
|
|
|
|
|
/* We always pretend the applet can't get and doesn't want to
|
|
|
|
* put, it's up to it to change this if needed. This ensures
|
|
|
|
* that one applet which ignores any event will not spin.
|
2015-09-25 15:56:16 +00:00
|
|
|
*/
|
2018-05-25 14:58:52 +00:00
|
|
|
si_applet_cant_get(si);
|
|
|
|
si_applet_stop_put(si);
|
2015-04-19 07:59:31 +00:00
|
|
|
|
2018-05-25 14:58:52 +00:00
|
|
|
app->applet->fct(app);
|
|
|
|
si_applet_wake_cb(si);
|
|
|
|
channel_release_buffer(si_ic(si), &app->buffer_wait);
|
|
|
|
return t;
|
2015-04-19 07:59:31 +00:00
|
|
|
}
|
2017-06-19 10:38:55 +00:00
|
|
|
|