@@ -853,21 +853,37 @@ pplx::task<void> http_linux_server::register_listener(details::http_listener_imp
853
853
{
854
854
pplx::extensibility::scoped_rw_lock_t lock (m_listeners_lock);
855
855
if (m_registered_listeners.find (listener) != m_registered_listeners.end ())
856
+ {
856
857
throw std::invalid_argument (" listener already registered" );
858
+ }
857
859
858
- m_registered_listeners[listener] = utility::details::make_unique<pplx::extensibility::reader_writer_lock_t >();
859
-
860
- auto found_hostport_listener = m_listeners.find (hostport);
861
- if (found_hostport_listener == m_listeners.end ())
860
+ try
862
861
{
863
- found_hostport_listener = m_listeners.insert (
864
- std::make_pair (hostport, utility::details::make_unique<details::hostport_listener>(this , hostport))).first ;
862
+ m_registered_listeners[listener] = utility::details::make_unique<pplx::extensibility::reader_writer_lock_t >();
865
863
866
- if (m_started)
867
- found_hostport_listener->second ->start ();
868
- }
864
+ auto found_hostport_listener = m_listeners.find (hostport);
865
+ if (found_hostport_listener == m_listeners.end ())
866
+ {
867
+ found_hostport_listener = m_listeners.insert (
868
+ std::make_pair (hostport, utility::details::make_unique<details::hostport_listener>(this , hostport))).first ;
869
869
870
- found_hostport_listener->second ->add_listener (path, listener);
870
+ if (m_started)
871
+ {
872
+ found_hostport_listener->second ->start ();
873
+ }
874
+ }
875
+
876
+ found_hostport_listener->second ->add_listener (path, listener);
877
+ }
878
+ catch (...)
879
+ {
880
+ // Future improvement - really this API should entirely be asychronously.
881
+ // the hostport_listener::start() method should be made to return a task
882
+ // throwing the exception.
883
+ m_registered_listeners.erase (listener);
884
+ m_listeners.erase (hostport);
885
+ throw ;
886
+ }
871
887
}
872
888
873
889
return pplx::task_from_result ();
0 commit comments