VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gbufferedserverpeer.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
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 // gbufferedserverpeer.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gnet.h"
23 #include "gbufferedserverpeer.h"
24 #include "gstr.h"
25 #include "glog.h"
26 
28  ServerPeer(peer_info)
29 {
30 }
31 
32 GNet::BufferedServerPeer::BufferedServerPeer( Server::PeerInfo peer_info , const std::string & eol ) :
33  ServerPeer(peer_info) ,
34  m_line_buffer(eol)
35 {
36 }
37 
39 {
40 }
41 
42 void GNet::BufferedServerPeer::onData( const char * p , ServerPeer::size_type n )
43 {
44  m_line_buffer.add( p , n ) ;
45 
46  LineBufferIterator iter( m_line_buffer ) ;
47  while( iter.more() && onReceive(iter.line()) )
48  ;
49 }
50 
52 {
53  m_line_buffer.expect( n ) ;
54 }
55 
56 const std::string & GNet::BufferedServerPeer::eol() const
57 {
58  return m_line_buffer.eol() ;
59 }
60 
61 /// \file gbufferedserverpeer.cpp
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:173
BufferedServerPeer(Server::PeerInfo)
Constructor with an auto-detected line ending.
An iterator class for GNet::LineBuffer that extracts complete lines.
Definition: glinebuffer.h:102
virtual void onData(const char *, ServerPeer::size_type)
Override from GNet::SocketProtocolSink.
void expect(size_t n)
Temporarily suspends line buffering so that the next 'n' bytes are accumulated without regard to line...
const std::string & line() const
Returns the current line.
virtual ~BufferedServerPeer()
Destructor.
const std::string & eol() const
Returns the line-buffer's line ending.
A structure used in GNet::Server::newPeer().
Definition: gserver.h:86
bool more()
Returns true if there is a line() to be had.