標題是我的問題。Boost Asio如何讀取/寫入不使用SSL的SSL套接字?
我已經發現了與此相關的話題在這裏 - >Using SSL sockets and non-SSL sockets simultaneously in Boost.Asio?
,基本上我在同樣的情況,但由於某種原因,我不能發表評論,有和/或諮詢提問直接,所以我這樣做作爲一個新問題。
我有一個設置SSL插座ssl::stream<ip::tcp::socket> socket_;
,在這裏客戶可以與
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的連接。所有的
首先我不確定該怎麼辦了「握手」,因爲它與SSL連接正如我上面提到完成。
通過查看一些正常的boost.asio示例,我假設我不需要爲非ssl連接執行此操作,並且只需在它被接受後直接讀取/寫入套接字?
然後作爲下一步我試圖做到這一點正如我上面提到的話題decsribed,我加了一個布爾SSL會話,以檢查其是否SSL連接或沒有。
然後,我使用socket_.lowest_layer()
而不是在異步函數中使用socket_
。
這裏的推薦代碼:
if (sslEnabled)
boost::asio::async_write(secureSocket_);
} else {
boost::asio::async_write(secureSocket_.lowest_layer());
}
但是似乎編譯犯規接受這個解決方案。當我嘗試使用具有socket_.lowest_layer()作爲流這個錯誤顯示了一個異步函數編譯代碼(其只對async_read,ASYNC_WRITE也有類似的一個):
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.
所以我現在幾乎卡住了,我真的希望你能幫助我。搜索帶來的誤差高達不信邪,因爲按理說應該有工作,我不知道這個錯誤可能是什麼...