blob: 111ffc740c67a68ce30efa4fa9d3e2ea6a72ec50 [file] [log] [blame]
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001/*
2 include/types/stream_interface.h
3 This file describes the stream_interface struct and associated constants.
4
5 Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
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*/
21
22#ifndef _TYPES_STREAM_INTERFACE_H
23#define _TYPES_STREAM_INTERFACE_H
24
25#include <stdlib.h>
26
Willy Tarreau48adac52008-08-30 04:58:38 +020027#include <types/buffers.h>
Willy Tarreaufa7e1022008-10-19 07:30:41 +020028#include <common/config.h>
29
30/* A stream interface must have its own errors independantly of the buffer's,
31 * so that applications can rely on what the buffer reports while the stream
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010032 * interface is performing some retries (eg: connection error). Some states are
33 * transient and do not last beyond process_session().
Willy Tarreaufa7e1022008-10-19 07:30:41 +020034 */
35enum {
Willy Tarreauefb453c2008-10-26 20:49:47 +010036 SI_ST_INI = 0, /* interface not sollicitated yet */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010037 SI_ST_REQ, /* [transient] connection initiation desired and not started yet */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020038 SI_ST_QUE, /* interface waiting in queue */
39 SI_ST_TAR, /* interface in turn-around state after failed connect attempt */
40 SI_ST_ASS, /* server just assigned to this interface */
41 SI_ST_CON, /* initiated connection request (resource exists) */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010042 SI_ST_CER, /* [transient] previous connection attempt failed (resource released) */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020043 SI_ST_EST, /* connection established (resource exists) */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010044 SI_ST_DIS, /* [transient] disconnected from other side, but cleanup not done yet */
Willy Tarreaucff64112008-11-03 06:26:53 +010045 SI_ST_CLO, /* stream intf closed, might not existing anymore. Buffers shut. */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020046};
47
48/* error types reported on the streams interface for more accurate reporting */
49enum {
Willy Tarreaue5ed4062008-08-30 03:17:31 +020050 SI_ET_NONE = 0x0000, /* no error yet, leave it to zero */
51 SI_ET_QUEUE_TO = 0x0001, /* queue timeout */
52 SI_ET_QUEUE_ERR = 0x0002, /* queue error (eg: full) */
53 SI_ET_QUEUE_ABRT = 0x0004, /* aborted in queue by external cause */
54 SI_ET_CONN_TO = 0x0008, /* connection timeout */
55 SI_ET_CONN_ERR = 0x0010, /* connection error (eg: no server available) */
56 SI_ET_CONN_ABRT = 0x0020, /* connection aborted by external cause (eg: abort) */
57 SI_ET_CONN_OTHER = 0x0040, /* connection aborted for other reason (eg: 500) */
58 SI_ET_DATA_TO = 0x0080, /* timeout during data phase */
59 SI_ET_DATA_ERR = 0x0100, /* error during data phase */
60 SI_ET_DATA_ABRT = 0x0200, /* data phase aborted by external cause */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020061};
62
Willy Tarreaud7704b52008-09-04 11:51:16 +020063/* flags set after I/O */
64enum {
65 SI_FL_NONE = 0x0000, /* nothing */
66 SI_FL_EXP = 0x0001, /* timeout has expired */
Willy Tarreaucff64112008-11-03 06:26:53 +010067 SI_FL_ERR = 0x0002, /* a non-recoverable error has occurred */
Willy Tarreaud7704b52008-09-04 11:51:16 +020068};
69
Willy Tarreaufa7e1022008-10-19 07:30:41 +020070struct stream_interface {
71 unsigned int state; /* SI_ST* */
Willy Tarreaue5ed4062008-08-30 03:17:31 +020072 unsigned int prev_state;/* SI_ST*, copy of previous state */
73 void *owner; /* generally a (struct task*) */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020074 int fd; /* file descriptor for a stream driver when known */
Willy Tarreaud7704b52008-09-04 11:51:16 +020075 unsigned int flags; /* SI_FL_*, must be cleared before I/O */
Willy Tarreau35374672008-09-03 18:11:02 +020076 unsigned int exp; /* wake up time for connect, queue, turn-around, ... */
Willy Tarreau3c6ab2e2008-09-04 11:19:41 +020077 int (*shutr)(struct stream_interface *); /* shutr function */
Willy Tarreau48adac52008-08-30 04:58:38 +020078 int (*shutw)(struct stream_interface *); /* shutw function */
79 struct buffer *ib, *ob; /* input and output buffers */
Willy Tarreaue5ed4062008-08-30 03:17:31 +020080 unsigned int err_type; /* first error detected, one of SI_ET_* */
81 void *err_loc; /* commonly the server, NULL when SI_ET_NONE */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020082};
83
84
85#endif /* _TYPES_STREAM_INTERFACE_H */
86
87/*
88 * Local variables:
89 * c-indent-level: 8
90 * c-basic-offset: 8
91 * End:
92 */