Server.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_SRC_SERVERS_SERVER_H
12 #define SQUID_SRC_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 "error/forward.h"
21 #include "http/Stream.h"
22 #include "log/forward.h"
23 #include "Pipeline.h"
24 #include "sbuf/SBuf.h"
25 #include "servers/forward.h"
26 
31 class Server : virtual public AsyncJob, public BodyProducer
32 {
33 public:
34  Server(const MasterXactionPointer &xact);
35  ~Server() override {}
36 
37  /* AsyncJob API */
38  void start() override;
39  bool doneAll() const override;
40  void swanSong() override;
41 
43  virtual bool shouldCloseOnEof() const = 0;
44 
46  void readSomeData();
47 
54  virtual bool handleReadData() = 0;
55 
57  virtual void afterClientRead() = 0;
58 
60  bool reading() const {return reader != nullptr;}
61 
63  void stopReading();
64 
66  virtual void receivedFirstByte() = 0;
67 
69  virtual void writeSomeData() {}
70 
72  void write(MemBuf *mb) {
74  writer = JobCallback(33, 5, Dialer, this, Server::clientWriteDone);
76  }
77 
79  void write(char *buf, int len) {
81  writer = JobCallback(33, 5, Dialer, this, Server::clientWriteDone);
82  Comm::Write(clientConnection, buf, len, writer, nullptr);
83  }
84 
86  virtual void afterClientWrite(size_t) {}
87 
89  bool writing() const {return writer != nullptr;}
90 
91 // XXX: should be 'protected:' for child access only,
92 // but all sorts of code likes to play directly
93 // with the I/O buffers and socket.
94 public:
95 
98 
99  // Client TCP connection details from comm layer.
101 
108 
111 
114 
116 
119 
120 protected:
122  virtual void terminateAll(const Error &, const LogTagsErrors &) = 0;
123 
125  bool mayBufferMoreRequestBytes() const;
126 
127  void doClientRead(const CommIoCbParams &io);
128  void clientWriteDone(const CommIoCbParams &io);
129 
132 };
133 
134 #endif /* SQUID_SRC_SERVERS_SERVER_H */
135 
AnyP::ProtocolVersion transferProtocol
Definition: Server.h:107
bool mayBufferMoreRequestBytes() const
whether client_request_buffer_max_size allows inBuf.length() increase
Definition: Server.cc:89
virtual bool handleReadData()=0
SBuf inBuf
read I/O buffer for the client connection
Definition: Server.h:113
AsyncCall::Pointer reader
set when we are reading
Definition: Server.h:130
Definition: SBuf.h:93
virtual void receivedFirstByte()=0
Update flags and timeout after the first byte received.
virtual bool shouldCloseOnEof() const =0
whether to stop serving our client after reading EOF on its connection
Definition: Server.h:31
void write(MemBuf *mb)
schedule some data for a Comm::Write()
Definition: Server.h:72
void maybeMakeSpaceAvailable()
grows the available read buffer space (if possible)
Definition: Server.cc:74
void write(char *buf, int len)
schedule some data for a Comm::Write()
Definition: Server.h:79
virtual void terminateAll(const Error &, const LogTagsErrors &)=0
abort any pending transactions and prevent new ones (by closing)
Pipeline pipeline
set of requests waiting to be serviced
Definition: Server.h:118
virtual void afterClientWrite(size_t)
processing to sync state after a Comm::Write()
Definition: Server.h:86
a transaction problem
Definition: Error.h:27
~Server() override
Definition: Server.h:35
Definition: MemBuf.h:23
void readSomeData()
maybe grow the inBuf and schedule Comm::Read()
Definition: Server.cc:101
bool reading() const
whether Comm::Read() is scheduled
Definition: Server.h:60
#define JobCallback(dbgSection, dbgLevel, Dialer, job, method)
Convenience macro to create a Dialer-based job callback.
Definition: AsyncJobCalls.h:70
void Write(const Comm::ConnectionPointer &conn, const char *buf, int size, AsyncCall::Pointer &callback, FREE *free_func)
Definition: Write.cc:33
Comm::ConnectionPointer clientConnection
Definition: Server.h:100
bool writing() const
whether Comm::Write() is scheduled
Definition: Server.h:89
void doClientRead(const CommIoCbParams &io)
Definition: Server.cc:115
void stopReading()
cancels Comm::Read() if it is scheduled
Definition: Server.cc:60
virtual void afterClientRead()=0
processing to be done after a Comm::Read()
AnyP::PortCfgPointer port
Squid listening port details where this connection arrived.
Definition: Server.h:110
Server(const MasterXactionPointer &xact)
Definition: Server.cc:26
AsyncCall::Pointer writer
set when we are writing
Definition: Server.h:131
bool doneAll() const override
whether positive goal has been reached
Definition: Server.cc:37
void start() override
called by AsyncStart; do not call directly
Definition: Server.cc:45
bool receivedFirstByte_
true if at least one byte received on this connection
Definition: Server.h:115
void swanSong() override
Definition: Server.cc:51
void clientWriteDone(const CommIoCbParams &io)
Definition: Server.cc:211
virtual void writeSomeData()
maybe find some data to send and schedule a Comm::Write()
Definition: Server.h:69

 

Introduction

Documentation

Support

Miscellaneous