I'am currently exploring the Asio library and have working code for regular TCP connections. I used asio::ip::tcp::iostream
objects since stuff I want to transmit already can serialize to/deserialize from iostreams, so this was really handy and worked well for me.
I then tried to switch to SSL connections and that's when everything turned crazy. There is apparently no built-in support to get the same iostream interface that all other protocols support for a secured connection. From a design perspective this is really perplexing to me. Is there any reason why this is the case?
I am aware of the discussion in How to create a boost ssl iostream? which concludes with a wrapper class to provide iostream functionality using boost. Apart from that, according to a comment, the implementation is flawed, this also does not give the same interface as for the other protocols (a basic_socket_iostream
) which also allows to e.g., set expiration times and close the connection. (I am also using asio in the non-boost version and want to avoid adding boost as an additional dependency if possible).
So, I guess my questions are:
- What exactly would I need to implement to get a basic_socket_iostream for an SSL connection? I assume it would be a derivation of
asio::basic_streambuf
orasio::basic_socket_streambuf
but I somehow can't figure out how they work and need to be tweaked.. there's just a bunch of weird pointer movement and buffer allocations and documentation to me is quite unclear on what happens when exactly to achieve what... - Why is this not already present in the first place? It seems very unreasonable to have this one protocol behave entirely different from any other and thus require major refactoring for changing a
tcp::iostream
based project to support secured connections
ssl::stream<socket>
defines a stream over a socket, not a "socket adaptor" – Hudgensssl::stream<socket>
really does neither: I doesn't give a socket but it also doesn't give me a stream interface that would be compatible to those available from the other protocols and, yes, in that sense it behaves very differently from the others (for no apparent reason). I think I can see where your argument is coming from (ssl being built on another protocol/socket and not doing connection itself), but the same could be said about any other higher-level protocol (e.g. tcp) and good design would provide an agnostic interface for communication. – Exorable