Coder Social home page Coder Social logo

lproxy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lproxy's Issues

Host not found (authoritative)

lssserver.exe:

2016-Apr-09 12:06:07.268711 [DEBUG] start socks5_request_processing...  [tid:7f0723367780] session_server.cpp:274 left_read_handler
2016-Apr-09 12:06:07.268715 [DEBUG] lproxy::socks5::req::AddrType = domain  [tid:7f0723367780] session_server.cpp:943 socks5_request_processing
2016-Apr-09 12:06:07.268734 [DEBUG] lproxy::socks5::req::Addr.domain = cn.bing.com  [tid:7f0723367780] session_server.cpp:949 socks5_request_processing
2016-Apr-09 12:06:07.268739 [DEBUG] lproxy::socks5::req::Port = 80  [tid:7f0723367780] session_server.cpp:973 socks5_request_processing
2016-Apr-09 12:06:07.268754 [DEBUG] lproxy::socks5::req::Cmd = TCP-CONNECT  [tid:7f0723367780] session_server.cpp:977 socks5_request_processing
2016-Apr-09 12:06:07.268842 [DEBUG] start async_read local...   [tid:7f0723367780] session_server.cpp:287 left_read_handler
2016-Apr-09 12:06:07.269290 [ WARN] Host not found (authoritative)  [tid:7f0721935700] session_server.cpp:1106 tcp_resolve_handler

在 deel/lproxy-dev 里运行的好好的,到了基于 docker.io/busybox 制作的镜像的容器中,就会报上面的那个问题,导致 lproxy 服务不可用。

网搜查到几个可能有帮助的链接:

  1. http://stackoverflow.com/questions/12542460/boost-asio-host-not-found-authorative
  2. http://stackoverflow.com/questions/5971242/how-does-boost-asios-hostname-resolution-work-on-linux-is-it-possible-to-use-n

摘录下来就是

The problem was that the constructor for query has the address_configured flag set by default which won't return an address if the loopback device is the only device with an address. By just settings flags to 0 or anything other than address_configured the problem is fixed. Here is what I'm successfully using now:
tcp::resolver::query query(host, PORT, boost::asio::ip::resolver_query_base::numeric_service);

查了下文档:

http://www.boost.org/doc/libs/1_60_0/doc/html/boost_asio/reference/ip__resolver_query_base.html#boost_asio.reference.ip__resolver_query_base.data_members

Name Description
address_configured Only return IPv4 addresses if a non-loopback IPv4 address is configured for the system. Only return IPv6 addresses if a non-loopback IPv6 address is configured for the system.
all_matching If used with v4_mapped, return all matching IPv6 and IPv4 addresses.
canonical_name Determine the canonical name of the host specified in the query.
numeric_host Host name should be treated as a numeric string defining an IPv4 or IPv6 address and no name resolution should be attempted.
numeric_service Service name should be treated as a numeric string defining a port number and no name resolution should be attempted.
passive Indicate that returned endpoint is intended for use as a locally bound socket endpoint.
v4_mapped If the query protocol family is specified as IPv6, return IPv4-mapped IPv6 addresses on finding no IPv6 addresses.

记录下来,以便查阅

"Program received signal SIGSEGV, Segmentation fault. if (descriptor_data->shutdown_)" [Ubuntu 14.04.1 LTS 64bit]

相关链接: https://svn.boost.org/trac/boost/ticket/7611

2016-Apr-22 13:30:41.860226 [DEBUG] Verify completed    [tid:7ffff65c3700] session_local.cpp:295 right_read_handler
2016-Apr-22 13:30:41.860467 [DEBUG] ---> bytes_transferred = 3  [tid:7ffff7fef780] session_local.cpp:479 left_read_socks5_step1
2016-Apr-22 13:30:41.860658 [DEBUG] read data from client: 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  [tid:7ffff7fef780] session_local.cpp:484 left_read_socks5_step1
2016-Apr-22 13:30:41.860676 [DEBUG] send socks5_data to client: 5 0     [tid:7ffff7fef780] session_local.cpp:497 left_read_socks5_step1
2016-Apr-22 13:30:41.860775 [DEBUG] ---> bytes_transferred = 2  [tid:7ffff7fef780] session_local.cpp:543 left_write_socks5_step1_handler
2016-Apr-22 13:30:41.860783 [DEBUG] begin async_read_some from client   [tid:7ffff7fef780] session_local.cpp:546 left_write_socks5_step1_handler
2016-Apr-22 13:30:41.862293 [DEBUG] ---> bytes_transferred = 24 [tid:7ffff7fef780] session_local.cpp:565 left_read_handler
2016-Apr-22 13:30:41.862501 [DEBUG] read data from client: 5 1 0 3 11 73 63 30 2e 68 61 6f 31 32 33 69 6d 67 2e 63 6f 6d 0 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0   [tid:7ffff7fef780] session_local.cpp:572 left_read_handler
2016-Apr-22 13:30:41.862571 [DEBUG] pack data/zipdata: 0 6 0 18 be 9c e3 39 b9 10 8 cf 15 73 c3 66 61 56 f2 92 82 5 f9 e5 94 96 ce d1   [tid:7ffff7fef780] session_local.cpp:725 pack_data
2016-Apr-22 13:30:41.862655 [DEBUG] and send to server. [tid:7ffff7fef780] session_local.cpp:585 left_read_handler
2016-Apr-22 13:30:41.863201 [DEBUG] ---> bytes_transferred = 28 [tid:7ffff65c3700] session_local.cpp:635 right_write_handler
2016-Apr-22 13:30:41.863706 [DEBUG] ---> bytes_transferred = 639    [tid:7ffff65c3700] session_local.cpp:238 right_read_handler
2016-Apr-22 13:30:41.863715 [DEBUG] lss_reply->version() = 0    [tid:7ffff65c3700] session_local.cpp:240 right_read_handler
2016-Apr-22 13:30:41.863720 [DEBUG] lss_reply->type() = 6   [tid:7ffff65c3700] session_local.cpp:241 right_read_handler

Program received signal SIGSEGV, Segmentation fault.
0x000000000041a5d1 in boost::asio::detail::epoll_reactor::start_op (this=0x179fd80, op_type=1, descriptor=40, descriptor_data=@0x17fdc58: 0x0, op=0x17a40c0, is_continuation=false, 
    allow_speculative=true) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/impl/epoll_reactor.ipp:219
219   if (descriptor_data->shutdown_)
(gdb) p descriptor_data
$1 = (boost::asio::detail::epoll_reactor::per_descriptor_data &) @0x17fdc58: 0x0
(gdb) l
214     return;
215   }
216 
217   mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
218 
219   if (descriptor_data->shutdown_)
220   {
221     post_immediate_completion(op, is_continuation);
222     return;
223   }
(gdb) bt
#0  0x000000000041a5d1 in boost::asio::detail::epoll_reactor::start_op (this=0x179fd80, op_type=1, descriptor=40, descriptor_data=@0x17fdc58: 0x0, op=0x17a40c0, is_continuation=false, 
    allow_speculative=true) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/impl/epoll_reactor.ipp:219
#1  0x000000000041d3c0 in boost::asio::detail::reactive_socket_service_base::start_op (this=0x17a28b8, impl=..., op_type=1, op=0x17a40c0, is_continuation=false, is_non_blocking=true, 
    noop=false) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/impl/reactive_socket_service_base.ipp:214
#2  0x0000000000457bfe in boost::asio::detail::reactive_socket_service_base::async_send<boost::asio::detail::consuming_buffers<boost::asio::const_buffer, boost::array<boost::asio::const_buffer, 5ul> >, boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::array<boost::asio::const_buffer, 5ul>, boost::asio::detail::transfer_all_t, boost::_bi::bind_t<void, boost::_mfi::mf0<void, lproxy::local::session>, boost::_bi::list1<boost::_bi::value<std::shared_ptr<lproxy::local::session> > > > > > (this=0x17a28b8, impl=..., buffers=..., flags=0, handler=...)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/reactive_socket_service_base.hpp:216
#3  0x0000000000454ef0 in boost::asio::stream_socket_service<boost::asio::ip::tcp>::async_send<boost::asio::detail::consuming_buffers<boost::asio::const_buffer, boost::array<boost::asio::const_buffer, 5ul> >, boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::array<boost::asio::const_buffer, 5ul>, boost::asio::detail::transfer_all_t, boost::_bi::bind_t<void, boost::_mfi::mf0<void, lproxy::local::session>, boost::_bi::list1<boost::_bi::value<std::shared_ptr<lproxy::local::session> > > > > >(boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp>::implementation_type&, boost::asio::detail::consuming_buffers<boost::asio::const_buffer, boost::array<boost::asio::const_buffer, 5ul> > const&, int, boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::array<boost::asio::const_buffer, 5ul>, boost::asio::detail::transfer_all_t, boost::_bi::bind_t<void, boost::_mfi::mf0<void, lproxy::local::session>, boost::_bi::list1<boost::_bi::value<std::shared_ptr<lproxy::local::session> > > > >&&) (this=0x17a2890, impl=..., buffers=..., flags=0, handler=<unknown type in /opt/lproxy/bin/lsslocal.exe, CU 0x66ee9, DIE 0xdd2c9>)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/stream_socket_service.hpp:330
#4  0x0000000000452634 in boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >::async_write_some<boost::asio::detail::consuming_buffers<boost::asio::const_buffer, boost::array<boost::asio::const_buffer, 5ul> >, boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::array<boost::asio::const_buffer, 5ul>, boost::asio::detail::transfer_all_t, boost::_bi::bind_t<void, boost::_mfi::mf0<void, lproxy::local::session>, boost::_bi::list1<boost::_bi::value<std::shared_ptr<lproxy::local::session> > > > > >(boost::asio::detail::consuming_buffers<boost::asio::const_buffer, boost::array<boost::asio::const_buffer, 5ul> > const&, boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::array<boost::asio::const_buffer, 5ul>, boost::asio::detail::transfer_all_t, boost::_bi::bind_t<void, boost::_mfi::mf0<void, lproxy::local::session>, boost::_bi::list1<boost::_bi::value<std::shared_ptr<lproxy::local::session> > > > >&&) (this=0x17fdc50, buffers=..., handler=<unknown type in /opt/lproxy/bin/lsslocal.exe, CU 0x66ee9, DIE 0xd8be6>)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/basic_stream_socket.hpp:732
#5  0x000000000044f3a8 in boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::array<boost::asio::const_buffer, 5ul>, boost::asio::detail::transfer_all_t, boost::_bi::bind_t<void, boost::_mfi::mf0<void, lproxy::local::session>, boost::_bi::list1<boost::_bi::value<std::shared_ptr<lproxy::local::session> > > > >::operator() (this=0x7fffffffdb80, ec=..., bytes_transferred=0, start=1)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/impl/write.hpp:181
#6  0x000000000044b323 in boost::asio::async_write<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::array<boost::asio::const_buffer, 5ul>, boost::_bi::bind_t<void, boost::_mfi::mf0<void, lproxy::local::session>, boost::_bi::list1<boost::_bi::value<std::shared_ptr<lproxy::local::session> > > > >(boost::asio::---Type <return> to continue, or q <return> to quit---
basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >&, boost::array<boost::asio::const_buffer, 5ul> const&, boost::_bi::bind_t<void, boost::_mfi::mf0<void, lproxy::local::session>, boost::_bi::list1<boost::_bi::value<std::shared_ptr<lproxy::local::session> > > >&&) (s=..., buffers=..., 
    handler=<unknown type in /opt/lproxy/bin/lsslocal.exe, CU 0x66ee9, DIE 0xcdc74>) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/impl/write.hpp:621
#7  0x000000000043fb06 in lproxy::local::session::left_read_handler (this=0x17fdbe0, error=..., bytes_transferred=0, data_left=std::shared_ptr (count 3, weak 0) 0x7fffe80114c0)
    at session_local.cpp:614
#8  0x0000000000459c2e in boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >::call<std::shared_ptr<lproxy::local::session>, boost::system::error_code const, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > (this=0x7fffffffe1a0, u=std::shared_ptr (count 3, weak 1) 0x17fdbe0, b1=..., b2=@0x7fffffffdf40: 0, 
    b3=std::shared_ptr (count 3, weak 0) 0x7fffe80114c0) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/bind/mem_fn_template.hpp:384
#9  0x0000000000457494 in boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >::operator()<std::shared_ptr<lproxy::local::session> > (this=0x7fffffffe1a0, u=std::shared_ptr (count 3, weak 1) 0x17fdbe0, a1=..., a2=0, 
    a3=std::shared_ptr (count 3, weak 0) 0x7fffe80114c0) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/bind/mem_fn_template.hpp:399
#10 0x0000000000454bcc in boost::_bi::list4<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > >::operator()<boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list2<boost::system::error_code const&, unsigned long const&> > (this=0x7fffffffe1b0, f=..., a=...) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/bind/bind.hpp:457
#11 0x0000000000452222 in boost::_bi::bind_t<void, boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list4<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > >::operator()<boost::system::error_code, unsigned long> (
    this=0x7fffffffe1a0, a1=..., a2=@0x7fffffffe1e0: 0) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/bind/bind_template.hpp:102
#12 0x000000000045d23b in boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list4<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > >, boost::system::error_code, unsigned long>::operator() (this=0x7fffffffe1a0) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/bind_handler.hpp:127
#13 0x000000000045bd07 in boost::asio::asio_handler_invoke<boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list4<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > >, boost::system::error_code, unsigned long> > (function=...) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/handler_invoke_hook.hpp:69
#14 0x0000000000459dd4 in boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list4<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned cha---Type <return> to continue, or q <return> to quit---
r> > > > > >, boost::system::error_code, unsigned long>, boost::_bi::bind_t<void, boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list4<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > > > (function=..., 
    context=...) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/handler_invoke_helpers.hpp:37
#15 0x0000000000457895 in boost::asio::detail::reactive_socket_recv_op<boost::asio::mutable_buffers_1, boost::_bi::bind_t<void, boost::_mfi::mf3<void, lproxy::local::session, boost::system::error_code const&, unsigned long, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list4<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > > >::do_complete (owner=0x179f790, base=0x7fffe800e6e0) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/reactive_socket_recv_op.hpp:110
#16 0x00000000004196ba in boost::asio::detail::task_io_service_operation::complete (this=0x7fffe800e6e0, owner=..., ec=..., bytes_transferred=0)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/task_io_service_operation.hpp:38
#17 0x000000000041b4bd in boost::asio::detail::epoll_reactor::descriptor_state::do_complete (owner=0x179f790, base=0x17a99e0, ec=..., bytes_transferred=1)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/impl/epoll_reactor.ipp:651
#18 0x00000000004196ba in boost::asio::detail::task_io_service_operation::complete (this=0x17a99e0, owner=..., ec=..., bytes_transferred=1)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/task_io_service_operation.hpp:38
#19 0x000000000041c040 in boost::asio::detail::task_io_service::do_run_one (this=0x179f790, lock=..., this_thread=..., ec=...)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/impl/task_io_service.ipp:372
#20 0x000000000041baa3 in boost::asio::detail::task_io_service::run (this=0x179f790, ec=...)
    at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/detail/impl/task_io_service.ipp:149
#21 0x000000000041c335 in boost::asio::io_service::run (this=0x7fffffffe500) at /opt/lproxy/src/core/lss/../../..//contrib/boost/boost_1_57_0/boost/asio/impl/io_service.ipp:59
#22 0x00000000004169da in main (argc=1, argv=0x7fffffffe818) at local.cpp:127
(gdb) l local.cpp:127
122     boost::asio::io_service io_service;
123 
124     lproxy::local::lss_server s(io_service, bind_addr, bind_port);
125     for (;;) {
126         try {
127             io_service.run();
128             break;
129         }
130         catch (boost::system::system_error const& e) {
131             logerror(e.what());
(gdb) l epoll_reactor.ipp:219
214     return;
215   }
216 
217   mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
218 
219   if (descriptor_data->shutdown_)
220   {
221     post_immediate_completion(op, is_continuation);
222     return;
223   }
(gdb) l 209
204 }
205 
206 void epoll_reactor::start_op(int op_type, socket_type descriptor,
207     epoll_reactor::per_descriptor_data& descriptor_data, reactor_op* op,
208     bool is_continuation, bool allow_speculative)
209 {
210   if (!descriptor_data)
211   {
212     op->ec_ = boost::asio::error::bad_descriptor;
213     post_immediate_completion(op, is_continuation);
(gdb) 
214     return;
215   }
216 
217   mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
218 
219   if (descriptor_data->shutdown_)
220   {
221     post_immediate_completion(op, is_continuation);
222     return;
223   }
(gdb) 

程度:致命
频率:偶现
临时解决方案:带 -k--keep-running 参数的启动程序

Socks5 通信优化项(进一步提高 lproxy 的性能)

版本:v0.1.0.20160418_Beta

lss 握手以后,就开始转发 Socks5 数据了,在 Socks5 刚开始的阶段:

socks5-client -> socks5-server

VER NMETHODS METHODS
1 1 1 to 255

然后 socks5-server -> socks5-client 应答

VER METHOD
1 1

这一应答过程,在 v0.1.0.20160418_Beta 版本中是通过 lssserver 端完成的,其实完全没有这个必要,这一步完全可以在 lsslocal 端完成。这样优化的话有很多好处:

  1. 减少 lsslocal 和 lssserver 之间的请求应答次数,进而节省宽带,提高网络利用率。
  2. 减轻 lssserver 端的负担,如果并发比较多,那减的负担可不是一丁点了,使 lssserver 抽开身完成其他待处理的工作。

总之,性能会进一步提高

ERROR 宏污染

在 MinGW 环境下编译日志库:

宏定义部分:
1

实现部分:
1

编译命令:

g++ -E -P

1

生成代码文件:
1

ERROR 被神奇的临时变成了 0,其他都一切正常

测试:

  1. g++ -c  -Wall -D_REENTRANT -DLOG_LOCKFREE_QUEUE   -std=gnu++0x  -I../lproxy-local-android  -I../lproxy-local-android/lproxy/contrib/boost/boost_1_57_0  -I../lproxy-local-android/lproxy/src/core  -o loglevel.o ../lproxy-local-android/lproxy/src/core/log/loglevel.cpp
    

    编译没有问题

  2. 但是用

    g++ -c -pipe -fno-keep-inline-dllexport -include winsock2.h -g -std=c++0x -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DLOG_LOCKFREE_QUEUE -D_REENTRANT -DBOOST_REGEX_NO_LIB -DBOOST_DATE_TIME_SOURCE -DBOOST_SYSTEM_NO_LIB -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_WEBSOCKETS_LIB -DQT_NETWORK_LIB -DQT_WEBCHANNEL_LIB -DQT_CORE_LIB -I../lproxy-local-android -I. -I../lproxy-local-android/lproxy/contrib/boost/boost_1_57_0 -I../lproxy-local-android/lproxy/contrib/cryptopp -I../lproxy-local-android/lproxy/src/core -I../lproxy-local-android/lproxy/src/core/boost_build -ID:/Qt/QtDev/5.5/mingw492_32/include -ID:/Qt/QtDev/5.5/mingw492_32/include/QtQuick -ID:/Qt/QtDev/5.5/mingw492_32/include/QtGui -ID:/Qt/QtDev/5.5/mingw492_32/include/QtANGLE -ID:/Qt/QtDev/5.5/mingw492_32/include/QtQml -ID:/Qt/QtDev/5.5/mingw492_32/include/QtWebSockets -ID:/Qt/QtDev/5.5/mingw492_32/include/QtNetwork -ID:/Qt/QtDev/5.5/mingw492_32/include/QtWebChannel -ID:/Qt/QtDev/5.5/mingw492_32/include/QtCore -Idebug -ID:/Qt/QtDev/5.5/mingw492_32/mkspecs/win32-g++  -o loglevel.o ../lproxy-local-android/lproxy/src/core/log/loglevel.cpp
    

    这行命令编译就会出现“宏污染”的问题:
    image

分享一篇文章《那些年我们追过的网络库》

原文地址:https://www.avboost.com/t/topic/654
作者:microcai 菜菜博士

为什么要用 C++ 编写服务端程序?

如果说答案是性能,那么肯定有人会满不在乎。觉得性能不够的话, 只要加机器就可以了。
然而更少的机器,意味着更低的能耗,更少的硬件投入,更少的人力资源投入去维护机器。总而言之,更低的成本。

肯定会有人说,C++的开发速度太慢了。然而这并不是绝对的。C++也可以做到非常快速的开发。有句俗语 “脚本一时爽,重构火葬场” 说的正是脚本语言开发的项目进入维护阶段后无穷的灾难。而 C++ 经过了几十年的发展, 拥有庞大的工具链. 不管是动态分析还是静态分析都有大量的工具, 能极大的帮助程序员减少错误.
c++得益于精良的设计,严格的检查,越是大型的工程,越是能降低开发成本。

但这并不意味着C++就不适合小型项目了。小型的项目,也可以快速开发。因为 C++11 开始,已经_感觉像是全新的语言了_,可以完全以脚本的形式去使用,获得接近甚至超越脚本语言的开发速度,同时得益于编译优化,获得不俗的运行时性能。
C++正是鱼和熊掌得兼的语言。

为什么要用asio这个库?
事实上如果使用C++开发服务端程序,你有多得数不清的选择。什么 ACE 啦,libuv 啦,libevent 啦,libev 啦,甚至可以直接使用 epoll/iocp 这样的系统API。
为什么要用 asio 呢?

那些年我们用过的网络库
在计算机史前文明时代, 曾经有个世界难题, 叫 "c10k problem". 这个是继 y2k problem 后的又一个重大攻关项目. 全世界的文艺青年都想拿下解决这个问题的荣誉, 正可谓八仙过海, 各显神通.

那一年, NPTL 还没有研究出来. 还不能创建成千上万个线程

那一年, windows 还在蓝屏中挣扎, 无暇顾及网络.

然而, 曙光还是有的. 异步的出现带给了人以希望. 古老的UNIX早就想到了, 提供了 select() 系统调用供人驱使.
然而问题还是有的, select 只能支持 1024 个文件描述符, windows 上的 select 更是劣质到只能使用64个. 就算通过修改定义强迫接受一万个文件描述符, 也没有解决实际的问题. select 实在是太慢了.

在这种背景下, IBM 老大哥带领着MS老弟先搞了 IOCP . 然而开源的人有开源的做法, 在 NIH 综合症的影响下, BSD 的人敢为天下所不齿, 发明了 Kqueue. 同样在 NIH 综合症影响下, Linux 的一群 M* 的猴子捣鼓出了 epoll.

分裂, 让人头疼.

然而, 他们都声称自己的新接口对 select 有质的提升, 是破解 c10k 问题的不二法宝. 你用也得用, 不用也得用.
为了让自己编写的网络程序能跨平台, 程序员开始了对3大各自为阵的法宝的膜拜学习.
除了需要应对多套互不兼容的 API , 异步本身也需要更高级的抽象, 把程序员从编写异步代码的地狱模式里拯救出来. 于是程序员们急需一个上天入地无所不能的法宝的法宝, 把这3家法宝给统御起来.

率先站出来悳瑟的是 ACE.

  1. 悳瑟的 ACE

    恰乱世刚过, 天下待定, C++ 委员会的老人们却韬光养晦, 不问世事. 所谓乱世出英雄, 英雄出少年, 欧文大学出了名秀才. 凭借其洋洋洒洒的一片雄文 《Pattern-Oriented Software Architecture》 中举去了首府学城, 并为ACE奠定了无可撼动的地位.

    ACE 的名字, 也许灵感来自 Adaptive Clubbed Rod, 这也是当年一位英雄少年的宝贝. 既是宝贝, 必需如意. 即是后来的葫芦娃都怕了 "如意宝贝".

    ACE 如意在什么地方呢?如意其一, 支持 IOCP/kqueu/epoll/select/you_name_it 各种接口, 号曰没有不能跨的平台. 如意其二, 支持多种模型。这些模型都在《Pattern-Oriented Software Architecture》有过详细叙述. ACE 本身就是这篇论文的实践,因为他知道, 纸上得来终觉浅 绝知此事要躬行。 如意其三, 接口和模式排列组合下, 多少种, 竟可不修改代码而适应。

    然而 ACE 毕竟嫩了点, 没过几年就失势了. 现在除了一些老程序员还在用, 新生代的程序员已经不再使用 ACE 了. 为什么呢? 陈硕在他的博客里说, ACE 过于复杂,甚至比它试图封装的对象更复杂,
    程序员是指望用你的如意宝贝去驾驭另外那三家宝贝的, 结果你比他们还难。ACE 犯了早期 C++ 库都会犯的一个错误,过度设计, 过度java化。所谓 java 化, 就是以对象代替接口, 以虚函数代替回调,以继承代替组合。以虚类代替模板。对象间关系错综复杂,牵一发而动全身。除了作者,已经无人能参与 ACE 的开发了。

    与此同时,C语言的回归却在背后悄然进行。C语言的复辟,带来了几个更为糟糕的替代品, libevent 和 libev,以及 乘着nodejs的盛行东风而来的 libuv。

  2. 原始的 libevent

    C语言有着顽强的生命力,当然,这并不是因为C语言有多好,在后续的章节了我们还会深入的探讨C++相对C的改进。C语言的顽强和人天生的懒惰和偏见是有一定关系的。这种惰性表现为随遇而安,表现为固执己见。 非要拼命的否定C++,固守 C , 对 C 的缺点视而不见,诋毁C++相对C的改进。固守的结果就是简陋原始的 libevent . 然而因为保守党巨大的人数优势, libevent 应其群众基础良好而获得了空前的广泛使用。

    libevent 就如名字所言,是一个异步事件框架。从 OS 那里获得事件, 然后派发。派发机制就是“回调函数”。异步异步,归根结底就是处理从操作系统获得的事件。iocp也好, epoll也罢,都只是用来获取事件的接口。libevent 去掉了ACE华而不实的包装,保留了异步事件,极大的简化了模型。不得不说软件工程是个糟糕的发明,从来都把简单问题复杂化。libevent把简单问题简单化,让异步网络编程反朴归真,应该来说,本是一个好库。

    然而 libevent 因为设计缺陷,例如使用全局变量,定时器无法处理时间跳变,诸如此类的设计缺陷导致了 libev 的出现。
    libev 就是为了克服libevent的缺陷而诞生的。然而,libev 就一定好了吗?

  3. 禁锢的 libev

    libev 带着对 libevent 的怨气出世了。 吸收了 libevent 的所有缺点,
    虽然承诺过改进。然而 libev 如何改进的了呢? libev 已经够原始了,向下改进还不如让人直接使用系统的 api, 向上改进,一是会导致和libevent的重叠,二是很快就碰到了 C 语言强加的禁锢。

    C 语言因其语法简陋简洁而著称。然而,缺乏必要的抽象能力,导致 C 语言编写异步程序,就如同安迪拿着小锤子琢开肖生克监狱的墙壁一样。能,但是要耗费巨大的精力和时间。
    编写异步程序, 最需要的2个抽象能力, 其一为协程,其二是函数对象,包括匿名函数对象, 也就是lambda。
    C统统没有。函数对象是实现闭包比不可少的,如果没有函数对象, 就只能通过携带 void* 指针的形式迂回完整,繁琐不说,还特别容易出错。程序里也到处充满了类型强转。到处是临时定义的类型,就为了传给 void* 使用。

    尽管C 有那么多缺点,然而 libev 还未来得及被C的缺点拖累,因为他不支持 IOCP. 于是 libuv 就出来给 libev 擦屁股了。 支持了 iocp 后的 libuv 就真的只有 C 本身的缺点了吗?

  4. 混乱的 libuv

    libuv 可以说是 C 语言的异步库所能达到的最高高度了。完完全全的触碰到了C语言的自身瓶颈,好在 libuv 只是 nodejs 的底层库,上层软件转移到 javascript 语言而逃避了 C 的禁锢。

    真的是这样的吗? libuv 自身还有什么缺点呢?

    开源社区avplayer的大拿jackarain曾经说过,一个网络库好不好,就看他有没有正确的处理 TCP 关闭, read write 实现的ui不对。
    libuv 很遗憾的是,不合格。libuv 的 uv_write 没有返回值,允许空回调。也就是忽略write错误。
    网络出错的情况下, libuv 的用户只能稀里糊涂的知道出错了, 至于错在哪?数据到底有没有发出去了? 一概不知道。
    把数据交给 uv_write 后,就是一笔糊涂账了,大概 TCP 不可靠的说法就是从这里传出来的吧。


ASIO 腾空出世

在地球最大的岛上,另一位少年开始拜读 ACE 的大作。那时候,没有 libuv 没有 libev 更没有 libevent . 有的只是 ACE.
然而这个南方小国的少年没有跟风陷入 ACE 崇拜,他以敏锐的目光察觉到了 ACE 的弊病。
ACE 哪里做的不好?又哪里是值得借鉴的?

少年在给 c++ 委员会写的一篇上书中说,Proactor 模型乃最优模型。而 Proactor 模型,乃 ACE 提出的 6 个模型之一。根据 IT 界赢者通吃律,一个优秀的网络库,只需要支持 Proactor 模型即可。
支持其他次优模型都是徒劳的。ACE 试图全盘通吃,犯了大忌。

少年在一次开发者大会的演讲上,再次透露,网络库不宜做成框架,而是要像系统的API那样,作为一个乐高积木。ACE 做成了一个框架,同样不妥。

你说了那么多 ACE 不好,有本事你弄个好的啊? 批评者向来都是这么理直气壮。
正如 ACE 的作者实践了 “纸上得来终觉浅 绝知此事要躬行” 一样,这位勇敢的少年也拿出了 ASIO, “实践出真知”,他如是说。

那还是 SARS 病毒肆虐的年代,几乎没有人注意到,今后颠覆C++的网络世界的 ASIO 悄然出世了。而他的父亲,还只是悉尼的学子。ASIO 并没有显赫的家庭背景,然而英雄不问出处,它注定将有不平凡的一生。

俗语有云,三岁看老。在 asio 才三岁的时候,它父亲就将 asio 引荐给了 c++ 委员会的老人们。上一次他们这么做的时候,他们接纳了 STL。
ASIO 最终被内定,然后放入 Boost 锻炼, 经过 Boost 十余的锻炼,ASIO 终于在 2017 年进入了 c++ 标准。

Proactor ? Why Proactor

在给 c++ 老人会的引荐信里,asio 爸爸仔细阐述了asio的设计抉择回答了围绕 asio 的设计提出的很多问题。
为什么 Proactor 会是最佳模型?

  • 跨平台 许多操作系统都有异步API,即便是没有异步API的Linux, 通过 epoll 也能模拟 Proactor 模式。
  • 支持回调函数组合 将一系列异步操作进行组合,封装成对外的一个异步调用。这个只有Proactor能做到,Reactor 做不到。意味着如果asio使用Reactor模式,就对不起他“库” 之名。
  • 相比 Reactor 可以实现 Zero-copy
  • 和线程解耦 长时间执行的过程总是有系统异步完成,应用程序无需为此开启线程

Proactor 也并非全无缺点,缺点就是内存占用比 Reactor 大。Proactor 需要先分配内存而后处理IO, 而 Reactor 是先等待 IO 而后分配内存。相对的Proactor却获得了Zero-copy好处。因为内存已经分配好了,因此操作系统可以将接受到的网络数据直接从网络接口拷贝到应用程序内存,而无需经过内核中转。
Proactor 模式需要一个 loop ,这个 loop asio 将其封装为 io_service.他不仅是 asio的核心,更是一切基于asio设计的程序的核心。

宇宙级异步核心

io_service 脱胎于 IO 但不仅用于 IO. Christopher Kohlhoff 在给委员会的另一份编号 N3747 的信上上说它是 宇宙级异步模型 Universal Asynchronous Model。在宇宙级异步模型里,一个异步操作由三部分构成

  1. 发起 按照 asio 的编码规范,所有的发起操作都使用 async_ 前缀,使用 async_动词 的形式作为函数名。
  2. 执行 异步过程在发起的时候被executor执行(系统可以是支持 AIO 的内核,不支持 AIO 的系统则是 aiso 用户层模拟)
  3. 完成并回调 在发起 async_* 操作的时候,总是携带一个回调的闭包。asio使用闭包作为异步事件完成的处理回调,没而不是C式的回调函数。asio的宇宙异步模型里,回调总是在执行 io_service::run 的线程里执行。asio绝不会在内部线程里调用回调。

在回调里发起新的异步操作,一轮套一轮。整个程序就围绕着 io_service::run 运转起来了。
io_service 不仅仅能用于异步 IO ,还可以用来投递任意闭包。实现作为线程池的功能。这一通用型异步模型彻底击败微软 PPL 提案,致使微软转而研究协程。然而微软在协程上同样面临 asio 的绞杀。

闭包和协程

宇宙级 asio 使用闭包作为回调,而 C 库只能使用函数+void*, ACE 虽然使用的 C++语言,却不知道闭包为何物,使用的是 虚函数作为回调。需要大量的从 ACE 的对象继承。以闭包为回调,asio更是支持了一种叫“无栈协程”的强悍武器。
asio的无栈协程,仅仅通过库的形式,不论是在性能上,还是易用性上,还是简洁性上,甚至是B格上,都超过了微软易于修改语言而得的 await提案。

微软,乃至 ACE ,并不是不知道闭包,而是在c++里实现闭包的宇宙级executor —— 也就是 io_service,需要对模板技术的精通。
asio “把困难留给自己,把方便带给大家”,以地球人无法理解的方式硬是在 c++98 上实现了宇宙级异步核心。
当然,如果 c++11 早点出现,如果 c++17 早点出现,实现 asio 的宇宙模型会更加的简单 —— 其实这也是 c++ 的理念,增加语言特性,只是为了让语言用起来更简单。

buffers

有了闭包的支持,内存管理也变得轻轻松松起来。
ASIO 本身并不管理内存,所有的IO操作,只提交对用户管理的内存的引用,称 Buffers。asio::buffers 引用了用户提交的内存,保持整个 IO 期间,这块内存的有效性是用户的责任。然而这并不难!
因为回调是一个闭包。通过闭包持有内存,只要 asio 还未回调,闭包就在,闭包在,内存在。asio 在调用完回调后才删除相应的闭包。因此资源管理的责任可以丢给闭包,而闭包可以通过智能指针精确的控制内存。
不是 GC , 胜于 GC 千百倍!益于c++的 RAII机制,再无内存泄漏之忧!

进入 ASIO 的世界

对 C++ 网络库的历史也介绍到差不多了,接下来的章节里,带你深入理解asio , 让你同时获得开发效率和执行效率。
一些在本章里,可能对许多人来说都是初次见到的技术,将在本书剩余章节里详细介绍。

翻开下一页,进入 ASIO 的世界,领略 C++ 的博大精深,享受网络遨游的快感吧!

如有侵权请版权方立即与我联系,我将及时删除

Android release: F libc : Fatal signal 7 (SIGBUS), code 1

qt for android release gcc

问题:

包含 store.lockfree.queue, 用 qt 5.5.1 编译 android release 版本的程序,在运行时就会出现:

F libc    : Fatal signal 7 (SIGBUS), code 1, fault addr 0x9da51154 in tid 25836 (.example.lproxy)
"org.qtproject.example.lproxy" died.

此时,程序尚未进入 qt.main 函数, 看来是全局区(静态区)出了问题。但是 编译 debug 版本的 android 程序,则运行正常,很奇怪的现象。其他平台:win32/linux 不管是 debug 还是 release 也都不会出现这个问题。

qt android release 的 gcc 编译指令示例:

D:\Qt\android\android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++  \
-c -Wno-psabi \
-march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums \
-DANDROID -Wa,--noexecstack -fno-builtin-memmove \
-std=c++11 -pthread -O2 -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb \ 
-Wall -Wno-psabi -W -D_REENTRANT -fPIC -DLOG_LOCKFREE_QUEUE -D_REENTRANT -DBOOST_REGEX_NO_LIB -DBOOST_DATE_TIME_SOURCE -DBOOST_SYSTEM_NO_LIB -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_WEBSOCKETS_LIB -DQT_NETWORK_LIB -DQT_WEBCHANNEL_LIB -DQT_CORE_LIB -I../lproxy-local-test -I. -I../lproxy-local-test/lproxy/contrib/boost/boost_1_57_0 -I../lproxy-local-test/lproxy/contrib/cryptopp -I../lproxy-local-test/lproxy/src/core -I../lproxy-local-test/lproxy/src/core/boost_build -ID:/Qt/QtDev/5.5/android_armv7/include -ID:/Qt/QtDev/5.5/android_armv7/include/QtQuick -ID:/Qt/QtDev/5.5/android_armv7/include/QtGui -ID:/Qt/QtDev/5.5/android_armv7/include/QtQml -ID:/Qt/QtDev/5.5/android_armv7/include/QtWebSockets -ID:/Qt/QtDev/5.5/android_armv7/include/QtNetwork -ID:/Qt/QtDev/5.5/android_armv7/include/QtWebChannel -ID:/Qt/QtDev/5.5/android_armv7/include/QtCore -I. -isystem D:/Qt/android/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem D:/Qt/android/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem D:/Qt/android/android-ndk-r10e/platforms/android-9/arch-arm/usr/include -ID:/Qt/QtDev/5.5/android_armv7/mkspecs/android-g++ -o websocketclientwrapper.obj ../lproxy-local-test/websocketchannel/websocketclientwrapper.cpp

debug 是没问题的:

D:\Qt\android\android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ \
-c -Wno-psabi \
-march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums \
-DANDROID -Wa,--noexecstack -fno-builtin-memmove \
-std=c++11 -pthread -g -g -marm -O0 -fno-omit-frame-pointer \
-Wall -Wno-psabi -W -D_REENTRANT -fPIC -DLOG_LOCKFREE_QUEUE -D_REENTRANT -DBOOST_REGEX_NO_LIB -DBOOST_DATE_TIME_SOURCE -DBOOST_SYSTEM_NO_LIB -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_WEBSOCKETS_LIB -DQT_NETWORK_LIB -DQT_WEBCHANNEL_LIB -DQT_CORE_LIB -I../lproxy-local-test -I. -I../lproxy-local-test/lproxy/contrib/boost/boost_1_57_0 -I../lproxy-local-test/lproxy/contrib/cryptopp -I../lproxy-local-test/lproxy/src/core -I../lproxy-local-test/lproxy/src/core/boost_build -ID:/Qt/QtDev/5.5/android_armv7/include -ID:/Qt/QtDev/5.5/android_armv7/include/QtQuick -ID:/Qt/QtDev/5.5/android_armv7/include/QtGui -ID:/Qt/QtDev/5.5/android_armv7/include/QtQml -ID:/Qt/QtDev/5.5/android_armv7/include/QtWebSockets -ID:/Qt/QtDev/5.5/android_armv7/include/QtNetwork -ID:/Qt/QtDev/5.5/android_armv7/include/QtWebChannel -ID:/Qt/QtDev/5.5/android_armv7/include/QtCore -I. -isystem D:/Qt/android/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem D:/Qt/android/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem D:/Qt/android/android-ndk-r10e/platforms/android-9/arch-arm/usr/include -ID:/Qt/QtDev/5.5/android_armv7/mkspecs/android-g++ -o webchannelobject.obj ../lproxy-local-test/webchannelobject/webchannelobject.cpp

release 和 debug 链接指令相同。

最终定位到问题代码 store.h

#include <boost/lockfree/queue.hpp>
template <typename T>
class Store<T, boost::lockfree::queue<T> > : 
        public boost::serialization::singleton<
                    Store<T, boost::lockfree::queue<T> > >,
        public boost::lockfree::queue<T> {
public:
    //using boost::lockfree::queue<T>::push;
    //using boost::lockfree::queue<T>::pop;
    typedef boost::lockfree::queue<T> BASETYPE;

    bool push(const T* element_ptr) {
        if (element_ptr) {
            return this->push(*element_ptr);
        }
        else {
            return false;
        }
    }
    bool push(const T& element) {
        return BASETYPE::push(element);
    }

    bool pop(T* element_ptr) {
        if (element_ptr) {
            return this->pop(*element_ptr);
        }
        else {
            return false;
        }
    }
    bool pop(T& element) {
        return BASETYPE::pop(element);
    }

    // 继承父类的reserve
    //void reserve(size_t);
    //void reserve_unsafe(size_t);
protected:
    Store(size_t _capacity = __STORECAPACITY__s) :
        boost::lockfree::queue<T>(_capacity) {}
    Store(const Store&) {}
private:
    // 屏蔽下面接口
    size_t size() const { return 0; }  
    bool full()   const { return false; }
};

对两个基类虚继承也照旧同一个问题。

gcc 版本

D:\Qt\android\android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ --version

arm-linux-androideabi-g++ (GCC) 4.9 20140827 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Android 版本:

Android 6.0 ABI:armeabi-v7a

解决办法:去掉 public boost::serialization::singleton<Store<T, boost::lockfree::queue<T> > > , 改用单继承。

更深层次的原因不详,有可能和 boost::serialization::singleton 有关,也可能和 boost::lockfree 有关,也可能和内存字节对齐有关。

mingw32 - cryptopp Segmentation fault: CryptoPP::Rijndael::Base::UncheckedSetKey { __m128i temp = _mm_loadu_si128((__m128i *)(void *)(userKey+keylen-16)); }

Program received signal SIGSEGV, Segmentation fault.
CryptoPP::Rijndael::Base::UncheckedSetKey (this=0x4b2c888,
    userKey=0x4b2c650 "u\033悡\b\t)'爯\251\341\aJ饅V颲\373\251+\t9紃\266\025鴥+\235\r\001\255\272\r\272 ", keylen=32)
    at rijndael.cpp:231
231                     __m128i temp = _mm_loadu_si128((__m128i *)(void *)(userKey+keylen-16));
(gdb) bt
#0  CryptoPP::Rijndael::Base::UncheckedSetKey (this=0x4b2c888,
    userKey=0x4b2c650 "u\033悡\b\t)'爯\251\341\aJ饅V颲\373\251+\t9紃\266\025+\235\r\001\255\272\r\272 ", keylen=32)
    at rijndael.cpp:231
#1  0x00428300 in CryptoPP::RandomPool::GenerateIntoBufferedTransformation (this=0x4b2c618, target=..., channel="", size=20)
    at randpool.cpp:40
#2  0x00420c0b in CryptoPP::RandomNumberGenerator::GenerateBlock (this=0x4b2c618,
    output=0x4b26c81 "瓠\272\r瓠\272\r瓠\272\r瓠\272\r\272\r\332\071^kK\r2U`\030\330\a\t", size=20) at cryptlib.cpp:339
#3  0x00448669 in CryptoPP::OAEP_Base::Pad (this=<optimized out>, rng=...,
    input=0x4b25ae8 "ABA369F7D2B28A9098A0A26FEB7DC9656326909417\253\253\253\253\253\253\253\253", inputLength=42,
    oaepBlock=0x4b26c81 "\272\r\272\r\272\r\272\r\272\r\332\071^kK\r2U`\030\330\a\t",
    oaepBlockLen=<optimized out>, parameters=...) at oaep.cpp:47
#4  0x0042ff55 in CryptoPP::TF_EncryptorBase::Encrypt (this=<optimized out>, rng=...,
    plaintext=0x4b25ae8 "ABA369F7D2B28A9098A0A26FEB7DC9656326909417\253\253\253\253\253\253\253\253",
    plaintextLength=42,
    ciphertext=0x4b25f20 "\r瓠\272\r瓠\272\r瓠\272\r瓠\272\r瓠\272\r瓠\272\r瓠\272\r瓠\272\r瓠\272\r瓠\272\r瓠\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\272\r\253\253\253\253", <incomplete sequence \253>, parameters=...) at pubkey.cpp:164
#5  0x004d631c in CryptoPP::PK_DefaultEncryptionFilter::Put2 (this=0x4b27fe8, inString=0x0, length=0, messageEnd=-1, blocking=true)
    at cryptlib.cpp:801
#6  0x004d27df in CryptoPP::BufferedTransformation::MessageEnd (this=0x4b27fe8, propagation=-1, blocking=true)
    at ../../../contrib/cryptopp/cryptopp/cryptlib.h:1437
#7  0x004c811c in CryptoPP::SimpleProxyFilter::LastPut (this=0x4b2ca30, inString=0x0, length=0)
    at ../../../contrib/cryptopp/cryptopp/filters.h:905
#8  0x0042615e in CryptoPP::FilterWithBufferedInput::PutMaybeModifiable (this=0x4b2ca30, inString=<optimized out>, length=0,
    messageEnd=-1, blocking=true, modifiable=false) at filters.cpp:437
#9  0x004d47cd in CryptoPP::FilterWithBufferedInput::Put2 (this=0x4b2ca30, inString=0x0, length=0, messageEnd=-1, blocking=true)
    at ../../../contrib/cryptopp/cryptopp/filters.h:339
#10 0x004204f7 in CryptoPP::BufferedTransformation::ChannelPut2 (this=<optimized out>, channel="", begin=0x0, length=0,
    messageEnd=-1, blocking=true) at cryptlib.cpp:470
---Type <return> to continue, or q <return> to quit---
#11 0x00420ea2 in ChannelMessageEnd (blocking=true, propagation=<optimized out>, channel="", this=0x4b2ca30) at cryptlib.h:1908
#12 CryptoPP::BufferedTransformation::TransferMessagesTo2 (this=0x606ef64, target=..., messageCount=@0x606edb8: 0, channel="",
    blocking=true) at cryptlib.cpp:627
#13 0x0042102a in CryptoPP::BufferedTransformation::TransferAllTo2 (this=0x606ef64, target=..., channel="", blocking=true)
    at cryptlib.cpp:668
#14 0x004bd44d in CryptoPP::SourceTemplate<CryptoPP::StringStore>::PumpAll2 (this=0x606ef4c, blocking=true)
    at ../../../contrib/cryptopp/cryptopp/filters.h:1222
#15 0x004e3283 in CryptoPP::Source::PumpAll (this=0x606ef4c) at ../../../contrib/cryptopp/cryptopp/filters.h:1166
#16 0x004e3256 in CryptoPP::Source::SourceInitialize (this=0x606ef4c, pumpAll=true, parameters=...)
    at ../../../contrib/cryptopp/cryptopp/filters.h:1199
#17 0x004b8a72 in CryptoPP::StringSource::StringSource (this=0x606ef4c,
    string=0x4b2c4b4 "ABA369F7D2B28A9098A0A26FEB7DC9656326909417", length=42, pumpAll=true, attachment=0x4b2ca30)
    at ../../../contrib/cryptopp/cryptopp/filters.h:1252
#18 0x0041ddec in crypto::Rsa::encrypt (this=0x4b2c4f8, dest=std::vector of length 0, capacity 0,
    src=0x4b2c4b4 "ABA369F7D2B28A9098A0A26FEB7DC9656326909417", src_len=42) at rsa_crypto.cpp:135
#19 0x0041e5a4 in crypto::Encryptor::encrypt (this=0x606f050, dest=std::vector of length 0, capacity 0,
    src=0x4b2c4b4 "ABA369F7D2B28A9098A0A26FEB7DC9656326909417", src_len=42) at encryptor.cpp:27
#20 0x0040dbff in lproxy::local::session::pack_exchange (this=0x4b25bfc, keysize=@0x606f1ea: 1024,
    public_key="30819D300D06092A864886F70D010101050003818B00308187028181009B7CA78876C3CAA5879C1761730E7D8139A63662DC9E7752DF369BDBB28A168EF61F884709FCE3C71D9582984CB57ED6D36060E556C52433ECDFA1C766CDCF6BABCF40B3BE15D0"...) at session_local.cpp:575
#21 0x004079ad in lproxy::local::session::right_read_handler (this=0x4b25bfc, error=..., bytes_transferred=326,
    lss_reply=std::shared_ptr (count 3, weak 0) 0x4b272c4, __data_right_rest=std::shared_ptr (count 7, weak 0) 0x4b25034,
    __write_data=std::shared_ptr (count 7, weak 0) 0x4b25034) at session_local.cpp:253
#22 0x004edaf1 in boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >::call<std::shared_ptr<lproxy::local::session>, boost::system::error_code const, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > (this=0x606fad4,
---Type <return> to continue, or q <return> to quit---
    u=std::shared_ptr (count 1, weak 1) 0x4b25bfc, b1=..., b2=@0x606f9ac: 326, b3=std::shared_ptr (count 3, weak 0) 0x4b272c4,
    b4=std::shared_ptr (count 7, weak 0) 0x4b25034, b5=std::shared_ptr (count 7, weak 0) 0x4b25034)
    at ../../../contrib/boost/boost_1_57_0/boost/bind/mem_fn_template.hpp:610
#23 0x004edb92 in boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >::operator()<std::shared_ptr<lproxy::local::session> > (this=0x606fad4, u=std::shared_ptr (count 1, weak 1) 0x4b25bfc, a1=..., a2=326,
    a3=std::shared_ptr (count 3, weak 0) 0x4b272c4, a4=std::shared_ptr (count 7, weak 0) 0x4b25034,
    a5=std::shared_ptr (count 7, weak 0) 0x4b25034) at ../../../contrib/boost/boost_1_57_0/boost/bind/mem_fn_template.hpp:625
#24 0x0048bead in boost::_bi::list6<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<lproxy::local::reply> >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > >::operator()<boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list2<boost::system::error_code const&, unsigned int const&> > (
    this=0x606fadc, f=..., a=...) at ../../../contrib/boost/boost_1_57_0/boost/bind/bind.hpp:596
#25 0x0048cc38 in boost::_bi::bind_t<void, boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list6<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<lproxy::local::reply> >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > >::operator()<boost::system::error_code, unsigned int> (this=0x606fad4,
    a1=..., a2=@0x606fb04: 326) at ../../../contrib/boost/boost_1_57_0/boost/bind/bind_template.hpp:102
#26 0x004a0122 in boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list6<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<---Type <return> to continue, or q <return> to quit---
1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<lproxy::local::reply> >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > >, boost::system::error_code, unsigned int>::operator() (this=0x606fad4) at ../../../contrib/boost/boost_1_57_0/boost/asio/detail/bind_handler.hpp:127
#27 0x0048fbae in boost::asio::asio_handler_invoke<boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list6<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<lproxy::local::reply> >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > >, boost::system::error_code, unsigned int> > (function=...) at ../../../contrib/boost/boost_1_57_0/boost/asio/handler_invoke_hook.hpp:69
#28 0x0047be48 in boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list6<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<lproxy::local::reply> >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > >, boost::system::error_code, unsigned int>, boost::_bi::bind_t<void, boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list6<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<lproxy::local::reply> >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > > > (function=..., context=...)
    at ../../../contrib/boost/boost_1_57_0/boost/asio/detail/handler_invoke_helpers.hpp:37
#29 0x0049b5e0 in boost::asio::detail::win_iocp_socket_recv_op<boost::array<boost::asio::mutable_buffer, 5u>, boost::_bi::bind_t<void, boost::_mfi::mf5<void, lproxy::local::session, boost::system::error_code const&, unsigned int, std::shared_ptr<lproxy::local::reply---Type <return> to continue, or q <return> to quit---
>, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > >, std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::list6<boost::_bi::value<std::shared_ptr<lproxy::local::session> >, boost::arg<1>, boost::arg<2>, boost::_bi::value<std::shared_ptr<lproxy::local::reply> >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > >, boost::_bi::value<std::shared_ptr<std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> > > > > > >::do_complete (owner=0x4b25b78, base=0x4b26e58, result_ec=..., bytes_transferred=326)
    at ../../../contrib/boost/boost_1_57_0/boost/asio/detail/win_iocp_socket_recv_op.hpp:97
#30 0x00498ea4 in boost::asio::detail::win_iocp_operation::complete (this=0x4b26e58, owner=..., ec=..., bytes_transferred=326)
    at ../../../contrib/boost/boost_1_57_0/boost/asio/detail/win_iocp_operation.hpp:46
#31 0x0049a0e1 in boost::asio::detail::win_iocp_io_service::do_one (this=0x4b25b78, block=true, ec=...)
    at ../../../contrib/boost/boost_1_57_0/boost/asio/detail/impl/win_iocp_io_service.ipp:405
#32 0x00499afc in boost::asio::detail::win_iocp_io_service::run (this=0x4b25b78, ec=...)
    at ../../../contrib/boost/boost_1_57_0/boost/asio/detail/impl/win_iocp_io_service.ipp:164
#33 0x0048e29e in boost::asio::io_service::run (
    this=0x559558 <lproxy::lss_server<lproxy::local::session>::io_service_right()::io_service>)
    at ../../../contrib/boost/boost_1_57_0/boost/asio/impl/io_service.ipp:59
#34 0x004b0ba2 in lproxy::lss_server<lproxy::local::session>::handle_thread_right (io_service=...)
    at ../../../src/core/lss/lss_server.h:109
#35 0x0051db02 in std::_Bind_simple<void (*(std::reference_wrapper<boost::asio::io_service>))(boost::asio::io_service&)>::_M_invoke<0u>(std::_Index_tuple<0u>) (this=0x4b25a80) at D:/Qt/QtDev/Tools/mingw492_32/i686-w64-mingw32/include/c++/functional:1700
#36 0x0051db82 in std::_Bind_simple<void (*(std::reference_wrapper<boost::asio::io_service>))(boost::asio::io_service&)>::operator()() (this=0x4b25a80) at D:/Qt/QtDev/Tools/mingw492_32/i686-w64-mingw32/include/c++/functional:1688
#37 0x0052b5ee in std::thread::_Impl<std::_Bind_simple<void (*(std::reference_wrapper<boost::asio::io_service>))(boost::asio::io_service&)> >::_M_run() (this=0x4b25a74) at D:/Qt/QtDev/Tools/mingw492_32/i686-w64-mingw32/include/c++/thread:115
#38 0x6fcb8c4f in libstdc++-6!execute_native_thread_routine () from D:\Qt\QtDev\5.5\mingw492_32\bin\libstdc++-6.dll
#39 0x64944f11 in pthread_create_wrapper () from D:\Qt\QtDev\Tools\mingw492_32\opt\bin\libwinpthread-1.dll
#40 0x749771e6 in msvcrt!_beginthreadex () from C:\WINDOWS\SYSTEM32\msvcrt.dll
#41 0x749772b1 in msvcrt!_endthreadex () from C:\WINDOWS\SYSTEM32\msvcrt.dll
#42 0x747f38f4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\SYSTEM32\kernel32.dll
#43 0x775f5de3 in ntdll!RtlUnicodeStringToInteger () from C:\WINDOWS\SYSTEM32\ntdll.dll
#44 0x04b26560 in ?? ()
#45 0x775f5dae in ntdll!RtlUnicodeStringToInteger () from C:\WINDOWS\SYSTEM32\ntdll.dll
#46 0xffffffff in ?? ()
#47 0x7761b7ea in ntdll!RtlCaptureContext () from C:\WINDOWS\SYSTEM32\ntdll.dll
#48 0x00000000 in ?? ()
// 组装 exchange
const request session::pack_exchange(const keysize_t& keysize, 
        const data_t& public_key) {


{
    std::string k = "30819D300D06092A864886F70D010101050003818B00308187028181009EFD7A5CFBF51D88C6F98588BBBCA26A6FB4E35657094E024B6CE79582EFE6DCCCE8954D416BBD57D4DC0B81320FD97DBCBB7CAE8BFB4B3827AC99210E15EC9062C32E7337905B92866A93E689A8E9940148DB08C5964CEF0272C16CFBB8A2E403A5DB4DD142280E8C3FCD1165FCB043C256AE0A951F4E3C8153E6891DD31EED020111";

    using namespace crypto;
    std::string p = "ABA369F7D2B28A9098A0A26FEB7DC9656326909417";
    Encryptor e_test(new Rsa(RsaKey::bit1024, (const uint8_t*)&k[0], k.size()));
    std::vector<uint8_t> cip;
    e_test.encrypt(cip, (const uint8_t*)&p[0], p.size());
    std::string msg = _debug_format_data(cip, int(), ' ', std::hex);
    std::cout << msg << std::endl;
}
...

但是在 test 用例中同样的的代码就没问题:

void test() {

    std::cout << "\n\n``````````````````````````````````````\n\n\n";
    std::string k = "30819D300D06092A864886F70D010101050003818B00308187028181009EFD7A5CFBF51D88C6F98588BBBCA26A6FB4E35657094E024B6CE79582EFE6DCCCE8954D416BBD57D4DC0B81320FD97DBCBB7CAE8BFB4B3827AC99210E15EC9062C32E7337905B92866A93E689A8E9940148DB08C5964CEF0272C16CFBB8A2E403A5DB4DD142280E8C3FCD1165FCB043C256AE0A951F4E3C8153E6891DD31EED020111";
    std::string p = "ABA369F7D2B28A9098A0A26FEB7DC9656326909417";
    Encryptor e_test(new Rsa(RsaKey::bit1024, (const uint8_t*)&k[0], k.size()));
    std::vector<uint8_t> cip;
    e_test.encrypt(cip, (const uint8_t*)&p[0], p.size());
    print_hex(cip, cip.size());
    std::cout << "\n\n``````````````````````````````````````\n\n\n";
}

repo 拆分

各个模块 static_analysis log logrotate crypto store language python ...

每一个都能分离出去,当做一个独立的 repo。

因为,绝大多数模块是按照 library 目标设计的,独立出去的好处是被其他 repo 引用时,就不用 引用一个完整的 lproxy. 比如,现在的 DD-L/MySecrect 只是用到了 crypto, 以及 contribtools 中的一部分, 就得 引用 整个 大的 lproxy, 是不合理的。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.