blob: 6af0f63d672bb4936343c1b256c94f3612fbdb29 [file] [log] [blame]
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001/*
Willy Tarreau4c283dc2009-12-29 14:36:34 +01002 * include/types/stream_interface.h
3 * This file describes the stream_interface struct and associated constants.
4 *
Willy Tarreaub24281b2011-02-13 13:16:36 +01005 * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
Willy Tarreau4c283dc2009-12-29 14:36:34 +01006 *
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 Tarreaufa7e1022008-10-19 07:30:41 +020021
22#ifndef _TYPES_STREAM_INTERFACE_H
23#define _TYPES_STREAM_INTERFACE_H
24
25#include <stdlib.h>
Emeric Brun129c5902010-01-04 14:47:58 +010026#include <sys/socket.h>
Willy Tarreaufa7e1022008-10-19 07:30:41 +020027
Willy Tarreau48adac52008-08-30 04:58:38 +020028#include <types/buffers.h>
Willy Tarreaufa7e1022008-10-19 07:30:41 +020029#include <common/config.h>
30
31/* A stream interface must have its own errors independantly of the buffer's,
32 * so that applications can rely on what the buffer reports while the stream
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010033 * interface is performing some retries (eg: connection error). Some states are
34 * transient and do not last beyond process_session().
Willy Tarreaufa7e1022008-10-19 07:30:41 +020035 */
36enum {
Willy Tarreauefb453c2008-10-26 20:49:47 +010037 SI_ST_INI = 0, /* interface not sollicitated yet */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010038 SI_ST_REQ, /* [transient] connection initiation desired and not started yet */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020039 SI_ST_QUE, /* interface waiting in queue */
40 SI_ST_TAR, /* interface in turn-around state after failed connect attempt */
41 SI_ST_ASS, /* server just assigned to this interface */
42 SI_ST_CON, /* initiated connection request (resource exists) */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010043 SI_ST_CER, /* [transient] previous connection attempt failed (resource released) */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020044 SI_ST_EST, /* connection established (resource exists) */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010045 SI_ST_DIS, /* [transient] disconnected from other side, but cleanup not done yet */
Willy Tarreaucff64112008-11-03 06:26:53 +010046 SI_ST_CLO, /* stream intf closed, might not existing anymore. Buffers shut. */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020047};
48
49/* error types reported on the streams interface for more accurate reporting */
50enum {
Willy Tarreaue5ed4062008-08-30 03:17:31 +020051 SI_ET_NONE = 0x0000, /* no error yet, leave it to zero */
52 SI_ET_QUEUE_TO = 0x0001, /* queue timeout */
53 SI_ET_QUEUE_ERR = 0x0002, /* queue error (eg: full) */
54 SI_ET_QUEUE_ABRT = 0x0004, /* aborted in queue by external cause */
55 SI_ET_CONN_TO = 0x0008, /* connection timeout */
56 SI_ET_CONN_ERR = 0x0010, /* connection error (eg: no server available) */
57 SI_ET_CONN_ABRT = 0x0020, /* connection aborted by external cause (eg: abort) */
58 SI_ET_CONN_OTHER = 0x0040, /* connection aborted for other reason (eg: 500) */
59 SI_ET_DATA_TO = 0x0080, /* timeout during data phase */
60 SI_ET_DATA_ERR = 0x0100, /* error during data phase */
61 SI_ET_DATA_ABRT = 0x0200, /* data phase aborted by external cause */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020062};
63
Willy Tarreaud7704b52008-09-04 11:51:16 +020064/* flags set after I/O */
65enum {
66 SI_FL_NONE = 0x0000, /* nothing */
67 SI_FL_EXP = 0x0001, /* timeout has expired */
Willy Tarreaucff64112008-11-03 06:26:53 +010068 SI_FL_ERR = 0x0002, /* a non-recoverable error has occurred */
Willy Tarreaub0ef7352008-12-14 13:26:20 +010069 SI_FL_WAIT_ROOM = 0x0004, /* waiting for space to store incoming data */
70 SI_FL_WAIT_DATA = 0x0008, /* waiting for more data to send */
Willy Tarreaudc340a92009-06-28 23:10:19 +020071 SI_FL_CAP_SPLTCP = 0x0010, /* splicing possible from/to TCP */
Willy Tarreau89f7ef22009-09-05 20:57:35 +020072 SI_FL_DONT_WAKE = 0x0020, /* resync in progress, don't wake up */
Willy Tarreauf27b5ea2009-10-03 22:01:18 +020073 SI_FL_INDEP_STR = 0x0040, /* independant streams = don't update rex on write */
Willy Tarreau4c283dc2009-12-29 14:36:34 +010074 SI_FL_NOLINGER = 0x0080, /* may close without lingering. One-shot. */
Willy Tarreaud7704b52008-09-04 11:51:16 +020075};
76
Willy Tarreaudc340a92009-06-28 23:10:19 +020077#define SI_FL_CAP_SPLICE (SI_FL_CAP_SPLTCP)
78
Willy Tarreau9650f372009-08-16 14:02:45 +020079struct server;
80struct proxy;
Willy Tarreaub24281b2011-02-13 13:16:36 +010081struct si_applet;
Willy Tarreau9650f372009-08-16 14:02:45 +020082
Willy Tarreaub24281b2011-02-13 13:16:36 +010083/* Note that if an applet is registered, the update function will not be called
84 * by the session handler, so it may be used to resync flags at the end of the
85 * applet handler. See stream_int_update_embedded() for reference.
Willy Tarreaufb90d942009-09-05 20:57:35 +020086 */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020087struct stream_interface {
88 unsigned int state; /* SI_ST* */
Willy Tarreaue5ed4062008-08-30 03:17:31 +020089 unsigned int prev_state;/* SI_ST*, copy of previous state */
90 void *owner; /* generally a (struct task*) */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020091 int fd; /* file descriptor for a stream driver when known */
Willy Tarreaudc340a92009-06-28 23:10:19 +020092 unsigned int flags;
Willy Tarreau35374672008-09-03 18:11:02 +020093 unsigned int exp; /* wake up time for connect, queue, turn-around, ... */
Willy Tarreaub029f8c2009-09-05 20:57:35 +020094 void (*update)(struct stream_interface *); /* I/O update function */
Willy Tarreau0a5d5dd2008-11-23 19:31:35 +010095 void (*shutr)(struct stream_interface *); /* shutr function */
96 void (*shutw)(struct stream_interface *); /* shutw function */
Willy Tarreau3ffeba12008-12-14 14:42:35 +010097 void (*chk_rcv)(struct stream_interface *);/* chk_rcv function */
98 void (*chk_snd)(struct stream_interface *);/* chk_snd function */
Willy Tarreaudc85b392009-08-18 07:38:19 +020099 int (*connect)(struct stream_interface *, struct proxy *, struct server *,
100 struct sockaddr *, struct sockaddr *); /* connect function if any */
Willy Tarreau0bd05ea2010-07-02 11:18:03 +0200101 void (*release)(struct stream_interface *); /* handler to call after the last close() */
Willy Tarreau48adac52008-08-30 04:58:38 +0200102 struct buffer *ib, *ob; /* input and output buffers */
Willy Tarreauee28de02010-06-01 09:51:00 +0200103 int conn_retries; /* number of connect retries left */
Willy Tarreaue5ed4062008-08-30 03:17:31 +0200104 unsigned int err_type; /* first error detected, one of SI_ET_* */
105 void *err_loc; /* commonly the server, NULL when SI_ET_NONE */
Willy Tarreaub24281b2011-02-13 13:16:36 +0100106 struct {
107 struct si_applet *handler; /* applet to use instead of doing I/O */
108 } applet;
Willy Tarreaueecc8ee2009-09-20 21:43:50 +0200109 void *private; /* may be used by any function above */
110 unsigned int st0, st1; /* may be used by any function above */
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200111};
112
Willy Tarreaub24281b2011-02-13 13:16:36 +0100113/* An applet designed to run in a stream interface */
114struct si_applet {
115 char *name; /* applet's name to report in logs */
116 void (*fct)(struct stream_interface *); /* internal I/O handler, may never be NULL */
117};
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200118
119#endif /* _TYPES_STREAM_INTERFACE_H */
120
121/*
122 * Local variables:
123 * c-indent-level: 8
124 * c-basic-offset: 8
125 * End:
126 */