Hi all I have a set up asio SSL socket
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_
and the connection to a client that uses SSL works just fine.
But now I would like to use the class also for non-ssl connections, I already did some research about this and found someone with pretty much the same problem ->
http://stackoverflow.com/questions/4720120/using-ssl-sockets-and-non-ssl-sockets-simultaneously-in-boost-asio
As suggested in the first answer I tried to differentiate between ssl and non-ssl simply by using a boolean that goes true/false when a connection is coming in (I listen on two parts, one os only for ssl the other only for non-ssl)
However the suggested solution doesnt seem to work (for both async_read and async_write), here's how I call read/write for SSL connections:
1 2
|
socket_.async_read_some(buffer(recieved_data, max_length), boost::bind(&session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
async_write(socket_, buffer(send_data, send_length), boost::bind(&session::handle_write, this, boost::asio::placeholders::error));
|
And here are the changed calls as described in the answer (actually
socket_
is just replaced by
socket_.lowest_layer()
:
1 2
|
async_read(socket_.lowest_layer(), buffer(recieved_data, max_length), boost::bind(&session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
async_write(socket_.lowest_layer(), buffer(send_data, send_length), boost::bind(&session::handle_write, this, boost::asio::placeholders::error));
|
And this is what I get when I try to compile the code with the above non-ssl functions:
boost_1_48_0\boost\asio\impl\write.hpp(250): error C2039: 'async_write_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_1_48_0\boost\asio\impl\write.hpp(242) : while compiling class template member function 'void boost::asio::detail::write_op<AsyncWriteStream,ConstBufferSequence,CompletionCondition,WriteHandler>::operator ()(const boost::system::error_code &,size_t,int)'
... |
The error is longer but since the formatting would look quite horrible if I just copy/paste the whole thing in here, I'll just post the first part. If you need the complete build log please say so.
I honestly have no idea what the error means or how to fix it, I guess simply calling socket_lowest_layer() is not the right solution but I have no idea how it would work otherwise.