Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 4c283dc | 2009-12-29 14:36:34 +0100 | [diff] [blame] | 2 | * include/types/stream_interface.h |
| 3 | * This file describes the stream_interface struct and associated constants. |
| 4 | * |
Willy Tarreau | a2df3fa | 2014-11-28 11:53:35 +0100 | [diff] [blame] | 5 | * Copyright (C) 2000-2014 Willy Tarreau - w@1wt.eu |
Willy Tarreau | 4c283dc | 2009-12-29 14:36:34 +0100 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 21 | |
| 22 | #ifndef _TYPES_STREAM_INTERFACE_H |
| 23 | #define _TYPES_STREAM_INTERFACE_H |
| 24 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 25 | #include <types/obj_type.h> |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 26 | #include <common/config.h> |
| 27 | |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 28 | /* A stream interface must have its own errors independently of the buffer's, |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 29 | * so that applications can rely on what the buffer reports while the stream |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 30 | * interface is performing some retries (eg: connection error). Some states are |
| 31 | * transient and do not last beyond process_session(). |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 32 | */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 33 | enum si_state { |
Willy Tarreau | efb453c | 2008-10-26 20:49:47 +0100 | [diff] [blame] | 34 | SI_ST_INI = 0, /* interface not sollicitated yet */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 35 | SI_ST_REQ, /* [transient] connection initiation desired and not started yet */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 36 | SI_ST_QUE, /* interface waiting in queue */ |
| 37 | SI_ST_TAR, /* interface in turn-around state after failed connect attempt */ |
| 38 | SI_ST_ASS, /* server just assigned to this interface */ |
| 39 | SI_ST_CON, /* initiated connection request (resource exists) */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 40 | SI_ST_CER, /* [transient] previous connection attempt failed (resource released) */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 41 | SI_ST_EST, /* connection established (resource exists) */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 42 | SI_ST_DIS, /* [transient] disconnected from other side, but cleanup not done yet */ |
Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 43 | SI_ST_CLO, /* stream intf closed, might not existing anymore. Buffers shut. */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 44 | } __attribute__((packed)); |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 45 | |
| 46 | /* error types reported on the streams interface for more accurate reporting */ |
| 47 | enum { |
Willy Tarreau | e5ed406 | 2008-08-30 03:17:31 +0200 | [diff] [blame] | 48 | SI_ET_NONE = 0x0000, /* no error yet, leave it to zero */ |
| 49 | SI_ET_QUEUE_TO = 0x0001, /* queue timeout */ |
| 50 | SI_ET_QUEUE_ERR = 0x0002, /* queue error (eg: full) */ |
| 51 | SI_ET_QUEUE_ABRT = 0x0004, /* aborted in queue by external cause */ |
| 52 | SI_ET_CONN_TO = 0x0008, /* connection timeout */ |
| 53 | SI_ET_CONN_ERR = 0x0010, /* connection error (eg: no server available) */ |
| 54 | SI_ET_CONN_ABRT = 0x0020, /* connection aborted by external cause (eg: abort) */ |
Willy Tarreau | 2d400bb | 2012-05-14 12:11:47 +0200 | [diff] [blame] | 55 | SI_ET_CONN_RES = 0x0040, /* connection aborted due to lack of resources */ |
| 56 | SI_ET_CONN_OTHER = 0x0080, /* connection aborted for other reason (eg: 500) */ |
| 57 | SI_ET_DATA_TO = 0x0100, /* timeout during data phase */ |
| 58 | SI_ET_DATA_ERR = 0x0200, /* error during data phase */ |
| 59 | SI_ET_DATA_ABRT = 0x0400, /* data phase aborted by external cause */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 60 | }; |
| 61 | |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 62 | /* flags set after I/O (16 bit) */ |
Willy Tarreau | d7704b5 | 2008-09-04 11:51:16 +0200 | [diff] [blame] | 63 | enum { |
| 64 | SI_FL_NONE = 0x0000, /* nothing */ |
| 65 | SI_FL_EXP = 0x0001, /* timeout has expired */ |
Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 66 | SI_FL_ERR = 0x0002, /* a non-recoverable error has occurred */ |
Willy Tarreau | b0ef735 | 2008-12-14 13:26:20 +0100 | [diff] [blame] | 67 | SI_FL_WAIT_ROOM = 0x0004, /* waiting for space to store incoming data */ |
| 68 | SI_FL_WAIT_DATA = 0x0008, /* waiting for more data to send */ |
Willy Tarreau | a5f5d8d | 2014-11-28 11:26:07 +0100 | [diff] [blame] | 69 | SI_FL_ISBACK = 0x0010, /* 0 for front-side SI, 1 for back-side */ |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 70 | SI_FL_DONT_WAKE = 0x0020, /* resync in progress, don't wake up */ |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 71 | SI_FL_INDEP_STR = 0x0040, /* independent streams = don't update rex on write */ |
Willy Tarreau | 4c283dc | 2009-12-29 14:36:34 +0100 | [diff] [blame] | 72 | SI_FL_NOLINGER = 0x0080, /* may close without lingering. One-shot. */ |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 73 | SI_FL_NOHALF = 0x0100, /* no half close, close both sides at once */ |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 74 | SI_FL_SRC_ADDR = 0x1000, /* get the source ip/port with getsockname */ |
Willy Tarreau | eb406dc | 2015-04-21 18:44:02 +0200 | [diff] [blame] | 75 | SI_FL_WANT_PUT = 0x2000, /* an applet would like to put some data into the buffer */ |
| 76 | SI_FL_WANT_GET = 0x4000, /* an applet would like to get some data from the buffer */ |
Willy Tarreau | d7704b5 | 2008-09-04 11:51:16 +0200 | [diff] [blame] | 77 | }; |
| 78 | |
Willy Tarreau | d414f8e | 2015-04-06 11:43:45 +0200 | [diff] [blame] | 79 | /* A stream interface has 3 parts : |
| 80 | * - the buffer side, which interfaces to the buffers. |
| 81 | * - the remote side, which describes the state and address of the other side. |
| 82 | * - the functions, which are used by the buffer side to communicate with the |
| 83 | * remote side from the buffer side. |
| 84 | */ |
| 85 | |
| 86 | /* Note that if an applet is registered, the update function will not be called |
| 87 | * by the session handler, so it may be used to resync flags at the end of the |
| 88 | * applet handler. See stream_int_update_embedded() for reference. |
| 89 | */ |
| 90 | struct stream_interface { |
| 91 | /* struct members used by the "buffer" side */ |
| 92 | enum si_state state; /* SI_ST* */ |
| 93 | enum si_state prev_state;/* SI_ST*, copy of previous state */ |
| 94 | unsigned short flags; /* SI_FL_* */ |
| 95 | unsigned int exp; /* wake up time for connect, queue, turn-around, ... */ |
| 96 | enum obj_type *end; /* points to the end point (connection or appctx) */ |
| 97 | struct si_ops *ops; /* general operations at the stream interface layer */ |
| 98 | |
| 99 | /* struct members below are the "remote" part, as seen from the buffer side */ |
| 100 | unsigned int err_type; /* first error detected, one of SI_ET_* */ |
| 101 | int conn_retries; /* number of connect retries left */ |
| 102 | }; |
| 103 | |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 104 | /* operations available on a stream-interface */ |
| 105 | struct si_ops { |
Willy Tarreau | 060781f | 2012-05-07 16:50:03 +0200 | [diff] [blame] | 106 | void (*update)(struct stream_interface *); /* I/O update function */ |
Willy Tarreau | 060781f | 2012-05-07 16:50:03 +0200 | [diff] [blame] | 107 | void (*chk_rcv)(struct stream_interface *); /* chk_rcv function */ |
| 108 | void (*chk_snd)(struct stream_interface *); /* chk_snd function */ |
Willy Tarreau | 6fe1541 | 2013-09-29 15:16:03 +0200 | [diff] [blame] | 109 | void (*shutr)(struct stream_interface *); /* shut read function */ |
| 110 | void (*shutw)(struct stream_interface *); /* shut write function */ |
Willy Tarreau | 060781f | 2012-05-07 16:50:03 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 113 | #endif /* _TYPES_STREAM_INTERFACE_H */ |
| 114 | |
| 115 | /* |
| 116 | * Local variables: |
| 117 | * c-indent-level: 8 |
| 118 | * c-basic-offset: 8 |
| 119 | * End: |
| 120 | */ |