- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
54 class GNet::SocketProtocol
55 {
56 public:
57 typedef SocketProtocolSink Sink ;
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
112 class GNet::SocketProtocolSink
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
GNet::SocketProtocol::readEvent
void readEvent()
Called on receipt of a read event.
Definition: gsocketprotocol.cpp:528
GNet
Network classes.
md5::size_type
std::string::size_type size_type
A std::size_t type.
Definition: md5.h:43
GNet::SocketProtocolSink::~SocketProtocolSink
virtual ~SocketProtocolSink()
Destructor.
Definition: gsocketprotocol.cpp:570
GNet::SocketProtocolSink::onSecure
virtual void onSecure(const std::string &peer_certificate)=0
Called once the secure socket protocol has been successfully negotiated.
GNet::SocketProtocol::sslAccept
void sslAccept()
Accepts the TLS/SSL protocol.
Definition: gsocketprotocol.cpp:553
GNet::SocketProtocolImp
A private implementation class used by GNet::SocketProtocol.
Definition: gsocketprotocol.cpp:41
GNet::SocketProtocolSink::onData
virtual void onData(const char *, std::string::size_type)=0
Called when data is read from the socket.
GNet::SocketProtocol::peerCertificate
std::string peerCertificate() const
Returns the peer's TLS/SSL certificate or the empty string.
Definition: gsocketprotocol.cpp:563
GNet::StreamSocket
A derivation of Socket for a stream socket.
Definition: gsocket.h:270
GNet::SocketProtocol::~SocketProtocol
~SocketProtocol()
Destructor.
Definition: gsocketprotocol.cpp:523
GNet::SocketProtocol::Sink
SocketProtocolSink Sink
Definition: gsocketprotocol.h:57
GNet::SocketProtocol::SocketProtocol
SocketProtocol(EventHandler &, Sink &, StreamSocket &, unsigned int secure_connection_timeout)
Constructor. The references are kept.
Definition: gsocketprotocol.cpp:517
GNet::EventHandler
A base class for classes that handle asynchronous socket events.
Definition: geventhandler.h:54
gsocket.h
GNet::SocketProtocol::send
bool send(const std::string &data, std::string::size_type offset=0U)
Sends data.
Definition: gsocketprotocol.cpp:538
gexception.h
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
GNet::SocketProtocol::sslCapable
static bool sslCapable()
Returns true if the implementation supports TLS/SSL.
Definition: gsocketprotocol.cpp:543
GNet::SocketProtocol::sslConnect
void sslConnect()
Initiates the TLS/SSL protocol.
Definition: gsocketprotocol.cpp:548
GNet::SocketProtocolSink
An interface used by GNet::SocketProtocol to deliver data from a socket.
Definition: gsocketprotocol.h:112
GNet::SocketProtocol
An interface for implementing a low-level protocol layer by means of calling read() and write() on a ...
Definition: gsocketprotocol.h:54
GNet::SocketProtocol::sslEnabled
bool sslEnabled() const
Returns true if TLS/SSL is active.
Definition: gsocketprotocol.cpp:558
GNet::SocketProtocol::writeEvent
bool writeEvent()
Called on receipt of a write event.
Definition: gsocketprotocol.cpp:533
G_EXCEPTION_CLASS
#define G_EXCEPTION_CLASS(class_name, description)
Definition: gexception.h:87