changed variant_stream to return a pointer instead of a reference when querying for underlying type (avoids exceptions)

This commit is contained in:
Arvid Norberg 2008-10-18 07:12:04 +00:00
parent 68981fc3fd
commit 3d75732145
5 changed files with 16 additions and 13 deletions

View File

@ -542,9 +542,11 @@ public:
} }
template <class S> template <class S>
S& get() S* get()
{ {
return *boost::get<S*>(m_variant); S** ret = boost::get<S*>(&m_variant);
if (!ret) return 0;
return *ret;
} }
bool instantiated() const bool instantiated() const

View File

@ -163,15 +163,16 @@ void http_connection::start(std::string const& hostname, std::string const& port
if (m_ssl) if (m_ssl)
{ {
m_sock.instantiate<ssl_stream<socket_type> >(m_resolver.get_io_service()); m_sock.instantiate<ssl_stream<socket_type> >(m_resolver.get_io_service());
ssl_stream<socket_type>& s = m_sock.get<ssl_stream<socket_type> >(); ssl_stream<socket_type>* s = m_sock.get<ssl_stream<socket_type> >();
bool ret = instantiate_connection(m_resolver.get_io_service(), m_proxy, s.next_layer()); TORRENT_ASSERT(s);
bool ret = instantiate_connection(m_resolver.get_io_service(), m_proxy, s->next_layer());
TORRENT_ASSERT(ret); TORRENT_ASSERT(ret);
} }
else else
{ {
m_sock.instantiate<socket_type>(m_resolver.get_io_service()); m_sock.instantiate<socket_type>(m_resolver.get_io_service());
bool ret = instantiate_connection(m_resolver.get_io_service() bool ret = instantiate_connection(m_resolver.get_io_service()
, m_proxy, m_sock.get<socket_type>()); , m_proxy, *m_sock.get<socket_type>());
TORRENT_ASSERT(ret); TORRENT_ASSERT(ret);
} }
#else #else

View File

@ -52,23 +52,23 @@ namespace libtorrent
|| ps.type == proxy_settings::http_pw) || ps.type == proxy_settings::http_pw)
{ {
s.instantiate<http_stream>(ios); s.instantiate<http_stream>(ios);
s.get<http_stream>().set_proxy(ps.hostname, ps.port); s.get<http_stream>()->set_proxy(ps.hostname, ps.port);
if (ps.type == proxy_settings::http_pw) if (ps.type == proxy_settings::http_pw)
s.get<http_stream>().set_username(ps.username, ps.password); s.get<http_stream>()->set_username(ps.username, ps.password);
} }
else if (ps.type == proxy_settings::socks5 else if (ps.type == proxy_settings::socks5
|| ps.type == proxy_settings::socks5_pw) || ps.type == proxy_settings::socks5_pw)
{ {
s.instantiate<socks5_stream>(ios); s.instantiate<socks5_stream>(ios);
s.get<socks5_stream>().set_proxy(ps.hostname, ps.port); s.get<socks5_stream>()->set_proxy(ps.hostname, ps.port);
if (ps.type == proxy_settings::socks5_pw) if (ps.type == proxy_settings::socks5_pw)
s.get<socks5_stream>().set_username(ps.username, ps.password); s.get<socks5_stream>()->set_username(ps.username, ps.password);
} }
else if (ps.type == proxy_settings::socks4) else if (ps.type == proxy_settings::socks4)
{ {
s.instantiate<socks4_stream>(ios); s.instantiate<socks4_stream>(ios);
s.get<socks4_stream>().set_proxy(ps.hostname, ps.port); s.get<socks4_stream>()->set_proxy(ps.hostname, ps.port);
s.get<socks4_stream>().set_username(ps.username); s.get<socks4_stream>()->set_username(ps.username);
} }
else else
{ {

View File

@ -772,7 +772,7 @@ namespace aux {
{ {
shared_ptr<socket_type> c(new socket_type(m_io_service)); shared_ptr<socket_type> c(new socket_type(m_io_service));
c->instantiate<stream_socket>(m_io_service); c->instantiate<stream_socket>(m_io_service);
listener->async_accept(c->get<stream_socket>() listener->async_accept(*c->get<stream_socket>()
, bind(&session_impl::on_incoming_connection, this, c , bind(&session_impl::on_incoming_connection, this, c
, boost::weak_ptr<socket_acceptor>(listener), _1)); , boost::weak_ptr<socket_acceptor>(listener), _1));
} }

View File

@ -2335,7 +2335,7 @@ namespace libtorrent
{ {
// the web seed connection will talk immediately to // the web seed connection will talk immediately to
// the proxy, without requiring CONNECT support // the proxy, without requiring CONNECT support
s->get<http_stream>().set_no_connect(true); s->get<http_stream>()->set_no_connect(true);
} }
boost::intrusive_ptr<peer_connection> c(new (std::nothrow) web_peer_connection( boost::intrusive_ptr<peer_connection> c(new (std::nothrow) web_peer_connection(