summaryrefslogtreecommitdiff
path: root/src/lib/evas/cserve2/evas_cs2_client.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-06-26 17:47:41 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-07-02 16:58:10 +0900
commitdb6cba1429624968cf7f9bc49a508d2bb5d0b23f (patch)
tree195755931f3edf5d4fe90c22b76f974f2bef3be5 /src/lib/evas/cserve2/evas_cs2_client.c
parentf9a7820e0240d166328576f7bd8a1ee16c9cd1d7 (diff)
evas/cserve2: avoid useless SETOPT messages.
Most of the time, the SETOPT message is sent only to carry 0 data. Let's add a flag to the OPEN message to avoid useless socket calls. Server-side: implement with message faking. Also, fix image ID logic on client side: - alloc data entry asap, - assign image_id during call to OPEN Signed-off-by: Cedric Bail <cedric.bail@samsung.com>
Diffstat (limited to 'src/lib/evas/cserve2/evas_cs2_client.c')
-rw-r--r--src/lib/evas/cserve2/evas_cs2_client.c70
1 files changed, 55 insertions, 15 deletions
diff --git a/src/lib/evas/cserve2/evas_cs2_client.c b/src/lib/evas/cserve2/evas_cs2_client.c
index 404b5224f3..30845501f5 100644
--- a/src/lib/evas/cserve2/evas_cs2_client.c
+++ b/src/lib/evas/cserve2/evas_cs2_client.c
@@ -46,6 +46,25 @@ static Eina_List *_requests = NULL;
46#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path) 46#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
47#endif 47#endif
48 48
49static inline Eina_Bool
50_memory_zero_cmp(void *data, size_t len)
51{
52 const int *idata = data;
53 const char *cdata;
54 int remain;
55
56 if (!data || !len) return EINA_TRUE;
57
58 for (remain = len / sizeof(idata); remain > 0; --remain)
59 if (*idata++ != 0) return EINA_FALSE;
60
61 cdata = (const char*) idata;
62 for (remain = ((const char*) data + len) - cdata; remain > 0; --remain)
63 if (*cdata++ != 0) return EINA_FALSE;
64
65 return EINA_TRUE;
66}
67
49static void 68static void
50_socket_path_set(char *path) 69_socket_path_set(char *path)
51{ 70{
@@ -585,7 +604,7 @@ _build_absolute_path(const char *path, char buf[], int size)
585} 604}
586 605
587static unsigned int 606static unsigned int
588_image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas_Image_Load_Opts *lopt EINA_UNUSED) 607_image_open_server_send(Image_Entry *ie, const char *file, const char *key, Eina_Bool has_load_opts)
589{ 608{
590 int flen, klen; 609 int flen, klen;
591 int size; 610 int size;
@@ -593,6 +612,7 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
593 char filebuf[PATH_MAX]; 612 char filebuf[PATH_MAX];
594 Msg_Open msg_open; 613 Msg_Open msg_open;
595 File_Entry *fentry; 614 File_Entry *fentry;
615 Data_Entry *dentry;
596 616
597 if (cserve2_init == 0) 617 if (cserve2_init == 0)
598 { 618 {
@@ -600,6 +620,9 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
600 return 0; 620 return 0;
601 } 621 }
602 622
623 ie->data1 = NULL;
624 ie->data2 = NULL;
625
603 flen = _build_absolute_path(file, filebuf, sizeof(filebuf)); 626 flen = _build_absolute_path(file, filebuf, sizeof(filebuf));
604 if (!flen) 627 if (!flen)
605 { 628 {
@@ -611,6 +634,16 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
611 if (!key) key = ""; 634 if (!key) key = "";
612 635
613 fentry = calloc(1, sizeof(*fentry)); 636 fentry = calloc(1, sizeof(*fentry));
637 if (!fentry)
638 return 0;
639
640 dentry = calloc(1, sizeof(*dentry));
641 if (!dentry)
642 {
643 free(fentry);
644 return 0;
645 }
646
614 647
615 memset(&msg_open, 0, sizeof(msg_open)); 648 memset(&msg_open, 0, sizeof(msg_open));
616 649
@@ -622,10 +655,17 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
622 msg_open.file_id = fentry->file_id; 655 msg_open.file_id = fentry->file_id;
623 msg_open.path_offset = 0; 656 msg_open.path_offset = 0;
624 msg_open.key_offset = flen; 657 msg_open.key_offset = flen;
658 msg_open.has_load_opts = has_load_opts;
659 msg_open.image_id = ++_data_id;
625 660
626 size = sizeof(msg_open) + flen + klen; 661 size = sizeof(msg_open) + flen + klen;
627 buf = malloc(size); 662 buf = malloc(size);
628 if (!buf) return EINA_FALSE; 663 if (!buf)
664 {
665 free(fentry);
666 free(dentry);
667 return 0;
668 }
629 memcpy(buf, &msg_open, sizeof(msg_open)); 669 memcpy(buf, &msg_open, sizeof(msg_open));
630 memcpy(buf + sizeof(msg_open), filebuf, flen); 670 memcpy(buf + sizeof(msg_open), filebuf, flen);
631 memcpy(buf + sizeof(msg_open) + flen, key, klen); 671 memcpy(buf + sizeof(msg_open) + flen, key, klen);
@@ -635,35 +675,33 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
635 ERR("Couldn't send message to server."); 675 ERR("Couldn't send message to server.");
636 free(buf); 676 free(buf);
637 free(fentry); 677 free(fentry);
678 free(dentry);
638 return 0; 679 return 0;
639 } 680 }
640 681
641 free(buf); 682 free(buf);
642 ie->data1 = fentry; 683 ie->data1 = fentry;
643 684
685 dentry->image_id = msg_open.image_id;
686 ie->data2 = dentry;
687
644 return msg_open.base.rid; 688 return msg_open.base.rid;
645} 689}
646 690
647static unsigned int 691static unsigned int
648_image_setopts_server_send(Image_Entry *ie) 692_image_setopts_server_send(Image_Entry *ie)
649{ 693{
650 File_Entry *fentry; 694 File_Entry *fentry = ie->data1;
651 Data_Entry *dentry; 695 Data_Entry *dentry = ie->data2;
652 Msg_Setopts msg; 696 Msg_Setopts msg;
653 697
654 if (cserve2_init == 0) 698 if (cserve2_init == 0)
655 return 0; 699 return 0;
656 700
657 fentry = ie->data1; 701 if (!fentry || !dentry)
658
659 dentry = calloc(1, sizeof(*dentry));
660 if (!dentry)
661 return 0; 702 return 0;
662 703
663 memset(&msg, 0, sizeof(msg)); 704 memset(&msg, 0, sizeof(msg));
664 dentry->image_id = ++_data_id;
665 if (dentry->image_id == 0)
666 dentry->image_id = ++_data_id;
667 705
668 msg.base.rid = _next_rid(); 706 msg.base.rid = _next_rid();
669 msg.base.type = CSERVE2_SETOPTS; 707 msg.base.type = CSERVE2_SETOPTS;
@@ -691,11 +729,10 @@ _image_setopts_server_send(Image_Entry *ie)
691 if (!_server_send(&msg, sizeof(msg), NULL, NULL)) 729 if (!_server_send(&msg, sizeof(msg), NULL, NULL))
692 { 730 {
693 free(dentry); 731 free(dentry);
732 ie->data2 = NULL;
694 return 0; 733 return 0;
695 } 734 }
696 735
697 ie->data2 = dentry;
698
699 return msg.base.rid; 736 return msg.base.rid;
700} 737}
701 738
@@ -840,17 +877,20 @@ Eina_Bool
840evas_cserve2_image_load(Image_Entry *ie, const char *file, const char *key, Evas_Image_Load_Opts *lopt) 877evas_cserve2_image_load(Image_Entry *ie, const char *file, const char *key, Evas_Image_Load_Opts *lopt)
841{ 878{
842 unsigned int rid; 879 unsigned int rid;
880 Eina_Bool has_load_opts;
843 881
844 if (!ie) 882 if (!ie)
845 return EINA_FALSE; 883 return EINA_FALSE;
846 884
847 rid = _image_open_server_send(ie, file, key, lopt); 885 has_load_opts = !_memory_zero_cmp(lopt, sizeof(*lopt));
886 rid = _image_open_server_send(ie, file, key, has_load_opts);
848 if (!rid) 887 if (!rid)
849 return EINA_FALSE; 888 return EINA_FALSE;
850 889
851 ie->open_rid = rid; 890 ie->open_rid = rid;
852 891
853 _image_setopts_server_send(ie); 892 if (has_load_opts)
893 _image_setopts_server_send(ie);
854 894
855 // _server_dispatch_until(rid); 895 // _server_dispatch_until(rid);
856 896