efl_net_dialer_socket: allow us to create a dialer from existing object.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Thu, 8 Dec 2016 20:57:04 +0000 (18:57 -0200)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 9 Dec 2016 15:47:04 +0000 (13:47 -0200)
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.

src/lib/ecore_con/efl_net_dialer_ssl.c
src/lib/ecore_con/efl_net_socket_ssl.c
src/lib/ecore_con/efl_net_socket_ssl.eo

index f85274c..453486b 100644 (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));
 }
 
index 492fe7b..c776ad4 100644 (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)
 {
index f32362a..b9ea98f 100644 (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 {