efl_net_dialer_socket: allow us to create a dialer from existing object.

If we want to upgrade a dialer, then we must have a way to know if
that socket has already adopted another socket so we don't create it.

We can't simply use efl_net_socket_ssl, otherwise we'd miss some
methods such as efl_net_dialer_address_dial_get() and events such as
connected.
This commit is contained in:
Gustavo Sverzut Barbieri 2016-12-08 18:57:04 -02:00
parent 3fc0fbba42
commit 9e682774d2
3 changed files with 35 additions and 3 deletions

View File

@ -1,4 +1,5 @@
#define EFL_NET_DIALER_SSL_PROTECTED 1
#define EFL_NET_SOCKET_SSL_PROTECTED 1
#define EFL_NET_DIALER_PROTECTED 1
#define EFL_NET_SOCKET_PROTECTED 1
#define EFL_IO_READER_PROTECTED 1
@ -73,10 +74,22 @@ _efl_net_dialer_ssl_efl_object_constructor(Eo *o, Efl_Net_Dialer_Ssl_Data *pd)
EOLIAN static Eo*
_efl_net_dialer_ssl_efl_object_finalize(Eo *o, Efl_Net_Dialer_Ssl_Data *pd)
{
if (!pd->ssl_ctx)
pd->ssl_ctx = efl_ref(efl_net_ssl_context_default_dialer_get(EFL_NET_SSL_CONTEXT_CLASS));
Eo *a_sock, *a_ctx;
if (efl_net_socket_ssl_adopted_get(o, &a_sock, &a_ctx))
{
efl_del(pd->sock); /* stub TCP we created */
pd->sock = a_sock;
pd->ssl_ctx = a_ctx;
}
else
{
if (!pd->ssl_ctx)
pd->ssl_ctx = efl_ref(efl_net_ssl_context_default_dialer_get(EFL_NET_SSL_CONTEXT_CLASS));
efl_net_socket_ssl_adopt(o, pd->sock, pd->ssl_ctx);
}
efl_net_socket_ssl_adopt(o, pd->sock, pd->ssl_ctx);
return efl_finalize(efl_super(o, MY_CLASS));
}

View File

@ -319,6 +319,14 @@ _efl_net_socket_ssl_adopt(Eo *o, Efl_Net_Socket_Ssl_Data *pd, Efl_Net_Socket *so
efl_event_callback_call(o, EFL_IO_CLOSER_EVENT_CLOSED, NULL);
}
EOLIAN static Eina_Bool
_efl_net_socket_ssl_adopted_get(Eo *o EINA_UNUSED, Efl_Net_Socket_Ssl_Data *pd, Efl_Net_Socket **sock, Efl_Net_Ssl_Context **context)
{
if (sock) *sock = pd->sock;
if (context) *context = pd->context;
return !!pd->sock;
}
static Efl_Net_Ssl_Verify_Mode
_efl_net_socket_ssl_verify_mode_get(Eo *o EINA_UNUSED, Efl_Net_Socket_Ssl_Data *pd)
{

View File

@ -33,6 +33,17 @@ class Efl.Net.Socket.Ssl (Efl.Loop_User, Efl.Net.Socket) {
}
}
@property adopted @protected {
[[Return the adopted object, if any. Be careful!]]
get {
return: bool(false); [[$true if adopted, $false otherwise]]
}
values {
efl_net_socket: Efl.Net.Socket; [[The adopted object, if any, otherwise NULL]]
ctx: Efl.Net.Ssl.Context; [[The SSL context used when adopting the socket, if any, otherwise NULL]]
}
}
@property verify_mode {
[[How to verify the remote peer.]]
values {