diff options
author | Lee Clagett <code@leeclagett.com> | 2020-10-13 15:15:07 +0000 |
---|---|---|
committer | Lee Clagett <code@leeclagett.com> | 2020-10-10 15:28:40 +0000 |
commit | 7414e2bac11cbf9163ca16dc1b1510b4fd9a0d64 (patch) | |
tree | 1cd7aa7394630a8be218534112ba88a5b618d96a /contrib/epee/include/net | |
parent | Merge pull request #7072 (diff) | |
download | monero-7414e2bac11cbf9163ca16dc1b1510b4fd9a0d64.tar.xz |
Change epee binary output from std::stringstream to byte_stream
Diffstat (limited to '')
-rw-r--r-- | contrib/epee/include/net/abstract_http_client.h | 2 | ||||
-rw-r--r-- | contrib/epee/include/net/http_client.h | 2 | ||||
-rw-r--r-- | contrib/epee/include/net/http_server_handlers_map2.h | 4 | ||||
-rw-r--r-- | contrib/epee/include/net/levin_base.h | 4 | ||||
-rw-r--r-- | contrib/epee/include/net/levin_protocol_handler_async.h | 5 | ||||
-rw-r--r-- | contrib/epee/include/net/net_helper.h | 5 |
6 files changed, 12 insertions, 10 deletions
diff --git a/contrib/epee/include/net/abstract_http_client.h b/contrib/epee/include/net/abstract_http_client.h index 1f8bbc605..5270824e1 100644 --- a/contrib/epee/include/net/abstract_http_client.h +++ b/contrib/epee/include/net/abstract_http_client.h @@ -70,7 +70,7 @@ namespace http virtual bool connect(std::chrono::milliseconds timeout) = 0; virtual bool disconnect() = 0; virtual bool is_connected(bool *ssl = NULL) = 0; - virtual bool invoke(const boost::string_ref uri, const boost::string_ref method, const std::string& body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; + virtual bool invoke(const boost::string_ref uri, const boost::string_ref method, const boost::string_ref body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; virtual bool invoke_get(const boost::string_ref uri, std::chrono::milliseconds timeout, const std::string& body = std::string(), const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; virtual bool invoke_post(const boost::string_ref uri, const std::string& body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; virtual uint64_t get_bytes_sent() const = 0; diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h index 9645e896b..3725ef079 100644 --- a/contrib/epee/include/net/http_client.h +++ b/contrib/epee/include/net/http_client.h @@ -233,7 +233,7 @@ namespace net_utils } //--------------------------------------------------------------------------- - inline bool invoke(const boost::string_ref uri, const boost::string_ref method, const std::string& body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) override + inline bool invoke(const boost::string_ref uri, const boost::string_ref method, const boost::string_ref body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) override { CRITICAL_REGION_LOCAL(m_lock); if(!is_connected()) diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h index ac22cd7a9..1665fdac7 100644 --- a/contrib/epee/include/net/http_server_handlers_map2.h +++ b/contrib/epee/include/net/http_server_handlers_map2.h @@ -118,8 +118,10 @@ return true; \ } \ uint64_t ticks2 = misc_utils::get_tick_count(); \ - epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), response_info.m_body); \ + epee::byte_slice buffer; \ + epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), buffer, 64 * 1024); \ uint64_t ticks3 = epee::misc_utils::get_tick_count(); \ + response_info.m_body.assign(reinterpret_cast<const char*>(buffer.data()), buffer.size()); \ response_info.m_mime_tipe = " application/octet-stream"; \ response_info.m_header_info.m_content_type = " application/octet-stream"; \ MDEBUG( s_pattern << "() processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \ diff --git a/contrib/epee/include/net/levin_base.h b/contrib/epee/include/net/levin_base.h index f9b6f9a81..ad561c5b6 100644 --- a/contrib/epee/include/net/levin_base.h +++ b/contrib/epee/include/net/levin_base.h @@ -31,7 +31,6 @@ #include <cstdint> -#include "byte_slice.h" #include "net_utils_base.h" #include "span.h" @@ -39,6 +38,7 @@ namespace epee { +class byte_slice; namespace levin { #pragma pack(push) @@ -86,7 +86,7 @@ namespace levin template<class t_connection_context = net_utils::connection_context_base> struct levin_commands_handler { - virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, t_connection_context& context)=0; + virtual int invoke(int command, const epee::span<const uint8_t> in_buff, byte_slice& buff_out, t_connection_context& context)=0; virtual int notify(int command, const epee::span<const uint8_t> in_buff, t_connection_context& context)=0; virtual void callback(t_connection_context& context){}; diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 1341a4ae6..8cb2be3e1 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -514,16 +514,15 @@ public: { if(m_current_head.m_have_to_return_data) { - std::string return_buff; + byte_slice return_buff; const uint32_t return_code = m_config.m_pcommands_handler->invoke( m_current_head.m_command, buff_to_invoke, return_buff, m_connection_context ); bucket_head2 head = make_header(m_current_head.m_command, return_buff.size(), LEVIN_PACKET_RESPONSE, false); head.m_return_code = SWAP32LE(return_code); - return_buff.insert(0, reinterpret_cast<const char*>(&head), sizeof(head)); - if(!m_pservice_endpoint->do_send(byte_slice{std::move(return_buff)})) + if(!m_pservice_endpoint->do_send(byte_slice{{epee::as_byte_span(head), epee::to_span(return_buff)}})) return false; MDEBUG(m_connection_context << "LEVIN_PACKET_SENT. [len=" << head.m_cb diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h index 9446e3588..508c79d76 100644 --- a/contrib/epee/include/net/net_helper.h +++ b/contrib/epee/include/net/net_helper.h @@ -44,6 +44,7 @@ #include <boost/lambda/lambda.hpp> #include <boost/interprocess/detail/atomic.hpp> #include <boost/system/error_code.hpp> +#include <boost/utility/string_ref.hpp> #include <functional> #include "net/net_utils_base.h" #include "net/net_ssl.h" @@ -280,7 +281,7 @@ namespace net_utils inline - bool send(const std::string& buff, std::chrono::milliseconds timeout) + bool send(const boost::string_ref buff, std::chrono::milliseconds timeout) { try @@ -298,7 +299,7 @@ namespace net_utils // object is used as a callback and will update the ec variable when the // operation completes. The blocking_udp_client.cpp example shows how you // can use boost::bind rather than boost::lambda. - async_write(buff.c_str(), buff.size(), ec); + async_write(buff.data(), buff.size(), ec); // Block until the asynchronous operation has completed. while (ec == boost::asio::error::would_block) |