@@ -281,6 +281,21 @@ struct cache_entry
281281 }
282282};
283283
284+ struct event_tuple
285+ {
286+ supply_events_ptr supply_events;
287+ get_timeout_ptr get_timeout;
288+ dispatch_events_ptr dispatch_events;
289+
290+ template <typename T>
291+ event_tuple (event_supplier<T>* es)
292+ {
293+ supply_events (std::bind1st (std::mem_fun (&T::supply_events), es));
294+ get_timeout (std::bind1st (std::mem_fun (&T::get_timeout), es));
295+ dispatch_events (std::bind1st (std::mem_fun (&T::dispatch_events), es));
296+ }
297+ };
298+
284299using namespace http ;
285300
286301int policy_callback (void *, const struct sockaddr *, socklen_t );
@@ -327,20 +342,6 @@ void logging_delegate::log_access(const string& s) const {}
327342
328343void logging_delegate::log_error (const string& s) const {}
329344
330- // EVENT SUPPLIER
331- event_supplier::event_supplier () {}
332-
333- event_supplier::~event_supplier () {}
334-
335- void event_supplier::supply_events (fd_set* read_fdset, fd_set* write_fdset, fd_set* exc_fdset, int * max) const {}
336-
337- long event_supplier::get_timeout () const
338- {
339- return 0L ;
340- }
341-
342- void event_supplier::dispatch_events () const {}
343-
344345// WEBSERVER CREATOR
345346create_webserver& create_webserver::https_mem_key (const std::string& https_mem_key)
346347{
@@ -654,7 +655,7 @@ void* webserver::select(void* self)
654655 }
655656
656657 {
657- std::map<std::string, event_supplier *>::const_iterator it;
658+ std::map<std::string, event_tuple *>::const_iterator it;
658659 pthread_rwlock_rdlock (&di->ws ->runguard );
659660 for (it = di->ws ->event_suppliers .begin (); it != di->ws ->event_suppliers .end (); ++it)
660661 {
@@ -704,7 +705,7 @@ void* webserver::select(void* self)
704705 ::select (max + 1 , &rs, &ws, &es, &timeout_value);
705706 MHD_run (di->daemon );
706707 {
707- std::map<std::string, event_supplier *>::const_iterator it;
708+ std::map<std::string, event_tuple *>::const_iterator it;
708709 pthread_rwlock_rdlock (&di->ws ->runguard );
709710 for (it = di->ws ->event_suppliers .begin (); it != di->ws ->event_suppliers .end (); ++it)
710711 {
@@ -1866,10 +1867,27 @@ void webserver::get_response(cache_entry* ce, http_response** res)
18661867 *res = ce->response .ptr ();
18671868}
18681869
1869- void webserver::register_event_supplier (const std::string& id, event_supplier* ev)
1870+ template <typename T>
1871+ void webserver::register_event_supplier (const std::string& id, event_supplier<T>* ev)
1872+ {
1873+ pthread_rwlock_wrlock (&runguard);
1874+ map<string, event_tuple*>::iterator it = event_suppliers.find (id);
1875+ if (it != event_suppliers.end ())
1876+ delete it->second ;
1877+ event_suppliers[id] = new event_tuple (&ev);
1878+ pthread_rwlock_unlock (&runguard);
1879+ }
1880+
1881+ void webserver::remove_event_supplier (const std::string& id)
18701882{
18711883 pthread_rwlock_wrlock (&runguard);
1872- event_suppliers[id] = ev;
1884+ map<string, event_tuple*>::iterator it = event_suppliers.find (id);
1885+ if (it != event_suppliers.end ())
1886+ {
1887+ event_tuple* evp (it->second );
1888+ event_suppliers.erase (it);
1889+ delete evp;
1890+ }
18731891 pthread_rwlock_unlock (&runguard);
18741892}
18751893
0 commit comments