Willy Tarreau | 81f38d6 | 2015-04-13 17:11:11 +0200 | [diff] [blame] | 1 | /* |
| 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 Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 19 | #include <proto/channel.h> |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 20 | #include <proto/stream.h> |
| 21 | #include <proto/stream_interface.h> |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 22 | #include <proto/task.h> |
Willy Tarreau | 81f38d6 | 2015-04-13 17:11:11 +0200 | [diff] [blame] | 23 | |
Christopher Faulet | 1cbe74c | 2016-12-06 09:13:22 +0100 | [diff] [blame] | 24 | unsigned int nb_applets = 0; |
Emeric Brun | 1138fd0 | 2017-06-19 12:38:55 +0200 | [diff] [blame] | 25 | |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 26 | struct task *task_run_applet(struct task *t, void *context, unsigned short state) |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 27 | { |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 28 | struct appctx *app = context; |
| 29 | struct stream_interface *si = app->owner; |
Christopher Faulet | b4a4d9a | 2017-11-15 22:14:49 +0100 | [diff] [blame] | 30 | |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 31 | if (app->state & APPLET_WANT_DIE) { |
| 32 | __appctx_free(app); |
| 33 | return NULL; |
Christopher Faulet | 7163056 | 2017-11-14 11:30:47 +0100 | [diff] [blame] | 34 | } |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 35 | /* 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 Tarreau | 581abd3 | 2018-10-25 10:21:41 +0200 | [diff] [blame] | 39 | if (!si_alloc_ibuf(si, &app->buffer_wait)) |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 40 | si_applet_cant_put(si); |
Emeric Brun | 1138fd0 | 2017-06-19 12:38:55 +0200 | [diff] [blame] | 41 | |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 42 | /* 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 Tarreau | 9994238 | 2015-09-25 17:56:16 +0200 | [diff] [blame] | 45 | */ |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 46 | si_applet_cant_get(si); |
| 47 | si_applet_stop_put(si); |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 48 | |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 49 | app->applet->fct(app); |
| 50 | si_applet_wake_cb(si); |
| 51 | channel_release_buffer(si_ic(si), &app->buffer_wait); |
| 52 | return t; |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 53 | } |
Emeric Brun | 1138fd0 | 2017-06-19 12:38:55 +0200 | [diff] [blame] | 54 | |