2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 33 Client-side Routines */
11 #ifndef SQUID_SERVERS_SERVER_H
12 #define SQUID_SERVERS_SERVER_H
14 #include "anyp/forward.h"
15 #include "anyp/ProtocolVersion.h"
16 #include "base/AsyncJob.h"
18 #include "comm/Write.h"
19 #include "CommCalls.h"
20 #include "log/forward.h"
22 #include "sbuf/SBuf.h"
23 #include "servers/forward.h"
26 * Common base for all Server classes used
27 * to manage connections from clients.
29 class Server
: virtual public AsyncJob
, public BodyProducer
32 Server(const MasterXactionPointer
&xact
);
37 virtual bool doneAll() const;
38 virtual void swanSong();
40 /// whether to stop serving our client after reading EOF on its connection
41 virtual bool shouldCloseOnEof() const = 0;
43 /// maybe grow the inBuf and schedule Comm::Read()
47 * called when new request data has been read from the socket
49 * \retval false called comm_close or setReplyToError (the caller should bail)
50 * \retval true we did not call comm_close or setReplyToError
52 virtual bool handleReadData() = 0;
54 /// processing to be done after a Comm::Read()
55 virtual void afterClientRead() = 0;
57 /// whether Comm::Read() is scheduled
58 bool reading() const {return reader
!= NULL
;}
60 /// cancels Comm::Read() if it is scheduled
63 /// Update flags and timeout after the first byte received
64 virtual void receivedFirstByte() = 0;
66 /// maybe find some data to send and schedule a Comm::Write()
67 virtual void writeSomeData() {}
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
);
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);
83 /// processing to sync state after a Comm::Write()
84 virtual void afterClientWrite(size_t) {}
86 /// whether Comm::Write() is scheduled
87 bool writing() const {return writer
!= NULL
;}
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.
94 /// grows the available read buffer space (if possible)
95 void maybeMakeSpaceAvailable();
97 // Client TCP connection details from comm layer.
98 Comm::ConnectionPointer clientConnection
;
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.
105 AnyP::ProtocolVersion transferProtocol
;
107 /// Squid listening port details where this connection arrived.
108 AnyP::PortCfgPointer port
;
110 /// read I/O buffer for the client connection
113 bool receivedFirstByte_
; ///< true if at least one byte received on this connection
115 /// set of requests waiting to be serviced
119 /// abort any pending transactions and prevent new ones (by closing)
120 virtual void terminateAll(const Error
&, const LogTagsErrors
&) = 0;
122 void doClientRead(const CommIoCbParams
&io
);
123 void clientWriteDone(const CommIoCbParams
&io
);
125 AsyncCall::Pointer reader
; ///< set when we are reading
126 AsyncCall::Pointer writer
; ///< set when we are writing
129 #endif /* SQUID_SERVERS_SERVER_H */