todo items for cserve for evas done - well some of them. more to come.
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 3 May 2009 07:37:31 +0000 (07:37 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 3 May 2009 07:37:31 +0000 (07:37 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@40495 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/bin/evas_cserve_main.c
src/lib/cserve/evas_cs_client.c
src/lib/cserve/evas_cs_mem.c

index 68bb726..db10194 100644 (file)
@@ -1,11 +1,9 @@
 #include "Evas.h"
 #include "evas_cs.h"
+#include <signal.h>
 
 // fixme:'s
 // 
-// sigint/term - catch and shut down cleanly (server)
-// sigpipe - catch and ignore (both)
-// cwd for loading files needs to be put into a full path (client)
 // add ops to get/set cache size, check time and cache time (both)
 // add ops to get internal state (both)
 // preload - make it work (both)
@@ -658,6 +656,66 @@ parse_args(int argc, char **argv)
      }
 }
 
+static exit_flag = 0;
+
+static void
+exit_handler(int x, siginfo_t *info, void *data)
+{
+   exit_flag = 1;
+}
+
+static void
+pipe_handler(int x, siginfo_t *info, void *data)
+{
+}
+
+static void
+signal_init(void)
+{
+   struct sigaction action, old_action;
+   
+   action.sa_handler = NULL;
+   action.sa_sigaction = exit_handler;
+   action.sa_flags = SA_RESTART | SA_SIGINFO;
+   sigemptyset(&action.sa_mask);
+   sigaction(SIGINT, &action, &old_action);
+
+   action.sa_handler = NULL;
+   action.sa_sigaction = exit_handler;
+   action.sa_flags = SA_RESTART | SA_SIGINFO;
+   sigemptyset(&action.sa_mask);
+   sigaction(SIGTERM, &action, &old_action);
+
+   action.sa_handler = NULL;
+   action.sa_sigaction = exit_handler;
+   action.sa_flags = SA_RESTART | SA_SIGINFO;
+   sigemptyset(&action.sa_mask);
+   sigaction(SIGQUIT, &action, &old_action);
+
+   action.sa_handler = NULL;
+   action.sa_sigaction = pipe_handler;
+   action.sa_flags = SA_RESTART | SA_SIGINFO;
+   sigemptyset(&action.sa_mask);
+   sigaction(SIGPIPE, &action, &old_action);
+
+   // SIGUSR1
+   // SIGUSR2
+   // SIGHUP
+
+   // SIGCHLD
+   
+   // SIGSEGV
+   // SIGILL
+   // SIGBUS
+   // SIGFPE
+   // SIGABRT
+}
+
+static void
+signal_shutdown(void)
+{
+}
+
 int
 main(int argc, char **argv)
 {
@@ -670,6 +728,7 @@ main(int argc, char **argv)
    evas_init();
 
    img_init();
+   signal_init();
    s = evas_cserve_server_add();
    if (!s)
      {
@@ -706,7 +765,9 @@ main(int argc, char **argv)
      {
         /* fixme: timeout 0 only her - future use timeouts for timed
          * housekeping */
+        if (exit_flag) break;
         evas_cserve_server_wait(s, t_next * 1000000);
+        if (exit_flag) break;
         t = time(NULL);
         t_next = t - last_check;
         if ((t_next) > cache_item_timeout_check)
@@ -720,6 +781,12 @@ main(int argc, char **argv)
           t_next = 1;
      }
    error:
+   printf("clean shutdown\n");
+   if (stat_mem)
+     {
+        stat_clean(stat_mem);
+     }
+   signal_shutdown();
    img_shutdown();
    if (stat_mem)
      {
index d9b9248..d029eca 100644 (file)
@@ -1,7 +1,33 @@
 #include "evas_cs.h"
+#include <signal.h>
 
 #ifdef EVAS_CSERVE
 
+static void
+pipe_handler(int x, siginfo_t *info, void *data)
+{
+}
+
+static void
+pipe_handle(int push)
+{
+   static struct sigaction old_action;
+   struct sigaction action;
+
+   if (push)
+     {
+        action.sa_handler = NULL;
+        action.sa_sigaction = pipe_handler;
+        action.sa_flags = SA_RESTART | SA_SIGINFO;
+        sigemptyset(&action.sa_mask);
+        sigaction(SIGPIPE, &action, &old_action);
+     }
+   else
+     {
+        sigaction(SIGPIPE, &old_action, &action);
+     }
+}
+
 static Server *
 server_connect(void)
 {
@@ -52,12 +78,22 @@ server_send(Server *s, int opcode, int size, unsigned char *data)
    int ints[2];
    int num;
    
+   pipe_handle(1);
    ints[0] = size;
    ints[1] = opcode;
    num = write(s->fd, ints, (sizeof(int) * 2));
-   if (num < 0) return 0;
+   if (num < 0)
+     {
+        pipe_handle(0);
+        return 0;
+     }
    num = write(s->fd, data, size);
-   if (num < 0) return 0;
+   if (num < 0)
+     {
+        pipe_handle(0);
+        return 0;
+     }
+   pipe_handle(0);
    return 1;
 }
 
@@ -158,6 +194,7 @@ evas_cserve_image_load(Image_Entry *ie, const char *file, const char *key, RGBA_
    Op_Load msg;
    Op_Load_Reply *rep;
    unsigned char *buf;
+   char fbuf[PATH_MAX], wd[PATH_MAX];
    int flen, klen;
    int opcode;
    int size;
@@ -171,6 +208,15 @@ evas_cserve_image_load(Image_Entry *ie, const char *file, const char *key, RGBA_
    msg.lopt.dpi = lopt->dpi;
    msg.lopt.w = lopt->w;
    msg.lopt.h = lopt->h;
+   if (file[0] != '/')
+     {
+        if (getcwd(wd, sizeof(wd)))
+          {
+             snprintf(fbuf, "%s/%s", wd, file);
+             file = fbuf;
+          }
+     }
+   if (!realpath(file, wd)) file = wd;
    flen = strlen(file) + 1;
    klen = strlen(key) + 1;
    buf = malloc(sizeof(msg) + flen + klen);
index 3e7a944..59f3460 100644 (file)
@@ -123,6 +123,7 @@ evas_cserve_mem_close(Mem *m)
 EAPI Eina_Bool
 evas_cserve_mem_resize(Mem *m, int size)
 {
+   if (m->size == size) return 1;
    if (m->write)
      {
         if (ftruncate(m->fd, size) < 0) return 0;