diff options
Diffstat (limited to 'contrib/epee')
-rw-r--r-- | contrib/epee/include/console_handler.h | 6 | ||||
-rw-r--r-- | contrib/epee/include/net/levin_protocol_handler_async.h | 35 | ||||
-rw-r--r-- | contrib/epee/include/net/net_utils_base.h | 5 | ||||
-rw-r--r-- | contrib/epee/include/serialization/keyvalue_serialization_overloads.h | 1 | ||||
-rw-r--r-- | contrib/epee/src/readline_buffer.cpp | 28 |
5 files changed, 48 insertions, 27 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index bb20faa65..6832f2ea1 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -315,7 +315,11 @@ namespace epee if (!m_prompt.empty()) { #ifdef HAVE_READLINE - m_stdin_reader.get_readline_buffer().set_prompt(m_prompt); + std::string color_prompt = "\001\033[1;33m\002" + m_prompt; + if (' ' != m_prompt.back()) + color_prompt += " "; + color_prompt += "\001\033[0m\002"; + m_stdin_reader.get_readline_buffer().set_prompt(color_prompt); #else epee::set_console_color(epee::console_color_yellow, true); std::cout << m_prompt; diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 5ef782206..8aa0faba1 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -144,7 +144,6 @@ public: virtual void cancel()=0; virtual bool cancel_timer()=0; virtual void reset_timer()=0; - virtual void timeout_handler(const boost::system::error_code& error)=0; }; template <class callback_t> struct anvoke_handler: invoke_response_handler_base @@ -157,9 +156,15 @@ public: { MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout); m_timer.expires_from_now(boost::posix_time::milliseconds(timeout)); - m_timer.async_wait([this](const boost::system::error_code& ec) + m_timer.async_wait([&con, command, cb, timeout](const boost::system::error_code& ec) { - timeout_handler(ec); + if(ec == boost::asio::error::operation_aborted) + return; + MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout); + std::string fake; + cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref()); + con.close(); + con.finish_outer_call(); }); m_timer_started = true; } @@ -174,16 +179,6 @@ public: bool m_timer_cancelled; uint64_t m_timeout; int m_command; - virtual void timeout_handler(const boost::system::error_code& error) - { - if(error == boost::asio::error::operation_aborted) - return; - MINFO(m_con.get_context_ref() << "Timeout on invoke operation happened, command: " << m_command << " timeout: " << m_timeout); - std::string fake; - m_cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, m_con.get_context_ref()); - m_con.close(); - m_con.finish_outer_call(); - } virtual bool handle(int res, const std::string& buff, typename async_protocol_handler::connection_context& context) { if(!cancel_timer()) @@ -220,10 +215,20 @@ public: boost::system::error_code ignored_ec; if (!m_cancel_timer_called && m_timer.cancel(ignored_ec) > 0) { + callback_t& cb = m_cb; + uint64_t timeout = m_timeout; + async_protocol_handler& con = m_con; + int command = m_command; m_timer.expires_from_now(boost::posix_time::milliseconds(m_timeout)); - m_timer.async_wait([this](const boost::system::error_code& ec) + m_timer.async_wait([&con, cb, command, timeout](const boost::system::error_code& ec) { - timeout_handler(ec); + if(ec == boost::asio::error::operation_aborted) + return; + MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout); + std::string fake; + cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref()); + con.close(); + con.finish_outer_call(); }); } } diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h index 1884412dc..3bea11985 100644 --- a/contrib/epee/include/net/net_utils_base.h +++ b/contrib/epee/include/net/net_utils_base.h @@ -115,10 +115,9 @@ namespace net_utils std::string host_str() const { return (*this) ? (*this)->host_str() : "<none>"; } bool is_loopback() const { return (*this)->is_loopback(); } bool is_local() const { return (*this)->is_local(); } - const std::type_info &type() const { return typeid(**this); } uint8_t get_type_id() const { return (*this)->get_type_id(); } - template<typename Type> Type &as() { if (type() != typeid(Type)) throw std::runtime_error("Bad type"); return *(Type*)get(); } - template<typename Type> const Type &as() const { if (type() != typeid(Type)) throw std::runtime_error("Bad type"); return *(const Type*)get(); } + template<typename Type> Type &as() { if (get_type_id() != Type::ID) throw std::runtime_error("Bad type"); return *(Type*)get(); } + template<typename Type> const Type &as() const { if (get_type_id() != Type::ID) throw std::runtime_error("Bad type"); return *(const Type*)get(); } BEGIN_KV_SERIALIZE_MAP() uint8_t type = is_store ? this_ref.get_type_id() : 0; diff --git a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h index 33486d9ec..1a58cab99 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h +++ b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h @@ -126,7 +126,6 @@ namespace epee static bool serialize_stl_container_pod_val_as_blob(const stl_container& container, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname) { if(!container.size()) return true; - typename stl_container::const_iterator it = container.begin(); std::string mb; mb.resize(sizeof(typename stl_container::value_type)*container.size()); typename stl_container::value_type* p_elem = (typename stl_container::value_type*)mb.data(); diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp index 2d17103b3..c846641bd 100644 --- a/contrib/epee/src/readline_buffer.cpp +++ b/contrib/epee/src/readline_buffer.cpp @@ -5,6 +5,7 @@ #include <unistd.h> #include <mutex> #include <condition_variable> +#include <boost/thread.hpp> static int process_input(); static void install_line_handler(); @@ -12,7 +13,7 @@ static void remove_line_handler(); static std::string last_line; static std::string last_prompt; -std::mutex line_mutex, sync_mutex; +std::mutex line_mutex, sync_mutex, process_mutex; std::condition_variable have_line; namespace @@ -21,6 +22,7 @@ namespace } rdln::suspend_readline::suspend_readline() +: m_buffer(NULL), m_restart(false) { m_buffer = current; if(!m_buffer) @@ -46,6 +48,7 @@ rdln::readline_buffer::readline_buffer() void rdln::readline_buffer::start() { + std::unique_lock<std::mutex> lock(process_mutex); if(m_cout_buf != NULL) return; m_cout_buf = std::cout.rdbuf(); @@ -55,6 +58,7 @@ void rdln::readline_buffer::start() void rdln::readline_buffer::stop() { + std::unique_lock<std::mutex> lock(process_mutex); if(m_cout_buf == NULL) return; std::cout.rdbuf(m_cout_buf); @@ -80,9 +84,17 @@ void rdln::readline_buffer::set_prompt(const std::string& prompt) int rdln::readline_buffer::process() { + process_mutex.lock(); if(m_cout_buf == NULL) + { + process_mutex.unlock(); + boost::this_thread::sleep_for(boost::chrono::milliseconds( 1 )); return 0; - return process_input(); + } + int count = process_input(); + process_mutex.unlock(); + boost::this_thread::sleep_for(boost::chrono::milliseconds( 1 )); + return count; } int rdln::readline_buffer::sync() @@ -114,19 +126,18 @@ int rdln::readline_buffer::sync() return 0; } -static fd_set fds; - static int process_input() { int count; struct timeval t; + fd_set fds; t.tv_sec = 0; t.tv_usec = 1000; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); - count = select(FD_SETSIZE, &fds, NULL, NULL, &t); + count = select(STDIN_FILENO + 1, &fds, NULL, NULL, &t); if (count < 1) { return count; @@ -168,8 +179,11 @@ static int handle_enter(int x, int y) } free(line); - rl_set_prompt(last_prompt.c_str()); - rl_redisplay(); + if(last_line != "exit") + { + rl_set_prompt(last_prompt.c_str()); + rl_redisplay(); + } rl_done = 1; return 0; |