升压短耳如何阅读,这并不使用SSL一个SSL插座/写? [英] Boost Asio how to read/write on a SSL socket that doesnt use SSL?

查看:155
本文介绍了升压短耳如何阅读,这并不使用SSL一个SSL插座/写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题是我的问题。

我已经找到与此相关的这里主题 - > <一个href=\"http://stackoverflow.com/questions/4720120/using-ssl-sockets-and-non-ssl-sockets-simultaneously-in-boost-asio\">Using SSL套接字和非SSL套接字同时在Boost.Asio的?结果
基本上我在同样的情况,但由于某种原因,我不能有意见和/或直接接触,所以我这样做,作为一个新的问题提问。

I already found a topic related to this here -> Using SSL sockets and non-SSL sockets simultaneously in Boost.Asio?
and basically I'm in the same situation but for some reason I couldn't comment there and/or contact the questioner directly so I'm doing this as a new question.

我有一个设置SSL插座 SSL ::流&LT; IP :: TCP ::插座&GT;插座_; ,其中客户端可以与连接就好了。

I have a set up ssl socket ssl::stream<ip::tcp::socket> socket_; where clients can connect just fine with

socket_.async_handshake(ssl::stream_base::server, session::handle_handshake)

,然后读/

async_write(socket_, buffer(send_data, send_length), session::handle_read)
socket_.async_read_some(buffer(recieved_data, max_length), session::handle_read)

但现在我想使用相同类型的插槽,建立了不使用SSL连接。

However now I want to use the same type of socket to build up connections that dont use SSL.

所有我不确定该怎么做了握手,因为它是用SSL连接正如我上面提到做的第一。结果通过查看一些正常的Boost.Asio的例子,我认为我没有这样做,对于非SSL连接,只需直接一旦被接受读/写的socket?

First of all I'm unsure how to do the "handshaking" as it is done with a SSL connection as I mentioned above.
By looking at some normal boost.asio example I assume that I dont have to do that for non-ssl connections and just directly read/write to the socket once it has been accepted?

然后作为下一步我试图做到这一点正如我上面提到的话题decsribed,我添加了一个布尔SSL会话,检查其是否SSL连接或没有。结果这时,而不是使用插座_ 中的异步功能,我使用了 socket_.lowest_layer()

Then as a next step I tried to do it as decsribed in the topic I mentioned above, I added a boolean ssl to session to check whether its a SSL connection or not.
Then instead of using socket_ in the async functions, I used socket_.lowest_layer().

下面是建议code:

if ( sslEnabled )
    boost::asio::async_write( secureSocket_ );
} else {
    boost::asio::async_write( secureSocket_.lowest_layer() );
}

但是它似乎是编译犯规接受该溶液中。当我尝试编译code与具有socket_.lowest_layer()作为流这个错误显示了一个异步函数(其只对async_read,async_write也有类似的一个):

However it seems that the compiler doesnt accept this solution. When I try to compile the code with an async function that has socket_.lowest_layer() as a stream this error shows up (its only for async_read, async_write has a similar one):

boost\asio\impl\read.hpp(263): error C2039: 'async_read_some' : is not a member of 'boost::asio::basic_socket<Protocol,SocketService>'
          with
          [
              Protocol=boost::asio::ip::tcp,
              SocketService=boost::asio::stream_socket_service<boost::asio::ip::tcp>
          ]
          boost\asio\impl\read.hpp(255) : while compiling class template member function 'void boost::asio::detail::read_op<AsyncReadStream,MutableBufferSequence,CompletionCondition,ReadHandler>::operator ()(const boost::system::error_code &,size_t,int)'
          with
          [
            AsyncReadStream=boost::asio::basic_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>>,
              MutableBufferSequence=boost::asio::mutable_buffers_1,
              CompletionCondition=boost::asio::detail::transfer_all_t,
              ReadHandler=boost::_bi::bind_t<void,boost::_mfi::mf2<void,CSocket,const boost::system::error_code &,size_t>,boost::_bi::list3<boost::_bi::value<CSocket *>,boost::arg<1>,boost::arg<2>>>
          ]
          boost\asio\impl\read.hpp(527) : see reference to class template instantiation 'boost::asio::detail::read_op<AsyncReadStream,MutableBufferSequence,CompletionCondition,ReadHandler>' being compiled
          with
          [
              AsyncReadStream=boost::asio::basic_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>>,
              MutableBufferSequence=boost::asio::mutable_buffers_1,
              CompletionCondition=boost::asio::detail::transfer_all_t,
              ReadHandler=boost::_bi::bind_t<void,boost::_mfi::mf2<void,CSocket,const boost::system::error_code &,size_t>,boost::_bi::list3<boost::_bi::value<CSocket *>,boost::arg<1>,boost::arg<2>>>
          ]
          c:\asio_test\source\server.cpp(131) : see reference to function template instantiation 'void boost::asio::async_read<boost::asio::basic_socket<Protocol,SocketService>,boost::asio::mutable_buffers_1,boost::_bi::bind_t<R,F,L>>(AsyncReadStream &,const MutableBufferSequence &,const ReadHandler &)' being compiled
          with
          [
              Protocol=boost::asio::ip::tcp,
              SocketService=boost::asio::stream_socket_service<boost::asio::ip::tcp>,
              R=void,
              F=boost::_mfi::mf2<void,CSocket,const boost::system::error_code &,size_t>,
              L=boost::_bi::list3<boost::_bi::value<CSocket *>,boost::arg<1>,boost::arg<2>>,
              AsyncReadStream=boost::asio::basic_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>>,
              MutableBufferSequence=boost::asio::mutable_buffers_1,
              ReadHandler=boost::_bi::bind_t<void,boost::_mfi::mf2<void,CSocket,const boost::system::error_code &,size_t>,boost::_bi::list3<boost::_bi::value<CSocket *>,boost::arg<1>,boost::arg<2>>>
          ]

Build FAILED.

所以我现在pretty多卡住,我真的希望你能帮助我。搜索错误长大不信邪,因为它应该按说工作,我不知道这个错误可能是什么...

So now I'm pretty much stuck and I really hope you can help me. Searching for the error brought up nothing and since it should supposedly work I dont know what the mistake could be...

推荐答案

其实我觉得我现在解决了。

Actually I think I solved it now.

1)非SSL的握手的确是没有必要的,我马上做async_reading后接受

1) The "handshaking" on a non-ssl is indeed not necessary, I immediately do async_reading after the accept

2),而不是 async_read /写(socket_.lowest_layer(),...)我不得不使用 socket_.next_layer()。 async_read_some(缓冲,处理器)和结果 async_write(socket_.next_layer(),...)

2) Instead of async_read/write( socket_.lowest_layer(), ... ) I had to use socket_.next_layer().async_read_some( buffer, handler) and
async_write( socket_.next_layer(), ... )

我仍然不知道为什么它不与socket_.lowest_layer工作()(如果有人知道,请解释),但至少它的工作原理只是上述方法的罚款。我希望这将帮助其他人有类似的问题太多; - )

I still dont know why it doesnt work with socket_.lowest_layer() (if someone knows, please explain) but at least it works just fine with the above methods. And I hope this will help other people with a similar problem too ;-)

这篇关于升压短耳如何阅读,这并不使用SSL一个SSL插座/写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆