64 define_event(FailedToAcceptPacketStream, failed_to_accept_packet_stream, const boost::system::error_code&)
76 handler_proxy(self_type& aParent) : iParentDestroyed{ aParent }, iParent{ aParent }
80 void operator()(
const boost::system::error_code& aError)
84 iParent.handle_accept(aError);
100 iHandlerProxy(new handler_proxy(*this)),
101 iLocalPort(aLocalPort),
104 iLocalEndpoint(iProtocolFamily, iLocalPort),
105 iAcceptor(aIoTask.io_service().native_object<boost::asio::io_service>(), iLocalEndpoint)
111 iHandlerProxy(new handler_proxy(*this)),
112 iLocalHostName(aLocalHostName),
113 iLocalPort(aLocalPort),
116 iLocalEndpoint(resolve(aIoTask, iLocalHostName, iLocalPort, iProtocolFamily)),
117 iAcceptor(aIoTask.io_service().native_object<boost::asio::io_service>(), iLocalEndpoint)
124 for (
typename stream_list::iterator i = iStreamList.begin(); i != iStreamList.end(); ++i)
138 for (
typename stream_list::iterator i = iStreamList.begin(); i != iStreamList.end(); ++i)
139 if (&**i == &aStream)
141 packet_stream_pointer found{ std::move(*i) };
142 iStreamList.erase(i);
143 return std::move(found);
154 boost::system::error_code ec;
155 typename resolver_type::iterator result = resolver.resolve(resolver_type::query(aHostname, std::to_string(aPort), ec));
158 for (
typename resolver_type::iterator i = result; i != resolver_type::iterator(); ++i)
161 if (endpoint.protocol() == aProtocolFamily)
166 throw failed_to_resolve_local_host();
168 void accept_connection()
170 if (iAcceptingStream !=
nullptr)
172 iAcceptingStream = std::make_unique<packet_stream_type>(iIoTask, iSecure, iLocalEndpoint.protocol() == protocol_type::v4() ?
IPv4 :
IPv6);
173 auto acceptingStream = &*iAcceptingStream;
174 iSink += iAcceptingStream->connection_closed([
this, acceptingStream]()
178 for (
typename stream_list::iterator i = iStreamList.begin(); i != iStreamList.end(); ++i)
179 if (&**i == acceptingStream)
181 packet_stream_pointer keepObjectAlive{ std::move(*i) };
182 iStreamList.erase(i);
183 PacketStreamRemoved.trigger(*acceptingStream);
188 PacketStreamRemoved.trigger(*acceptingStream);
191 iAcceptingStream->connection().open(
true);
192 iAcceptor.async_accept(iAcceptingStream->connection().socket(), boost::bind(&handler_proxy::operator(), iHandlerProxy, boost::asio::placeholders::error));
194 void handle_accept(
const boost::system::error_code& aError)
198 iAcceptingStream->connection().server_accept();
199 iStreamList.push_back(std::move(iAcceptingStream));
200 PacketStreamAdded.trigger(*iStreamList.back());
204 FailedToAcceptPacketStream.trigger(aError);
209 i_async_task& iIoTask;
210 std::shared_ptr<handler_proxy> iHandlerProxy;
211 std::string iLocalHostName;
212 unsigned short iLocalPort;
217 packet_stream_pointer iAcceptingStream;