1 #include "stg/sgcp_proto.h"
3 #include "stg/sgcp_transport.h"
8 using STG::SGCP::Proto;
10 Proto::Proto(TransportType transport, const std::string& key)
11 : m_impl(new Impl(transport, key))
19 ConnectionPtr Proto::connect(const std::string& address, uint16_t port)
21 m_impl->connect(adress, port);
24 void Proto::bind(const std::string& address, uint16_t port, AcceptHandler handler)
26 m_impl->bind(address, port, handler);
36 return m_impl->stop();
42 Impl(TransportType transport, const std::string& key);
45 Connection& connect(const std::string& address, uint16_t port);
46 void bind(const std::string& address, uint16_t port, AcceptHandler handler);
53 boost::scoped_ptr<Transport> m_transport;
54 std::vector<ConnectionPtr> m_conns;
59 Proto::Impl::Impl(TransportType transport, const std::string& key)
60 : m_transport(makeTransport(transport, key)),
71 ConnectionPtr Proto::Impl::connect(const std::string& address, uint16_t port)
73 return m_transport->connect(address, port);
76 void Proto::Impl::bind(const std::string& address, uint16_t port, AcceptHandler handler)
78 m_transport->bind(address, port, handler);
81 void Proto::Impl::run()
90 bool Proto::Impl::stop()
92 for (size_t i = 0; i < m_conns.size(); ++i)
95 for (size_t i = 0; i < 10 && !m_ios.stopped(); ++i) {
98 ts.tv_nsec = 10000000; // 10 msec
100 return m_ios.stopped();