gsocketprotocol.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 // ===
20 
21 #ifndef G_SOCKET_PROTOCOL_H
22 #define G_SOCKET_PROTOCOL_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gsocket.h"
27 #include "gexception.h"
28 #include <string>
29 
31 namespace GNet
32 {
33  class SocketProtocol ;
34  class SocketProtocolImp ;
35  class SocketProtocolSink ;
36 }
37 
55 {
56 public:
58  G_EXCEPTION_CLASS( ReadError , "read error: disconnected" ) ;
59  G_EXCEPTION( SendError , "peer disconnected" ) ;
60  G_EXCEPTION( SecureConnectionTimeout , "secure connection timeout" ) ;
61 
62  SocketProtocol( EventHandler & , Sink & , StreamSocket & , unsigned int secure_connection_timeout ) ;
64 
65  ~SocketProtocol() ;
67 
68  void readEvent() ;
72 
73  bool writeEvent() ;
78 
79  bool send( const std::string & data , std::string::size_type offset = 0U ) ;
83 
84  static bool sslCapable() ;
86 
87  void sslConnect() ;
89 
90  void sslAccept() ;
92 
93  bool sslEnabled() const ;
95 
96  std::string peerCertificate() const ;
99 
100 private:
101  SocketProtocol( const SocketProtocol & ) ;
102  void operator=( const SocketProtocol & ) ;
103 
104 private:
105  SocketProtocolImp * m_imp ;
106 } ;
107 
113 {
114 public:
115  virtual ~SocketProtocolSink() ;
117 
118 protected:
119  friend class SocketProtocolImp ;
120 
121  virtual void onData( const char * , std::string::size_type ) = 0 ;
123 
124  virtual void onSecure( const std::string & peer_certificate ) = 0 ;
127 } ;
128 
129 #endif
void readEvent()
Called on receipt of a read event.
Network classes.
std::string::size_type size_type
A std::size_t type.
Definition: md5.h:43
virtual ~SocketProtocolSink()
Destructor.
virtual void onSecure(const std::string &peer_certificate)=0
Called once the secure socket protocol has been successfully negotiated.
void sslAccept()
Accepts the TLS/SSL protocol.
A private implementation class used by GNet::SocketProtocol.
virtual void onData(const char *, std::string::size_type)=0
Called when data is read from the socket.
std::string peerCertificate() const
Returns the peer's TLS/SSL certificate or the empty string.
A derivation of Socket for a stream socket.
Definition: gsocket.h:270
~SocketProtocol()
Destructor.
SocketProtocolSink Sink
SocketProtocol(EventHandler &, Sink &, StreamSocket &, unsigned int secure_connection_timeout)
Constructor. The references are kept.
A base class for classes that handle asynchronous socket events.
Definition: geventhandler.h:54
bool send(const std::string &data, std::string::size_type offset=0U)
Sends data.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
static bool sslCapable()
Returns true if the implementation supports TLS/SSL.
void sslConnect()
Initiates the TLS/SSL protocol.
An interface used by GNet::SocketProtocol to deliver data from a socket.
An interface for implementing a low-level protocol layer by means of calling read() and write() on a ...
bool sslEnabled() const
Returns true if TLS/SSL is active.
bool writeEvent()
Called on receipt of a write event.
#define G_EXCEPTION_CLASS(class_name, description)
Definition: gexception.h:87