E-MailRelay
gbufferedserverpeer.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gbufferedserverpeer.h
19 ///
20 
21 #ifndef G_NET_BUFFERED_SERVER_PEER__H
22 #define G_NET_BUFFERED_SERVER_PEER__H
23 
24 #include "gdef.h"
25 #include "gserver.h"
26 #include "gsocketprotocol.h"
27 #include "glinebuffer.h"
28 #include "gexception.h"
29 #include <string>
30 
31 namespace GNet
32 {
33  class BufferedServerPeer ;
34 }
35 
36 /// \class GNet::BufferedServerPeer
37 /// A ServerPeer that does line-buffering on input.
38 ///
40 {
41 public:
43  ///< Constructor.
44 
45  virtual ~BufferedServerPeer() ;
46  ///< Destructor.
47 
48  std::string lineBufferEndOfLine() const ;
49  ///< Returns the line buffer end-of-line string. Returns
50  ///< the empty string if auto-detecting and not yet
51  ///< auto-detected.
52 
53  void expect( size_t n ) ;
54  ///< Temporarily suspends line buffering so that the next 'n' bytes
55  ///< are accumulated without regard to line terminators.
56 
57 protected:
58  virtual bool onReceive( const char * line_data , size_t line_size , size_t eolsize ) = 0 ;
59  ///< Called when a complete line is received from the peer. Returns
60  ///< false if no more lines should be delivered.
61 
62  virtual void onData( const char * , ServerPeer::size_type ) override ;
63  ///< Override from GNet::SocketProtocolSink.
64 
65 private:
67  void operator=( const BufferedServerPeer & ) ;
68 
69 private:
70  LineBuffer m_line_buffer ;
71  size_t m_expect ;
72  std::string m_expect_data ;
73 } ;
74 
75 #endif
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:173
Network classes.
Definition: gaddress.h:29
std::string lineBufferEndOfLine() const
Returns the line buffer end-of-line string.
BufferedServerPeer(Server::PeerInfo, LineBufferConfig)
Constructor.
virtual bool onReceive(const char *line_data, size_t line_size, size_t eolsize)=0
Called when a complete line is received from the peer.
A configuration structure for GNet::LineBuffer.
Definition: glinebuffer.h:174
void expect(size_t n)
Temporarily suspends line buffering so that the next 'n' bytes are accumulated without regard to line...
virtual void onData(const char *, ServerPeer::size_type) override
Override from GNet::SocketProtocolSink.
virtual ~BufferedServerPeer()
Destructor.
A class that does line buffering, supporting auto-detection of line endings and fixed-size extraction...
Definition: glinebuffer.h:53
A ServerPeer that does line-buffering on input.
A structure used in GNet::Server::newPeer().
Definition: gserver.h:85