SOCKET_CLIENT_TLS_HANDSHAKING: connection is NOT a TlsClientConnection
According to the documentation for Gio::SocketClient signal_event()
:
void on_my_event(SocketClientEvent event, const Glib::RefPtr& connectable, const Glib::RefPtr& connection) [...]
The meanings of the different event values are as follows: [...]
SOCKET_CLIENT_TLS_HANDSHAKING: client is about to begin a TLS handshake. connection is a TlsClientConnection.
Code example:
Glib::RefPtr<Gio::SocketClient> client = Gio::SocketClient::create();
client->set_tls(true);
client->signal_event().connect([](Gio::SocketClientEvent event, const Glib::RefPtr<Gio::SocketConnectable> &dst, const Glib::RefPtr<Gio::IOStream> &stream) {
if (event == Gio::SOCKET_CLIENT_TLS_HANDSHAKING) {
#if 0
Glib::RefPtr<Gio::TlsClientConnection> tcc = Glib::RefPtr<Gio::TlsClientConnection>::cast_dynamic(stream); // (segfault with cast_static)
assert(tcc); // FAILS!
printf("TLS handshaking with: %s\n", tcc->get_server_identity()->to_string().c_str());
#else
Glib::RefPtr<Gio::TlsConnection> tcc = Glib::RefPtr<Gio::TlsConnection>::cast_static(stream); // WORKS.
assert(tcc);
GTlsClientConnection *gtc = (GTlsClientConnection *)tcc->gobj();
GSocketConnectable *gsc = g_tls_client_connection_get_server_identity(gtc); //
WORKS!
gchar *gc = g_socket_connectable_to_string(gsc);
printf("TLS handshaking with: %s\n", gc);
g_free(gc);
#endif
}
});
Glib::RefPtr<Gio::SocketConnection> conn = client->connect_to_host("google.com", 443);
-> it works with gio, but it doesn't with giomm.