44 #include <boost/asio.hpp>
45 #include <boost/assign.hpp>
46 #include <boost/filesystem.hpp>
47 #include <boost/lexical_cast.hpp>
48 #include <boost/program_options.hpp>
49 #include <boost/thread.hpp>
50 #include <boost/unordered_map.hpp>
52 using namespace boost;
53 using namespace boost::asio::ip;
54 using namespace boost::filesystem;
58 namespace popt = boost::program_options;
72 <<
"Servint petició en fil " << this_thread::get_id() <<
commit;
81 catch (
const std::exception & e) {
82 cerr <<
"Error no previst: " << e.what() << endl;
88 <<
"(" << this_thread::get_id() <<
"): Sessió finalitzada" <<
commit;
96 static boost::unordered_map<int, string> noms_senyals = boost::assign::map_list_of
98 ( SIGTERM,
"SIGTERM" )
100 ( SIGUSR1,
"SIGUSR1" )
104 cerr <<
"> Sortida: senyal " << noms_senyals[signum] <<
" rebuda" << endl;
111 int main(
int argc,
char * argv[],
char * envp[]) {
123 asio::io_service io_service;
126 asio::signal_set senyals(io_service, SIGINT, SIGTERM);
128 senyals.add(SIGUSR1);
130 senyals.async_wait(signal_callback);
137 cerr <<
"Servidor Web (TFC primavera 2012) v" VERSION "\n"
147 assert( filesystem::is_directory(cfg.
arrel()) );
150 log() <<
"Iniciant thread pool..." <<
commit;
154 log() <<
"> Obrint servei (port " << cfg.
port() <<
")..." <<
commit;
156 tcp::acceptor acceptador(io_service, tcp::endpoint(tcp::v4(), cfg.
port()));
158 log() <<
" + Escoltant en " << acceptador.local_endpoint() <<
commit;
167 acceptador.accept(*psocket);
171 << psocket->local_endpoint() <<
" <-> "
172 << psocket->remote_endpoint() <<
commit;
173 #ifdef THREADS_A_PETICIO
174 boost::thread(Executor(cfg, psocket));
176 pool.programa(Executor(cfg, psocket));
179 #if 0 // Durant proves
180 catch (
const boost::system::system_error & e) {
181 cerr <<
"Error no previst (Boost): " << e.what() << endl;
184 catch (
const std::exception & e) {
185 cerr <<
"Error no previst: " << e.what() << endl;
192 cerr << e.what() << endl;
197 cout << e.what() << endl;
202 cout <<
"Entorn de compilació:"
204 "\n Sistema operatiu : " TFC_SO
206 "\n Data de compilació : " __DATE__
208 "\n zlib : " ZLIB_VERSION
213 cerr <<
"Error de log: " << e.what() << endl;
216 catch (
const std::exception & e) {
217 cerr <<
"Error intern: " << e.what() << endl;