Commit | Line | Data |
---|---|---|
6650af14 BS |
1 | /** @file |
2 | * @brief TCPService class header. This class represents a TCP client. | |
3 | * | |
4 | * | |
5 | * | |
6 | * @copyright Intra2net AG | |
7 | * @license GPLv2 | |
8 | */ | |
9 | ||
10 | #ifndef TCPSERVICE_H | |
11 | #define TCPSERVICE_H | |
12 | ||
13 | #include "logger.h" | |
ca5d6889 | 14 | #include "ip_service.h" |
6650af14 BS |
15 | |
16 | #include <boost/shared_ptr.hpp> | |
17 | #include <boost/asio.hpp> | |
18 | #include <boost/asio/ssl.hpp> | |
19 | ||
20 | typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream; | |
21 | ||
22 | class TCPService : public IPService | |
23 | { | |
24 | ||
25 | private: | |
26 | ||
27 | boost::shared_ptr<SSLStream> Socket; | |
28 | // IOService has to be a member, otherwise the socket.close() operation will throw "mutex: Invalid argument" | |
29 | // Bug in boost::asio ? Cause no docs found concerning this issue. The socket.close() operation is trying to clean up io_service. | |
30 | boost::asio::io_service IOService; | |
31 | ||
32 | public: | |
33 | ||
c9d27cb6 | 34 | //typedef boost::shared_ptr<TCPService> Ptr; |
6650af14 BS |
35 | |
36 | TCPService(); | |
37 | ||
38 | ~TCPService(); | |
39 | ||
c9d27cb6 | 40 | virtual void connect(const std::string& _hostname, const std::string& _port) throw (boost::system::system_error); |
6650af14 BS |
41 | |
42 | std::string read_from_socket() throw (boost::system::system_error); | |
43 | ||
83ae2edf | 44 | void write_to_socket(const std::string& data) throw (boost::system::system_error); |
6650af14 | 45 | |
31beb90a | 46 | void close() throw (boost::system::system_error); |
6650af14 BS |
47 | }; |
48 | ||
49 | #endif |