blob: 6911ab4a9e536e1ccfed0d8be9f6e79b583d0386 [file] [log] [blame]
Willy Tarreau81f38d62015-04-13 17:11:11 +02001/*
2 * Functions managing applets
3 *
4 * Copyright 2000-2015 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15
16#include <common/config.h>
17#include <common/mini-clist.h>
18#include <proto/applet.h>
Christopher Fauleta73e59b2016-12-09 17:30:18 +010019#include <proto/channel.h>
Willy Tarreau3c595ac2015-04-19 09:59:31 +020020#include <proto/stream.h>
21#include <proto/stream_interface.h>
Olivier Houchard673867c2018-05-25 16:58:52 +020022#include <proto/task.h>
Willy Tarreau81f38d62015-04-13 17:11:11 +020023
Christopher Faulet1cbe74c2016-12-06 09:13:22 +010024unsigned int nb_applets = 0;
Emeric Brun1138fd02017-06-19 12:38:55 +020025
Olivier Houchard673867c2018-05-25 16:58:52 +020026struct task *task_run_applet(struct task *t, void *context, unsigned short state)
Willy Tarreau3c595ac2015-04-19 09:59:31 +020027{
Olivier Houchard673867c2018-05-25 16:58:52 +020028 struct appctx *app = context;
29 struct stream_interface *si = app->owner;
Christopher Fauletb4a4d9a2017-11-15 22:14:49 +010030
Olivier Houchard673867c2018-05-25 16:58:52 +020031 if (app->state & APPLET_WANT_DIE) {
32 __appctx_free(app);
33 return NULL;
Christopher Faulet71630562017-11-14 11:30:47 +010034 }
Olivier Houchard673867c2018-05-25 16:58:52 +020035 /* Now we'll try to allocate the input buffer. We wake up the
36 * applet in all cases. So this is the applet responsibility to
37 * check if this buffer was allocated or not. This let a chance
38 * for applets to do some other processing if needed. */
Willy Tarreau581abd32018-10-25 10:21:41 +020039 if (!si_alloc_ibuf(si, &app->buffer_wait))
Olivier Houchard673867c2018-05-25 16:58:52 +020040 si_applet_cant_put(si);
Emeric Brun1138fd02017-06-19 12:38:55 +020041
Olivier Houchard673867c2018-05-25 16:58:52 +020042 /* We always pretend the applet can't get and doesn't want to
43 * put, it's up to it to change this if needed. This ensures
44 * that one applet which ignores any event will not spin.
Willy Tarreau99942382015-09-25 17:56:16 +020045 */
Olivier Houchard673867c2018-05-25 16:58:52 +020046 si_applet_cant_get(si);
47 si_applet_stop_put(si);
Willy Tarreau3c595ac2015-04-19 09:59:31 +020048
Olivier Houchard673867c2018-05-25 16:58:52 +020049 app->applet->fct(app);
50 si_applet_wake_cb(si);
51 channel_release_buffer(si_ic(si), &app->buffer_wait);
52 return t;
Willy Tarreau3c595ac2015-04-19 09:59:31 +020053}
Emeric Brun1138fd02017-06-19 12:38:55 +020054