From b17b34924e629a3a78ee77646defc52734cd79b3 Mon Sep 17 00:00:00 2001 From: jyelon Date: Fri, 4 Mar 2022 14:05:24 -0500 Subject: [PATCH] A little code cleanup --- luprex/core/cpp/driver-common.cpp | 35 +++++++++++++------------------ luprex/core/cpp/driver-linux.cpp | 3 ++- luprex/core/cpp/driver-mingw.cpp | 3 ++- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/luprex/core/cpp/driver-common.cpp b/luprex/core/cpp/driver-common.cpp index cd15ea03..e63b7929 100644 --- a/luprex/core/cpp/driver-common.cpp +++ b/luprex/core/cpp/driver-common.cpp @@ -120,7 +120,7 @@ public: int last_write_nbytes; }; - DrivenEngine *driven_; + UniqueDrivenEngine driven_; std::vector chans_; std::map listen_sockets_; bool read_console_recently_; @@ -478,8 +478,18 @@ public: cleanup_channels(); } - void drive(DrivenEngine *de, int argc, char *argv[]) { - driven_ = de; + void drive(int argc, char *argv[]) { + if (argc < 2) { + DrivenEngine::print_usage(std::cerr, argv[0]); + exit(1); + } + driven_ = DrivenEngine::make(argv[1]); + if (driven_ == nullptr) { + DrivenEngine::print_usage(std::cerr, argv[0]); + exit(1); + } + DrivenEngine::set(driven_.get()); + read_console_recently_ = false; ssl_ctx_with_root_certs_ = new_ssl_context(false, true, ""); @@ -496,19 +506,18 @@ public: exit(1); } - DrivenEngine::set(de); handle_lua_source(); driven_->drv_invoke_event_init(argc, argv); handle_listen_ports(); - while (!de->drv_get_stop_driver()) { + while (!driven_->drv_get_stop_driver()) { handle_lua_source(); handle_console_output(); handle_new_outgoing_sockets(); handle_socket_input_output(); handle_console_input(); handle_console_output(); - de->drv_invoke_event_update(monoclock.get()); + driven_->drv_invoke_event_update(monoclock.get()); } for (ChanInfo &chan : chans_) { @@ -522,17 +531,3 @@ public: }; -void driver_drive(int argc, char *argv[]) { - Driver driver; - if (argc < 2) { - DrivenEngine::print_usage(std::cerr, argv[0]); - exit(1); - } - UniqueDrivenEngine engine = DrivenEngine::make(argv[1]); - if (engine == nullptr) { - DrivenEngine::print_usage(std::cerr, argv[0]); - exit(1); - } - driver.drive(engine.get(), argc, argv); -} - diff --git a/luprex/core/cpp/driver-linux.cpp b/luprex/core/cpp/driver-linux.cpp index ccaf479f..0e4debf2 100644 --- a/luprex/core/cpp/driver-linux.cpp +++ b/luprex/core/cpp/driver-linux.cpp @@ -268,6 +268,7 @@ int main(int argc, char **argv) enable_tty_raw(); OPENSSL_init_ssl(0, NULL); SourceDB::register_lua_builtins(); - driver_drive(argc, argv); + Driver driver; + driver.drive(argc, argv); } diff --git a/luprex/core/cpp/driver-mingw.cpp b/luprex/core/cpp/driver-mingw.cpp index 0da25d99..17c7d4bd 100644 --- a/luprex/core/cpp/driver-mingw.cpp +++ b/luprex/core/cpp/driver-mingw.cpp @@ -273,6 +273,7 @@ int main(int argc, char **argv) init_winsock(); OPENSSL_init_ssl(0, NULL); SourceDB::register_lua_builtins(); - driver_drive(argc, argv); + Driver driver; + driver.drive(argc, argv); }