Re: [Cppcms-users] Design decision
Brought to you by:
artyom-beilis
From: Christian G. <chr...@gm...> - 2012-10-04 12:11:32
|
2012/10/4 Artyom Beilis <art...@ya...>: >>________________________________ > >> From: Christian Gmeiner <chr...@gm...> >>To: cpp...@li... >>Sent: Thursday, October 4, 2012 11:01 AM >>Subject: [Cppcms-users] Design decision >> >>Hi all. >> >>My cppcms based web application is in a quite good shape and I got >>some ideas what >>new features could be added. >> >>+ Detection of networking changes via PF_NETLINK socket >> >>At the moment it is possible to configure networking settings via >>cppcms. For instance, >>it is possible to use manual mode for an ethernet interface to specify >>ip. netmask etc. or >>use DHCP mode. If DHCP gets used the running system starts dhcp client >>and it could >>takes some seconds until it got a valid IP address. >> >>The basic idea is now to use SSE (server send events) and some >>detection threads. >> >>Create a (cppcms ?) thread per ethernet interface and run something like >>http://stackoverflow.com/questions/579783/how-to-detect-ip-address-change-programmatically-in-linux >> >>Then I would have a singleton class for SSE where I can call e.g. >>SSE::instance()->ethernet("eth0", ip,...) and my front-end can update >>the values. >> >>Can this work? >> >> >>--- >>Christian Gmeiner, MSc >> > > Why not? > > Several points > > 1. In there link there is an example to use it without polling, so just use basic_io_device to check > for readability and then call recv > > So basically you don't need threads just implement event driven > handling in the event loop (see tutorial for examples) > This looks like the elegant solution I am looking for :) But... I don't get it up and running :/ I decided to go this way: #ifndef NETLINK_H_ #define NETLINK_H_ #include <booster/aio/basic_io_device.h> class Netlink : public booster::aio::basic_io_device { public: Netlink(); ~Netlink(); void read(booster::system::error_code const &e); private: char _buffer[4096]; }; #endif /* NETLINK_H_ */ And this is my main() // start cppcms service try { cppcms::service srv(argc, argv); booster::aio::io_service &io_srv = srv.get_io_service(); Netlink netlink; netlink.set_io_service(io_srv); netlink.on_readable(std::bind(&Netlink::read)); srv.applications_pool().mount(cppcms::applications_factory<Tssw>()); srv.run(); } catch (std::exception const &e) { std::cerr << e.what() << std::endl; } The big big problem is how should I use on_readable(..) ? The above example does not compile. ---- Christian Gmeiner, MSc |