]>
Commit | Line | Data |
---|---|---|
fcc444e3 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 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" |
5ceaee75 | 20 | #include "forward.h" |
c6ae1627 | 21 | #include "Pipeline.h" |
65e41a45 | 22 | #include "sbuf/SBuf.h" |
fcc444e3 AJ |
23 | |
24 | /** | |
25 | * Common base for all Server classes used | |
26 | * to manage connections from clients. | |
27 | */ | |
28 | class Server : virtual public AsyncJob, public BodyProducer | |
29 | { | |
30 | public: | |
5ceaee75 | 31 | Server(const MasterXactionPointer &xact); |
fcc444e3 AJ |
32 | virtual ~Server() {} |
33 | ||
34 | /* AsyncJob API */ | |
35 | virtual void start(); | |
36 | virtual bool doneAll() const; | |
37 | virtual void swanSong(); | |
38 | ||
fcc444e3 AJ |
39 | /// ?? |
40 | virtual bool connFinishedWithConn(int size) = 0; | |
41 | ||
fcc444e3 AJ |
42 | /// maybe grow the inBuf and schedule Comm::Read() |
43 | void readSomeData(); | |
44 | ||
45 | /** | |
46 | * called when new request data has been read from the socket | |
47 | * | |
48 | * \retval false called comm_close or setReplyToError (the caller should bail) | |
49 | * \retval true we did not call comm_close or setReplyToError | |
50 | */ | |
51 | virtual bool handleReadData() = 0; | |
52 | ||
21cd3227 AJ |
53 | /// processing to be done after a Comm::Read() |
54 | virtual void afterClientRead() = 0; | |
55 | ||
fcc444e3 AJ |
56 | /// whether Comm::Read() is scheduled |
57 | bool reading() const {return reader != NULL;} | |
58 | ||
59 | /// cancels Comm::Read() if it is scheduled | |
60 | void stopReading(); | |
61 | ||
62 | /// Update flags and timeout after the first byte received | |
63 | virtual void receivedFirstByte() = 0; | |
64 | ||
21cd3227 | 65 | /// maybe find some data to send and schedule a Comm::Write() |
fcc444e3 AJ |
66 | virtual void writeSomeData() {} |
67 | ||
21cd3227 AJ |
68 | /// schedule some data for a Comm::Write() |
69 | void write(MemBuf *mb) { | |
70 | typedef CommCbMemFunT<Server, CommIoCbParams> Dialer; | |
71 | writer = JobCallback(33, 5, Dialer, this, Server::clientWriteDone); | |
72 | Comm::Write(clientConnection, mb, writer); | |
73 | } | |
74 | ||
75 | /// schedule some data for a Comm::Write() | |
76 | void write(char *buf, int len) { | |
77 | typedef CommCbMemFunT<Server, CommIoCbParams> Dialer; | |
78 | writer = JobCallback(33, 5, Dialer, this, Server::clientWriteDone); | |
79 | Comm::Write(clientConnection, buf, len, writer, nullptr); | |
80 | } | |
81 | ||
82 | /// processing to sync state after a Comm::Write() | |
83 | virtual void afterClientWrite(size_t) {} | |
84 | ||
fcc444e3 AJ |
85 | /// whether Comm::Write() is scheduled |
86 | bool writing() const {return writer != NULL;} | |
87 | ||
88 | // XXX: should be 'protected:' for child access only, | |
89 | // but all sorts of code likes to play directly | |
90 | // with the I/O buffers and socket. | |
91 | public: | |
92 | ||
93 | /// grows the available read buffer space (if possible) | |
19e97cf0 | 94 | void maybeMakeSpaceAvailable(); |
fcc444e3 AJ |
95 | |
96 | // Client TCP connection details from comm layer. | |
97 | Comm::ConnectionPointer clientConnection; | |
98 | ||
99 | /** | |
100 | * The transfer protocol currently being spoken on this connection. | |
101 | * HTTP/1.x CONNECT, HTTP/1.1 Upgrade and HTTP/2 SETTINGS offer the | |
102 | * ability to change protocols on the fly. | |
103 | */ | |
104 | AnyP::ProtocolVersion transferProtocol; | |
105 | ||
106 | /// Squid listening port details where this connection arrived. | |
107 | AnyP::PortCfgPointer port; | |
108 | ||
109 | /// read I/O buffer for the client connection | |
110 | SBuf inBuf; | |
111 | ||
112 | bool receivedFirstByte_; ///< true if at least one byte received on this connection | |
113 | ||
c6ae1627 AJ |
114 | /// set of requests waiting to be serviced |
115 | Pipeline pipeline; | |
116 | ||
fcc444e3 AJ |
117 | protected: |
118 | void doClientRead(const CommIoCbParams &io); | |
119 | void clientWriteDone(const CommIoCbParams &io); | |
120 | ||
da6dbcd1 EB |
121 | /// Log the current [attempt at] transaction if nobody else will. |
122 | virtual void checkLogging() = 0; | |
123 | ||
fcc444e3 AJ |
124 | AsyncCall::Pointer reader; ///< set when we are reading |
125 | AsyncCall::Pointer writer; ///< set when we are writing | |
126 | }; | |
127 | ||
128 | #endif /* SQUID_SERVERS_SERVER_H */ | |
15f8f9eb | 129 |