2 * Copyright (C) 1996-2017 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"
21 #include "sbuf/SBuf.h"
24 * Common base for all Server classes used
25 * to manage connections from clients.
27 class Server
: virtual public AsyncJob
, public BodyProducer
30 Server(const MasterXaction::Pointer
&xact
);
35 virtual bool doneAll() const;
36 virtual void swanSong();
39 virtual bool connFinishedWithConn(int size
) = 0;
41 /// maybe grow the inBuf and schedule Comm::Read()
45 * called when new request data has been read from the socket
47 * \retval false called comm_close or setReplyToError (the caller should bail)
48 * \retval true we did not call comm_close or setReplyToError
50 virtual bool handleReadData() = 0;
52 /// processing to be done after a Comm::Read()
53 virtual void afterClientRead() = 0;
55 /// whether Comm::Read() is scheduled
56 bool reading() const {return reader
!= NULL
;}
58 /// cancels Comm::Read() if it is scheduled
61 /// Update flags and timeout after the first byte received
62 virtual void receivedFirstByte() = 0;
64 /// maybe find some data to send and schedule a Comm::Write()
65 virtual void writeSomeData() {}
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
);
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);
81 /// processing to sync state after a Comm::Write()
82 virtual void afterClientWrite(size_t) {}
84 /// whether Comm::Write() is scheduled
85 bool writing() const {return writer
!= NULL
;}
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.
92 /// grows the available read buffer space (if possible)
93 void maybeMakeSpaceAvailable();
95 // Client TCP connection details from comm layer.
96 Comm::ConnectionPointer clientConnection
;
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.
103 AnyP::ProtocolVersion transferProtocol
;
105 /// Squid listening port details where this connection arrived.
106 AnyP::PortCfgPointer port
;
108 /// read I/O buffer for the client connection
111 bool receivedFirstByte_
; ///< true if at least one byte received on this connection
113 /// set of requests waiting to be serviced
117 void doClientRead(const CommIoCbParams
&io
);
118 void clientWriteDone(const CommIoCbParams
&io
);
120 /// Log the current [attempt at] transaction if nobody else will.
121 virtual void checkLogging() = 0;
123 AsyncCall::Pointer reader
; ///< set when we are reading
124 AsyncCall::Pointer writer
; ///< set when we are writing
127 #endif /* SQUID_SERVERS_SERVER_H */