static void flash_firmware(void) { char* svcs[] = { "l2tpd", "xl2tpd", "pppd", "wpa_cli", "wpa_supplicant", NULL }; stop_misc(); stop_services(0); // don't stop httpd/telnetd/sshd/vpn #if (BOARD_NUM_USB_PORTS > 0) stop_usb_printer_spoolers(); safe_remove_usb_device(0, NULL, 0); #endif stop_igmpproxy(NULL); kill_services(svcs, 6, 1); /* save storage (if changed) */ storage_save_time(60); write_storage_to_mtd(); sync(); sleep(1); if (eval("/tmp/mtd_write", "-r", "write", FW_IMG_NAME, FW_MTD_NAME) != 0) { start_watchdog(); } }
/// /// Initialize all needed data /// /// @param file_name to file of data that are sent to the client /// @param io_service reference to io_service /// @param thread_num_acceptors number of threads in thread pool for acceptors /// @param thread_num_executors number of threads in thread pool for executors /// @param local_port port to listen on, by default - 10001 /// @param local_interface_address local interface address to listen on /// @param timeout time in seconds for timeout of connection /// T_server::T_server(const std::string file_name, ba::io_service& io_service_acceptors, ba::io_service& io_service_executors, unsigned int thread_num_acceptors, unsigned int thread_num_executors, unsigned int local_port, std::string local_interface_address, const unsigned int timeout) : file_name_(file_name), io_service_acceptors_(io_service_acceptors), io_service_executors_(io_service_executors), work_acceptors_(io_service_acceptors_), work_executors_(io_service_executors_), local_endpoint_(local_interface_address.empty()? (ba::ip::tcp::endpoint(ba::ip::tcp::v4(), local_port)): // INADDR_ANY for v4 (in6addr_any if the fix to v6) ba::ip::tcp::endpoint(ba::ip::address().from_string(local_interface_address), local_port) ), // specified ip address acceptor_(io_service_acceptors_, local_endpoint_), // By default set option to reuse the address (i.e. SO_REUSEADDR) timeout_(timeout) { std::clog << "Start listener: " << local_endpoint_ << std::endl << std::endl; // create threads in pool for executors for(size_t i = 0; i < thread_num_executors; ++i) thr_grp_executors_.emplace_back(boost::bind(&boost::asio::io_service::run, &io_service_executors_)); // create threads in pool and start acceptors for(size_t i = 0; i < thread_num_acceptors; ++i) { // create threads in pool if(i != 0) // one main thread already in pool from: int main() { ... io_service_acceptors.run(); ... } thr_grp_acceptors_.emplace_back(boost::bind(&boost::asio::io_service::run, &io_service_acceptors_)); std::stringstream ss; try { // create memory pool for objects of connections T_memory_pool_ptr memory_pool_ptr(new T_memory_pool, T_memory_pool_deleter() ); // create next connection, that will accepted next T_connection * const memory_pool_raw_ptr = reinterpret_cast<T_connection *>( memory_pool_ptr.get() ); T_connection * const new_connection_raw_ptr = T_connection::create(file_name_, memory_pool_raw_ptr, 0, io_service_executors_, timeout_); // start another acceptor in async mode acceptor_.async_accept(new_connection_raw_ptr->socket(), new_connection_raw_ptr->client_bind( boost::bind(&T_server::handle_accept, this, boost::move(memory_pool_ptr), // doesn't copy and doesn't use the atomic counter with memory barrier 0, ba::placeholders::error)) ); } catch(const seh::T_seh_exception& e) { ss << "T_seh_exception: " << e.what() << "\n ->throw place: " << THROW_PLACE << std::endl; } catch(const bs::system_error& e) { ss << "Boost system_error exception: " << e.what() << "\n ->throw place: " << THROW_PLACE << std::endl; } catch(const std::exception &e) { ss << "Exception: " << e.what() << "\n ->throw place: " << THROW_PLACE << std::endl; } catch(...) { ss << "Unknown exception!" << "\n ->throw place: " << THROW_PLACE << std::endl; } if(ss.str().size() > 0) { stop_services(); throw std::runtime_error(ss.str()); } } }
void shutdown_router(int use_reboot) { int is_ap_mode = get_ap_mode(); stop_misc(); stop_services(1); #if (BOARD_NUM_USB_PORTS > 0) stop_usb_printer_spoolers(); safe_remove_usb_device(0, NULL, !use_reboot); #endif #if defined (BOARD_GPIO_LED_USB) LED_CONTROL(BOARD_GPIO_LED_USB, LED_OFF); #endif stop_wan(); stop_services_lan_wan(); set_ipv4_forward(0); #if defined (BOARD_GPIO_LED_WAN) LED_CONTROL(BOARD_GPIO_LED_WAN, LED_OFF); #endif storage_save_time(10); write_storage_to_mtd(); stop_8021x_all(); stop_wifi_all_wl(); stop_wifi_all_rt(); stop_logger(); stop_lan(is_ap_mode); umount_rwfs_partition(); #if defined (BOARD_GPIO_LED_LAN) LED_CONTROL(BOARD_GPIO_LED_LAN, LED_OFF); #endif #if defined (BOARD_GPIO_LED_POWER) LED_CONTROL(BOARD_GPIO_LED_POWER, LED_OFF); #endif if (!use_reboot) module_smart_unload("rt_timer_wdg", 0); }
/// Deinitialize services T_server::~T_server() { std::cerr << "~T_server() \n"; stop_services(); }