19 #ifndef STREAMSOCKET_H_ 20 #define STREAMSOCKET_H_ 22 #include <Atlas/Objects/ObjectsFwd.h> 23 #include <Atlas/Negotiate.h> 25 #include <boost/asio.hpp> 26 #include <boost/asio/steady_timer.hpp> 27 #include <boost/noncopyable.hpp> 54 class StreamSocket:
public std::enable_shared_from_this<StreamSocket>,
private boost::noncopyable
90 const std::string& client_name,
91 Atlas::Bridge& bridge,
107 Atlas::Codec& getCodec();
114 Atlas::Objects::ObjectsEncoder& getEncoder();
119 virtual void write() = 0;
123 read_buffer_size = 2048
125 boost::asio::io_service& m_io_service;
126 Atlas::Bridge& _bridge;
166 std::unique_ptr<Atlas::Net::StreamConnect>
_sc;
167 boost::asio::steady_timer _negotiateTimer;
168 boost::asio::steady_timer _connectTimer;
169 std::unique_ptr<Atlas::Codec> m_codec;
170 std::unique_ptr<Atlas::Objects::ObjectsEncoder> m_encoder;
173 virtual void do_read() = 0;
174 virtual void negotiate_read() = 0;
175 void startNegotiation();
176 Atlas::Negotiate::State negotiate();
183 template<
typename ProtocolT>
188 const std::string& client_name, Atlas::Bridge& bridge,
191 void connect(
const typename ProtocolT::endpoint& endpoint);
192 void write()
override;
193 typename ProtocolT::socket& getAsioSocket();
195 typename ProtocolT::socket m_socket;
196 void negotiate_read()
override;
197 void negotiate_write();
198 void do_read()
override;
204 template<
typename ProtocolT>
209 const std::string& client_name, Atlas::Bridge& bridge,
211 void connectWithQuery(
const typename ProtocolT::resolver::query& query);
213 typename ProtocolT::resolver m_resolver;
boost::asio::streambuf mReadBuffer
std::unique_ptr< boost::asio::streambuf > mSendBuffer
connection fully established
Handles the internal socket instance, interacting with the asynchronous io_service calls...
stream / socket connection in progress
std::unique_ptr< Atlas::Net::StreamConnect > _sc
negotiation object (nullptr after connection!)
failure when trying to establish a connection
Methods that are used as callbacks.
Template specialization which uses boost::asio sockets.
std::unique_ptr< boost::asio::streambuf > mWriteBuffer
Template specialization which uses boost::asio sockets with resolvers (i.e. TCP and UDP...
std::function< void(Status)> stateChanged
Called when the internal state has changed.
std::function< void()> dispatch
Called when operations have arrived and needs dispatching.
timeout when trying to establish a connection
Atlas negotiation in progress.