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>
This commit is contained in:
Jean-Philippe Andre 2013-06-26 17:47:41 +09:00 committed by Cedric Bail
parent f9a7820e02
commit db6cba1429
3 changed files with 74 additions and 16 deletions

View File

@ -130,9 +130,24 @@ _cserve2_client_open(Client *client)
key = ((const char *)msg) + sizeof(*msg) + msg->key_offset;
INF("Received OPEN command: RID=%d", msg->base.rid);
INF("File_ID: %d, path=\"%s\", key=\"%s\"", msg->file_id, path, key);
INF("File_ID: %d, path=\"%s\", key=\"%s\", has_load_opts=%d",
msg->file_id, path, key, (int) msg->has_load_opts);
cserve2_cache_file_open(client, msg->file_id, path, key, msg->base.rid);
if (!msg->has_load_opts)
{
/* FIXME: We should remove this fake call to setopts and do the
* appropriate work instead. (split functions) */
Msg_Setopts optsmsg;
memset(&optsmsg, 0, sizeof(optsmsg));
optsmsg.base.rid = msg->base.rid;
optsmsg.base.type = CSERVE2_SETOPTS;
optsmsg.file_id = msg->file_id;
optsmsg.image_id = msg->image_id;
cserve2_cache_image_opts_set(client, &optsmsg);
}
}
static void

View File

@ -54,6 +54,9 @@ struct _Msg_Open {
unsigned int file_id;
int path_offset;
int key_offset;
unsigned int image_id;
Eina_Bool has_load_opts : 1;
};
struct _Msg_Opened {

View File

@ -46,6 +46,25 @@ static Eina_List *_requests = NULL;
#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
#endif
static inline Eina_Bool
_memory_zero_cmp(void *data, size_t len)
{
const int *idata = data;
const char *cdata;
int remain;
if (!data || !len) return EINA_TRUE;
for (remain = len / sizeof(idata); remain > 0; --remain)
if (*idata++ != 0) return EINA_FALSE;
cdata = (const char*) idata;
for (remain = ((const char*) data + len) - cdata; remain > 0; --remain)
if (*cdata++ != 0) return EINA_FALSE;
return EINA_TRUE;
}
static void
_socket_path_set(char *path)
{
@ -585,7 +604,7 @@ _build_absolute_path(const char *path, char buf[], int size)
}
static unsigned int
_image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas_Image_Load_Opts *lopt EINA_UNUSED)
_image_open_server_send(Image_Entry *ie, const char *file, const char *key, Eina_Bool has_load_opts)
{
int flen, klen;
int size;
@ -593,6 +612,7 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
char filebuf[PATH_MAX];
Msg_Open msg_open;
File_Entry *fentry;
Data_Entry *dentry;
if (cserve2_init == 0)
{
@ -600,6 +620,9 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
return 0;
}
ie->data1 = NULL;
ie->data2 = NULL;
flen = _build_absolute_path(file, filebuf, sizeof(filebuf));
if (!flen)
{
@ -611,6 +634,16 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
if (!key) key = "";
fentry = calloc(1, sizeof(*fentry));
if (!fentry)
return 0;
dentry = calloc(1, sizeof(*dentry));
if (!dentry)
{
free(fentry);
return 0;
}
memset(&msg_open, 0, sizeof(msg_open));
@ -622,10 +655,17 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key, Evas
msg_open.file_id = fentry->file_id;
msg_open.path_offset = 0;
msg_open.key_offset = flen;
msg_open.has_load_opts = has_load_opts;
msg_open.image_id = ++_data_id;
size = sizeof(msg_open) + flen + klen;
buf = malloc(size);
if (!buf) return EINA_FALSE;
if (!buf)
{
free(fentry);
free(dentry);
return 0;
}
memcpy(buf, &msg_open, sizeof(msg_open));
memcpy(buf + sizeof(msg_open), filebuf, flen);
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
ERR("Couldn't send message to server.");
free(buf);
free(fentry);
free(dentry);
return 0;
}
free(buf);
ie->data1 = fentry;
dentry->image_id = msg_open.image_id;
ie->data2 = dentry;
return msg_open.base.rid;
}
static unsigned int
_image_setopts_server_send(Image_Entry *ie)
{
File_Entry *fentry;
Data_Entry *dentry;
File_Entry *fentry = ie->data1;
Data_Entry *dentry = ie->data2;
Msg_Setopts msg;
if (cserve2_init == 0)
return 0;
fentry = ie->data1;
dentry = calloc(1, sizeof(*dentry));
if (!dentry)
if (!fentry || !dentry)
return 0;
memset(&msg, 0, sizeof(msg));
dentry->image_id = ++_data_id;
if (dentry->image_id == 0)
dentry->image_id = ++_data_id;
msg.base.rid = _next_rid();
msg.base.type = CSERVE2_SETOPTS;
@ -691,11 +729,10 @@ _image_setopts_server_send(Image_Entry *ie)
if (!_server_send(&msg, sizeof(msg), NULL, NULL))
{
free(dentry);
ie->data2 = NULL;
return 0;
}
ie->data2 = dentry;
return msg.base.rid;
}
@ -840,17 +877,20 @@ Eina_Bool
evas_cserve2_image_load(Image_Entry *ie, const char *file, const char *key, Evas_Image_Load_Opts *lopt)
{
unsigned int rid;
Eina_Bool has_load_opts;
if (!ie)
return EINA_FALSE;
rid = _image_open_server_send(ie, file, key, lopt);
has_load_opts = !_memory_zero_cmp(lopt, sizeof(*lopt));
rid = _image_open_server_send(ie, file, key, has_load_opts);
if (!rid)
return EINA_FALSE;
ie->open_rid = rid;
_image_setopts_server_send(ie);
if (has_load_opts)
_image_setopts_server_send(ie);
// _server_dispatch_until(rid);