]>
Commit | Line | Data |
---|---|---|
fcc444e3 | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 The Squid Software Foundation and contributors |
fcc444e3 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
9 | /* DEBUG: section 33 Client-side Routines */ | |
10 | ||
11 | #ifndef SQUID_SERVERS_SERVER_H | |
12 | #define SQUID_SERVERS_SERVER_H | |
13 | ||
14 | #include "anyp/forward.h" | |
15 | #include "anyp/ProtocolVersion.h" | |
16 | #include "base/AsyncJob.h" | |
17 | #include "BodyPipe.h" | |
21cd3227 | 18 | #include "comm/Write.h" |
fcc444e3 | 19 | #include "CommCalls.h" |
83b053a0 | 20 | #include "log/forward.h" |
c6ae1627 | 21 | #include "Pipeline.h" |
65e41a45 | 22 | #include "sbuf/SBuf.h" |
e16571ed | 23 | #include "servers/forward.h" |
fcc444e3 AJ |
24 | |
25 | /** | |
26 | * Common base for all Server classes used | |
27 | * to manage connections from clients. | |
28 | */ | |
29 | class Server : virtual public AsyncJob, public BodyProducer | |
30 | { | |
31 | public: | |
5ceaee75 | 32 | Server(const MasterXactionPointer &xact); |
337b9aa4 | 33 | ~Server() override {} |
fcc444e3 AJ |
34 | |
35 | /* AsyncJob API */ | |
337b9aa4 AR |
36 | void start() override; |
37 | bool doneAll() const override; | |
38 | void swanSong() override; | |
fcc444e3 | 39 | |
83b053a0 CT |
40 | /// whether to stop serving our client after reading EOF on its connection |
41 | virtual bool shouldCloseOnEof() const = 0; | |
fcc444e3 | 42 | |
fcc444e3 AJ |
43 | /// maybe grow the inBuf and schedule Comm::Read() |
44 | void readSomeData(); | |
45 | ||
46 | /** | |
47 | * called when new request data has been read from the socket | |
48 | * | |
49 | * \retval false called comm_close or setReplyToError (the caller should bail) | |
50 | * \retval true we did not call comm_close or setReplyToError | |
51 | */ | |
52 | virtual bool handleReadData() = 0; | |
53 | ||
21cd3227 AJ |
54 | /// processing to be done after a Comm::Read() |
55 | virtual void afterClientRead() = 0; | |
56 | ||
fcc444e3 | 57 | /// whether Comm::Read() is scheduled |
aee3523a | 58 | bool reading() const {return reader != nullptr;} |
fcc444e3 AJ |
59 | |
60 | /// cancels Comm::Read() if it is scheduled | |
61 | void stopReading(); | |
62 | ||
63 | /// Update flags and timeout after the first byte received | |
64 | virtual void receivedFirstByte() = 0; | |
65 | ||
21cd3227 | 66 | /// maybe find some data to send and schedule a Comm::Write() |
fcc444e3 AJ |
67 | virtual void writeSomeData() {} |
68 | ||
21cd3227 AJ |
69 | /// schedule some data for a Comm::Write() |
70 | void write(MemBuf *mb) { | |
71 | typedef CommCbMemFunT<Server, CommIoCbParams> Dialer; | |
72 | writer = JobCallback(33, 5, Dialer, this, Server::clientWriteDone); | |
73 | Comm::Write(clientConnection, mb, writer); | |
74 | } | |
75 | ||
76 | /// schedule some data for a Comm::Write() | |
77 | void write(char *buf, int len) { | |
78 | typedef CommCbMemFunT<Server, CommIoCbParams> Dialer; | |
79 | writer = JobCallback(33, 5, Dialer, this, Server::clientWriteDone); | |
80 | Comm::Write(clientConnection, buf, len, writer, nullptr); | |
81 | } | |
82 | ||
83 | /// processing to sync state after a Comm::Write() | |
84 | virtual void afterClientWrite(size_t) {} | |
85 | ||
fcc444e3 | 86 | /// whether Comm::Write() is scheduled |
aee3523a | 87 | bool writing() const {return writer != nullptr;} |
fcc444e3 AJ |
88 | |
89 | // XXX: should be 'protected:' for child access only, | |
90 | // but all sorts of code likes to play directly | |
91 | // with the I/O buffers and socket. | |
92 | public: | |
93 | ||
94 | /// grows the available read buffer space (if possible) | |
19e97cf0 | 95 | void maybeMakeSpaceAvailable(); |
fcc444e3 AJ |
96 | |
97 | // Client TCP connection details from comm layer. | |
98 | Comm::ConnectionPointer clientConnection; | |
99 | ||
100 | /** | |
101 | * The transfer protocol currently being spoken on this connection. | |
102 | * HTTP/1.x CONNECT, HTTP/1.1 Upgrade and HTTP/2 SETTINGS offer the | |
103 | * ability to change protocols on the fly. | |
104 | */ | |
105 | AnyP::ProtocolVersion transferProtocol; | |
106 | ||
107 | /// Squid listening port details where this connection arrived. | |
108 | AnyP::PortCfgPointer port; | |
109 | ||
110 | /// read I/O buffer for the client connection | |
111 | SBuf inBuf; | |
112 | ||
113 | bool receivedFirstByte_; ///< true if at least one byte received on this connection | |
114 | ||
c6ae1627 AJ |
115 | /// set of requests waiting to be serviced |
116 | Pipeline pipeline; | |
117 | ||
fcc444e3 | 118 | protected: |
83b053a0 CT |
119 | /// abort any pending transactions and prevent new ones (by closing) |
120 | virtual void terminateAll(const Error &, const LogTagsErrors &) = 0; | |
121 | ||
fcc444e3 AJ |
122 | void doClientRead(const CommIoCbParams &io); |
123 | void clientWriteDone(const CommIoCbParams &io); | |
124 | ||
125 | AsyncCall::Pointer reader; ///< set when we are reading | |
126 | AsyncCall::Pointer writer; ///< set when we are writing | |
127 | }; | |
128 | ||
129 | #endif /* SQUID_SERVERS_SERVER_H */ | |
15f8f9eb | 130 |