Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_con


Modified Files:
        ecore_con.c ecore_con_dns.c 


Log Message:


a bit of work to make dns lookups happen in a forked child - the dns protocol
stuff, though nice and cool, is having problems with multiple listing returns
and more with segv's, so this is the fastest/easiest fix right now - all the
old code is still there.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_con/ecore_con.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -3 -r1.57 -r1.58
--- ecore_con.c 11 Jan 2006 05:13:23 -0000      1.57
+++ ecore_con.c 19 Jan 2006 09:11:30 -0000      1.58
@@ -66,6 +66,7 @@
 {
    if (++init_count != 1) return init_count;
 
+   ecore_init();
    ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
    ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
    ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
@@ -99,6 +100,8 @@
 
    ecore_con_dns_shutdown();
 
+   ecore_shutdown();
+   
    return init_count;
 }
 
@@ -450,7 +453,10 @@
    ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);   
 
    if (type == ECORE_CON_REMOTE_SYSTEM)
-     ecore_con_dns_lookup(svr->name, _ecore_con_cb_dns_lookup, svr);
+     {
+       if (!ecore_con_dns_lookup(svr->name, _ecore_con_cb_dns_lookup, svr))
+         goto error;
+     }
 
    return svr;
    
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_con/ecore_con_dns.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- ecore_con_dns.c     7 Sep 2005 08:58:07 -0000       1.21
+++ ecore_con_dns.c     19 Jan 2006 09:11:30 -0000      1.22
@@ -104,6 +104,10 @@
 int
 ecore_con_dns_init(void)
 {
+#if 1   
+   dns_init++;
+   return dns_init;
+#else
    FILE *file;
    char buf[1024];
    char *p, *p2;
@@ -218,11 +222,16 @@
      }
 
    return dns_init;
+#endif   
 }
 
 int
 ecore_con_dns_shutdown(void)
 {
+#if 1
+   dns_init--;
+   return  dns_init;
+#else   
    Ecore_List2 *l;
    int i;
 
@@ -248,13 +257,140 @@
    search_count = 0;
 
    return dns_init;
+#endif   
+}
+
+#if 1
+typedef struct _CB_Data CB_Data;
+
+struct _CB_Data
+{
+   void (*cb_done) (void *data, struct hostent *hostent);
+   void *data;
+   Ecore_Fd_Handler *fdh;
+   pid_t pid;
+   Ecore_Event_Handler *handler;
+};
+
+static void
+_ecore_con_dns_readdata(CB_Data *cbdata)
+{
+   struct hostent he;
+   struct in_addr addr;
+   char *addr2;
+   ssize_t size;
+   
+   size = read(ecore_main_fd_handler_fd_get(cbdata->fdh), &(addr.s_addr),
+              sizeof(in_addr_t));
+   if (size == sizeof(in_addr_t))
+     {
+       addr2 = (char *)&addr;
+       he.h_addrtype = AF_INET;
+       he.h_length = sizeof(in_addr_t);
+       he.h_addr_list = &addr2;
+       cbdata->cb_done(cbdata->data, &he);
+     }
+   else
+     cbdata->cb_done(cbdata->data, NULL);
+   cbdata->cb_done = NULL;
+}
+
+static int
+_ecore_con_dns_data_handler(void *data, Ecore_Fd_Handler *fd_handler)
+{
+   CB_Data *cbdata;
+
+   cbdata = data;
+   if (cbdata->cb_done)
+     {
+       if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
+         _ecore_con_dns_readdata(cbdata);
+       else
+         {
+            cbdata->cb_done(cbdata->data, NULL);
+            cbdata->cb_done = NULL;
+         }
+     }
+   return 1;
 }
 
+static int
+_ecore_con_dns_exit_handler(void *data, int type, void *event)
+{
+   CB_Data *cbdata;
+   Ecore_Exe_Event_Del *ev;
+   
+   ev = event;
+   cbdata = data;
+   if (cbdata->pid != ev->pid) return 1;
+   close(ecore_main_fd_handler_fd_get(cbdata->fdh));
+   ecore_main_fd_handler_del(cbdata->fdh);
+   ecore_event_handler_del(cbdata->handler);
+   free(cbdata);
+   return 0;
+}
+#else
+#endif
+
 int
 ecore_con_dns_lookup(const char *name,
-                    void (*done_cb)(void *data, struct hostent *hostent),
+                    void (*done_cb) (void *data, struct hostent *hostent),
                     void *data)
 {
+#if 1
+   CB_Data *cbdata;
+   int fd[2];
+   
+   /* FIXME: set up one-way pipe back to parent and fdhandler */
+   if (pipe(fd) < 0) return 0;
+   cbdata = calloc(1, sizeof(CB_Data));
+   if (!cbdata)
+     {
+       close(fd[0]);
+       close(fd[1]);
+       return 0;
+     }
+   cbdata->cb_done = done_cb;
+   cbdata->data = data;
+   if (!(cbdata->fdh = ecore_main_fd_handler_add(fd[0], ECORE_FD_READ, 
+                                                _ecore_con_dns_data_handler,
+                                                cbdata,
+                                                NULL, NULL)))
+     {
+       free(cbdata);
+       close(fd[0]);
+       close(fd[1]);
+       return 0;
+     }
+                            
+   if ((cbdata->pid = fork()) == 0)
+     {
+       struct hostent *he;
+       
+       /* CHILD */
+       he = gethostbyname(name);
+       if (he)
+         {
+            struct in_addr addr;
+            
+            memcpy((struct in_addr *)&addr, he->h_addr,
+                   sizeof(struct in_addr));
+            write(fd[1], &(addr.s_addr), sizeof(in_addr_t));
+         }
+       close(fd[1]);
+       exit(0);
+     }
+   /* PARENT */
+   cbdata->handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, 
_ecore_con_dns_exit_handler, cbdata);
+   if (!cbdata->handler)
+     {
+       ecore_main_fd_handler_del(cbdata->fdh);
+       free(cbdata);
+       close(fd[0]);
+       close(fd[1]);
+       return 0;
+     }
+#else
    Ecore_Con_Dns_Query *query;
    Ecore_Con_Dns_Cache *current;
    Ecore_List2 *l;
@@ -311,9 +447,12 @@
    query->search = -1;
 
    _ecore_con_dns_ghbn(query, name);
+#endif   
    return 1;
 }
 
+#if 1
+#else
 static void
 _ecore_con_dns_ghbn(Ecore_Con_Dns_Query *query, const char *hostname)
 {
@@ -780,3 +919,4 @@
      data++;
    return data;
 }
+#endif




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to