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