forked from enlightenment/efl
1. make max image size a #define
2. max image size > 65536x65536 3. fix cserve leak 4. fix cserve+async load to work together. SVN revision: 42406
This commit is contained in:
parent
e7d76f6392
commit
7ee7fb5604
|
@ -465,16 +465,16 @@ img_new(const char *file, const char *key, RGBA_Image_Loadopts *load_opts, const
|
|||
int err = 0;
|
||||
double t;
|
||||
|
||||
D("... stat %s\n", file);
|
||||
D("... stat %s", file);
|
||||
ret = stat(file, &st);
|
||||
if (ret < 0) return NULL;
|
||||
D("... load header\n");
|
||||
D("... load header");
|
||||
t = get_time();
|
||||
ie = evas_cache_image_request(cache, file, key, load_opts, &err);
|
||||
t = get_time() - t;
|
||||
D("... header done\n");
|
||||
D("... header done");
|
||||
if (!ie) return NULL;
|
||||
D("... ie->cache = %p\n", ie->cache);
|
||||
D("... ie->cache = %p", ie->cache);
|
||||
img = (Img *)ie;
|
||||
img->stats.load1 = t;
|
||||
img->key = eina_stringshare_add(bufkey);
|
||||
|
@ -552,21 +552,21 @@ img_free(Img *img)
|
|||
static void
|
||||
cache_clean(void)
|
||||
{
|
||||
D("... cache clean!!! do\n");
|
||||
D("... cache clean!!! do");
|
||||
LKL(cache_lock);
|
||||
while ((cache_usage > ((cache_max_usage + cache_max_adjust) * 1024)) &&
|
||||
(cache_images))
|
||||
{
|
||||
Img *img;
|
||||
Eina_List *l;
|
||||
|
||||
D("... clean loop %i > %i\n", cache_usage, (cache_max_usage + cache_max_adjust) * 1024);
|
||||
|
||||
D("... clean loop %i > %i", cache_usage, (cache_max_usage + cache_max_adjust) * 1024);
|
||||
l = eina_list_last(cache_images); // THREAD: called from thread. happens to be safe as it uses no unlocked shared resources
|
||||
if (!l) break;
|
||||
img = l->data;
|
||||
if (!img) break;
|
||||
LKL(img->lock);
|
||||
D("... REMOVE %p '%s'\n", img, img->file.file);
|
||||
D("... REMOVE %p '%s'", img, img->file.file);
|
||||
#ifdef BUILD_PTHREAD
|
||||
img->killme = 1;
|
||||
img->useless = 1;
|
||||
|
@ -577,7 +577,7 @@ cache_clean(void)
|
|||
cache_images = eina_list_remove_list(cache_images, l); // FIXME: called from thread
|
||||
img->incache--;
|
||||
cache_usage -= img->usage;
|
||||
D("... IMG FREE %p\n", img);
|
||||
D("... IMG FREE %p", img);
|
||||
img_free(img);
|
||||
#endif
|
||||
}
|
||||
|
@ -633,10 +633,10 @@ mem_cache_adjust(void)
|
|||
|
||||
if (cache_max_adjust < -cache_max_usage)
|
||||
cache_max_adjust = -cache_max_usage;
|
||||
D("... cache_max_adjust = %i\n", cache_max_adjust);
|
||||
D("... cache_max_adjust = %i", cache_max_adjust);
|
||||
if (pval != cache_max_adjust)
|
||||
{
|
||||
D("... cache clean\n");
|
||||
D("... cache clean");
|
||||
// FIXME lock problem
|
||||
cache_clean();
|
||||
}
|
||||
|
@ -648,17 +648,17 @@ img_cache(Img *img)
|
|||
eina_hash_del(active_images, img->key, img);
|
||||
if (img->dead)
|
||||
{
|
||||
D("... img %p '%s' dead\n", img , img->file.file);
|
||||
D("... img %p '%s' dead", img , img->file.file);
|
||||
img_free(img);
|
||||
return;
|
||||
}
|
||||
if ((cache_usage + img->usage) > ((cache_max_usage + cache_max_adjust) * 1024))
|
||||
{
|
||||
D("... img %p '%s' too big for cache\n", img , img->file.file);
|
||||
D("... img %p '%s' too big for cache", img , img->file.file);
|
||||
img_free(img);
|
||||
return;
|
||||
}
|
||||
D("... img %p '%s' cached += %i\n", img , img->file.file, img->usage);
|
||||
D("... img %p '%s' cached += %i", img , img->file.file, img->usage);
|
||||
if (img->incache > 0)
|
||||
{
|
||||
printf("EEEEEEEEEEEEEEEEK!\n");
|
||||
|
@ -726,8 +726,8 @@ img_load(const char *file, const char *key, RGBA_Image_Loadopts *load_opts)
|
|||
Eina_List *l, *l_next;
|
||||
|
||||
if (!file) return NULL;
|
||||
D("... img_load '%s'\n", file);
|
||||
if (key) D("... ... key '%s'\n", key);
|
||||
D("... img_load '%s'", file);
|
||||
if (key) D("... ... key '%s'", key);
|
||||
if (key)
|
||||
snprintf(buf, sizeof(buf), "%s///::/%s/\001/%i/%1.8f/%ix%i",
|
||||
file, key,
|
||||
|
@ -740,16 +740,16 @@ img_load(const char *file, const char *key, RGBA_Image_Loadopts *load_opts)
|
|||
load_opts->scale_down_by,
|
||||
load_opts->dpi,
|
||||
load_opts->w, load_opts->h);
|
||||
D("... find '%s'\n", buf);
|
||||
D("... find '%s'", buf);
|
||||
img = eina_hash_find(active_images, buf);
|
||||
if ((img) && (img_ok(img)))
|
||||
{
|
||||
D("... found!\n");
|
||||
D("... found!");
|
||||
img->stats.load1saved++;
|
||||
img->ref++;
|
||||
D("... sats update\n");
|
||||
D("... sats update");
|
||||
stats_update();
|
||||
D("... return %p\n", img);
|
||||
D("... return %p", img);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
@ -762,7 +762,7 @@ img_load(const char *file, const char *key, RGBA_Image_Loadopts *load_opts)
|
|||
LKL(img->lock);
|
||||
if (img_ok(img))
|
||||
{
|
||||
D("... found cached\n");
|
||||
D("... found cached");
|
||||
cache_images = eina_list_remove_list(cache_images, l);
|
||||
img->incache--;
|
||||
cache_usage -= img->usage;
|
||||
|
@ -770,9 +770,9 @@ img_load(const char *file, const char *key, RGBA_Image_Loadopts *load_opts)
|
|||
img->stats.load1saved++;
|
||||
img->ref++;
|
||||
eina_hash_direct_add(active_images, img->key, img);
|
||||
D("... sats update\n");
|
||||
D("... sats update");
|
||||
stats_update();
|
||||
D("... return %p\n", img);
|
||||
D("... return %p", img);
|
||||
LKU(img->lock);
|
||||
LKU(cache_lock);
|
||||
return img;
|
||||
|
@ -781,7 +781,7 @@ img_load(const char *file, const char *key, RGBA_Image_Loadopts *load_opts)
|
|||
}
|
||||
}
|
||||
LKU(cache_lock);
|
||||
D("... ned new img\n");
|
||||
D("... ned new img");
|
||||
return img_new(file, key, load_opts, buf);
|
||||
}
|
||||
|
||||
|
@ -797,10 +797,10 @@ img_unload(Img *img)
|
|||
return;
|
||||
}
|
||||
img->ref--;
|
||||
D("... img ref-- = %i\n", img->ref);
|
||||
D("... img ref-- = %i", img->ref);
|
||||
if (img->ref == 0)
|
||||
{
|
||||
D("... img cache %p '%s'\n", img, img->file.file);
|
||||
D("... img cache %p '%s'", img, img->file.file);
|
||||
img_cache(img);
|
||||
}
|
||||
}
|
||||
|
@ -808,12 +808,12 @@ img_unload(Img *img)
|
|||
static void
|
||||
img_unloaddata(Img *img)
|
||||
{
|
||||
D("img_unloaddata() %p '%s'\n", img, img->file.file);
|
||||
D("img_unloaddata() %p '%s'", img, img->file.file);
|
||||
if ((img->dref <= 0) && (img->useless) && (img->mem))
|
||||
{
|
||||
Image_Entry *ie = (Image_Entry *)img;
|
||||
|
||||
D("... really do forced unload\n");
|
||||
D("... really do forced unload");
|
||||
if (!img->active) cache_usage -= img->usage;
|
||||
img->usage -=
|
||||
(4096 * (((img->image.w * img->image.h * sizeof(DATA32)) + 4095) / 4096)) +
|
||||
|
@ -824,7 +824,7 @@ img_unloaddata(Img *img)
|
|||
img->mem = NULL;
|
||||
img->image.data = NULL;
|
||||
img->dref = 0;
|
||||
D("... done\n");
|
||||
D("... done");
|
||||
|
||||
ie->flags.loaded = 0;
|
||||
ie->allocated.w = 0;
|
||||
|
@ -835,7 +835,7 @@ img_unloaddata(Img *img)
|
|||
static void
|
||||
img_useless(Img *img)
|
||||
{
|
||||
D("img_useless() %p\n", img);
|
||||
D("img_useless() %p", img);
|
||||
img->useless = 1;
|
||||
if (img->dref <= 0) img_unloaddata(img);
|
||||
}
|
||||
|
@ -843,7 +843,7 @@ img_useless(Img *img)
|
|||
static void
|
||||
img_forcedunload(Img *img)
|
||||
{
|
||||
D("img_forcedunload() %p\n", img);
|
||||
D("img_forcedunload() %p", img);
|
||||
img->dead = 1;
|
||||
img_unload(img);
|
||||
}
|
||||
|
@ -851,8 +851,7 @@ img_forcedunload(Img *img)
|
|||
static void
|
||||
img_preload(Img *img)
|
||||
{
|
||||
D("img_preload() %p\n", img);
|
||||
printf("preload '%s'\n", img->file.file);
|
||||
D("img_preload() %p", img);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -862,12 +861,12 @@ client_del(void *data, Client *c)
|
|||
Img *img;
|
||||
|
||||
images = data;
|
||||
D("... CLIENT DEL %i\n", c->pid);
|
||||
D("... CLIENT DEL %i", c->pid);
|
||||
EINA_LIST_FREE(images, img)
|
||||
{
|
||||
D("... unloaddata img %p\n", img);
|
||||
D("... unloaddata img %p", img);
|
||||
img_unloaddata(img);
|
||||
D("... unload img %p\n", img);
|
||||
D("... unload img %p", img);
|
||||
img_unload(img);
|
||||
}
|
||||
}
|
||||
|
@ -901,7 +900,7 @@ load_data_thread(void *data)
|
|||
msg.mem.id = img->mem->id;
|
||||
msg.mem.offset = img->mem->offset;
|
||||
msg.mem.size = img->mem->size;
|
||||
D("... reply\n");
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_LOADDATA, sizeof(msg), (unsigned char *)(&msg));
|
||||
LKU(c->lock);
|
||||
return NULL;
|
||||
|
@ -917,7 +916,7 @@ load_data_thread(void *data)
|
|||
else
|
||||
msg.mem.id = msg.mem.offset = msg.mem.size = 0;
|
||||
LKU(img->lock);
|
||||
D("... reply\n");
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_LOADDATA, sizeof(msg), (unsigned char *)(&msg));
|
||||
LKU(c->lock);
|
||||
return NULL;
|
||||
|
@ -928,7 +927,7 @@ static int
|
|||
message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *data)
|
||||
{
|
||||
t_now = time(NULL);
|
||||
D("message @ %i...\n", (int)t_now);
|
||||
D("message @ %i...", (int)t_now);
|
||||
switch (opcode)
|
||||
{
|
||||
case OP_INIT:
|
||||
|
@ -939,12 +938,17 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
memset(&msg, 0, sizeof(msg));
|
||||
msg.pid = getpid();
|
||||
msg.server_id = server_id;
|
||||
msg.handle = c;
|
||||
rep = (Op_Init *)data;
|
||||
c->pid = rep->pid;
|
||||
if (rep->server_id == 1) // 2nd channel conn
|
||||
{
|
||||
c->client_main = rep->handle;
|
||||
}
|
||||
c->func = client_del;
|
||||
c->data = NULL;
|
||||
D("OP_INIT %i\n", c->pid);
|
||||
D("... reply\n");
|
||||
D("OP_INIT %i", c->pid);
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_INIT, sizeof(msg), (unsigned char *)(&msg));
|
||||
}
|
||||
break;
|
||||
|
@ -956,7 +960,7 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
RGBA_Image_Loadopts lopt = {0, 0.0, 0, 0};
|
||||
char *file = NULL, *key = NULL;
|
||||
|
||||
D("OP_LOAD %i\n", c->pid);
|
||||
D("OP_LOAD %i", c->pid);
|
||||
rep = (Op_Load *)data;
|
||||
file = data + sizeof(Op_Load);
|
||||
key = file + strlen(file) + 1;
|
||||
|
@ -965,17 +969,20 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
lopt.dpi = rep->lopt.dpi;
|
||||
lopt.w = rep->lopt.w;
|
||||
lopt.h = rep->lopt.h;
|
||||
D("... img_load '%s'\n", file);
|
||||
if (key) D("'%s'\n", key);
|
||||
else D(" '%s'\n", NULL);
|
||||
D(" lopt { %i %1.1f %i %i}\n",
|
||||
D("... img_load '%s'", file);
|
||||
if (key) D("'%s'", key);
|
||||
else D(" '%s'", NULL);
|
||||
D(" lopt { %i %1.1f %i %i}",
|
||||
lopt.scale_down_by, lopt.dpi, lopt.w, lopt.h);
|
||||
img = img_load(file, key, &lopt);
|
||||
D("... img_load = %p\n", img);
|
||||
D("... img_load = %p", img);
|
||||
if (img)
|
||||
{
|
||||
D("... add image to client list\n");
|
||||
c->data = eina_list_append(c->data, img);
|
||||
D("... add image to client list");
|
||||
if (c->client_main)
|
||||
c->client_main->data = eina_list_append(c->client_main->data, img);
|
||||
else
|
||||
c->data = eina_list_append(c->data, img);
|
||||
}
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.handle = img;
|
||||
|
@ -995,7 +1002,7 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
msg.image.h = img->image.h;
|
||||
msg.image.alpha = img->image.alpha;
|
||||
}
|
||||
D("... reply\n");
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_LOAD, sizeof(msg), (unsigned char *)(&msg));
|
||||
}
|
||||
break;
|
||||
|
@ -1004,19 +1011,27 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
Op_Unload *rep;
|
||||
Img *img;
|
||||
|
||||
D("OP_UNLOAD %i\n", c->pid);
|
||||
D("OP_UNLOAD %i", c->pid);
|
||||
rep = (Op_Unload *)data;
|
||||
img = rep->handle;
|
||||
if ((img) && (rep->server_id == server_id))
|
||||
{
|
||||
D("... remove %p from list\n", img);
|
||||
c->data = eina_list_remove(c->data, img);
|
||||
D("... unload %p\n", img);
|
||||
Eina_Bool doflush = 0;
|
||||
|
||||
D("... remove %p from list", img);
|
||||
if (c->client_main)
|
||||
c->client_main->data = eina_list_remove(c->client_main->data, img);
|
||||
else
|
||||
c->data = eina_list_remove(c->data, img);
|
||||
D("... unload %p", img);
|
||||
LKL(img->lock);
|
||||
img->ref++;
|
||||
img_unload(img);
|
||||
img->ref--;
|
||||
if (img->ref == 0) doflush = 1;
|
||||
LKU(img->lock);
|
||||
if (doflush)
|
||||
img_cache(img);
|
||||
cache_clean();
|
||||
}
|
||||
}
|
||||
|
@ -1027,14 +1042,14 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
Op_Loaddata_Reply msg;
|
||||
Img *img;
|
||||
|
||||
D("OP_LOADDATA %i\n", c->pid);
|
||||
D("OP_LOADDATA %i", c->pid);
|
||||
rep = (Op_Loaddata *)data;
|
||||
img = rep->handle;
|
||||
if ((img) && (rep->server_id == server_id))
|
||||
{
|
||||
if (img->mem)
|
||||
{
|
||||
D("... load saved - cached %p\n", img);
|
||||
D("... load saved - cached %p", img);
|
||||
img->stats.load2saved++;
|
||||
stats_update();
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
@ -1046,7 +1061,7 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
}
|
||||
else
|
||||
msg.mem.id = msg.mem.offset = msg.mem.size = 0;
|
||||
D("... reply\n");
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_LOADDATA, sizeof(msg), (unsigned char *)(&msg));
|
||||
}
|
||||
else
|
||||
|
@ -1056,7 +1071,7 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
pthread_attr_t attr;
|
||||
Load_Inf *li;
|
||||
|
||||
D("... load data %p\n", img);
|
||||
D("... load data %p", img);
|
||||
pthread_attr_init(&attr);
|
||||
li = calloc(1, sizeof(Load_Inf));
|
||||
if (li)
|
||||
|
@ -1083,7 +1098,7 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
}
|
||||
else
|
||||
msg.mem.id = msg.mem.offset = msg.mem.size = 0;
|
||||
D("... reply\n");
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_LOADDATA, sizeof(msg), (unsigned char *)(&msg));
|
||||
#endif
|
||||
}
|
||||
|
@ -1100,16 +1115,16 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
Op_Unloaddata *rep;
|
||||
Img *img;
|
||||
|
||||
D("OP_UNLOADDATA %i\n", c->pid);
|
||||
D("OP_UNLOADDATA %i", c->pid);
|
||||
rep = (Op_Unloaddata *)data;
|
||||
img = rep->handle;
|
||||
if ((img) && (rep->server_id == server_id))
|
||||
{
|
||||
D("... dref--\n");
|
||||
D("... dref--");
|
||||
LKL(img->lock);
|
||||
img->dref--;
|
||||
if (img->dref < 0) img->dref = 0;
|
||||
D("... unload data %p '%s'\n", img, img->file.file);
|
||||
D("... unload data %p '%s'", img, img->file.file);
|
||||
img_unloaddata(img);
|
||||
LKU(img->lock);
|
||||
}
|
||||
|
@ -1120,16 +1135,16 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
Op_Unloaddata *rep;
|
||||
Img *img;
|
||||
|
||||
D("OP_USELESSDATA %i\n", c->pid);
|
||||
D("OP_USELESSDATA %i", c->pid);
|
||||
rep = (Op_Unloaddata *)data;
|
||||
img = rep->handle;
|
||||
if ((img) && (rep->server_id == server_id))
|
||||
{
|
||||
D("... dref--\n");
|
||||
D("... dref--");
|
||||
LKL(img->lock);
|
||||
img->dref--;
|
||||
if (img->dref < 0) img->dref = 0;
|
||||
D("... useless %p\n", img);
|
||||
D("... useless %p", img);
|
||||
img_useless(img);
|
||||
LKU(img->lock);
|
||||
}
|
||||
|
@ -1140,13 +1155,16 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
Op_Preload *rep;
|
||||
Img *img;
|
||||
|
||||
D("OP_PRELOAD %i\n", c->pid);
|
||||
D("OP_PRELOAD %i", c->pid);
|
||||
rep = (Op_Preload *)data;
|
||||
img = rep->handle;
|
||||
if ((img) && (rep->server_id == server_id))
|
||||
{
|
||||
LKL(img->lock);
|
||||
c->data = eina_list_remove(c->data, img);
|
||||
if (c->client_main)
|
||||
c->client_main->data = eina_list_remove(c->client_main->data, img);
|
||||
else
|
||||
c->data = eina_list_remove(c->data, img);
|
||||
// FIXME: preload doesnt work async
|
||||
img_preload(img);
|
||||
LKU(img->lock);
|
||||
|
@ -1157,19 +1175,27 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
Op_Forcedunload *rep;
|
||||
Img *img;
|
||||
|
||||
D("OP_FORCEDUNLOAD %i\n", c->pid);
|
||||
D("OP_FORCEDUNLOAD %i", c->pid);
|
||||
rep = (Op_Forcedunload *)data;
|
||||
img = rep->handle;
|
||||
if ((img) && (rep->server_id == server_id))
|
||||
{
|
||||
Eina_Bool doflush = 0;
|
||||
|
||||
LKL(img->lock);
|
||||
D("remove %p from list\n", img);
|
||||
c->data = eina_list_remove(c->data, img);
|
||||
D("... forced unload now\n");
|
||||
D("remove %p from list", img);
|
||||
if (c->client_main)
|
||||
c->client_main->data = eina_list_remove(c->client_main->data, img);
|
||||
else
|
||||
c->data = eina_list_remove(c->data, img);
|
||||
D("... forced unload now");
|
||||
img->ref++;
|
||||
img_forcedunload(img);
|
||||
img->ref--;
|
||||
if (img->ref == 0) doflush = 1;
|
||||
LKU(img->lock);
|
||||
if (doflush)
|
||||
img_cache(img);
|
||||
cache_clean();
|
||||
}
|
||||
}
|
||||
|
@ -1178,11 +1204,11 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
{
|
||||
Op_Getconfig_Reply msg;
|
||||
|
||||
D("OP_GETCONFIG %i\n", c->pid);
|
||||
D("OP_GETCONFIG %i", c->pid);
|
||||
msg.cache_max_usage = cache_max_usage;
|
||||
msg.cache_item_timeout = cache_item_timeout;
|
||||
msg.cache_item_timeout_check = cache_item_timeout_check;
|
||||
D("... reply\n");
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_GETCONFIG, sizeof(msg), (unsigned char *)(&msg));
|
||||
}
|
||||
break;
|
||||
|
@ -1190,14 +1216,14 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
{
|
||||
Op_Setconfig *rep;
|
||||
|
||||
D("OP_SETCONFIG %i\n", c->pid);
|
||||
D("OP_SETCONFIG %i", c->pid);
|
||||
rep = (Op_Setconfig *)data;
|
||||
cache_max_usage = rep->cache_max_usage;
|
||||
cache_item_timeout = rep->cache_item_timeout;
|
||||
cache_item_timeout_check = rep->cache_item_timeout_check;
|
||||
D("... cache timeout\n");
|
||||
D("... cache timeout");
|
||||
cache_timeout(t_now);
|
||||
D("... cache clean\n");
|
||||
D("... cache clean");
|
||||
cache_clean();
|
||||
}
|
||||
break;
|
||||
|
@ -1205,7 +1231,7 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
{
|
||||
Op_Getstats_Reply msg;
|
||||
|
||||
D("OP_GETSTATS %i\n", c->pid);
|
||||
D("OP_GETSTATS %i", c->pid);
|
||||
stats_calc();
|
||||
msg.saved_memory = saved_memory;
|
||||
msg.wasted_memory = (real_memory - alloced_memory);
|
||||
|
@ -1213,7 +1239,7 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
msg.wasted_memory_peak = (real_memory_peak - alloced_memory_peak);
|
||||
msg.saved_time_image_header_load = saved_load_lifetime + saved_load_time;
|
||||
msg.saved_time_image_data_load = saved_loaddata_lifetime + saved_loaddata_time;
|
||||
D("... reply\n");
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_GETSTATS, sizeof(msg), (unsigned char *)(&msg));
|
||||
}
|
||||
break;
|
||||
|
@ -1224,19 +1250,19 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
Eina_List *imgs = NULL, *l;
|
||||
Img *img;
|
||||
|
||||
D("OP_GETINFO %i\n", c->pid);
|
||||
D("OP_GETINFO %i", c->pid);
|
||||
len = sizeof(Op_Getinfo_Reply);
|
||||
D("... foreach\n");
|
||||
D("... foreach");
|
||||
if (active_images)
|
||||
eina_hash_foreach(active_images, getinfo_hash_image_cb, &imgs);
|
||||
D("... walk foreach list output\n");
|
||||
D("... walk foreach list output");
|
||||
LKL(cache_lock);
|
||||
EINA_LIST_FOREACH(cache_images, l, img)
|
||||
{
|
||||
imgs = eina_list_append(imgs, img);
|
||||
}
|
||||
LKU(cache_lock);
|
||||
D("... walk image cache\n");
|
||||
D("... walk image cache");
|
||||
EINA_LIST_FOREACH(imgs, l, img)
|
||||
{
|
||||
len += sizeof(Op_Getinfo_Item);
|
||||
|
@ -1245,13 +1271,13 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
if (img->file.key) len += strlen(img->file.key);
|
||||
len++;
|
||||
}
|
||||
D("... malloc msg\n");
|
||||
D("... malloc msg");
|
||||
msg = malloc(len);
|
||||
if (msg)
|
||||
{
|
||||
unsigned char *p;
|
||||
|
||||
D("... init msg\n");
|
||||
D("... init msg");
|
||||
memset(msg, 0, len);
|
||||
p = (unsigned char *)msg;
|
||||
msg->active.mem_total = 0;
|
||||
|
@ -1259,13 +1285,13 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
msg->cached.mem_total = 0;
|
||||
msg->cached.count = 0;
|
||||
p += sizeof(Op_Getinfo_Reply);
|
||||
D("... walk all imgs\n");
|
||||
D("... walk all imgs");
|
||||
EINA_LIST_FOREACH(imgs, l, img)
|
||||
{
|
||||
Op_Getinfo_Item *itt, it;
|
||||
|
||||
LKL(img->lock);
|
||||
D("... img %p\n", img);
|
||||
D("... img %p", img);
|
||||
memset(&it, 0, sizeof(Op_Getinfo_Item));
|
||||
itt = (Op_Getinfo_Item *)p;
|
||||
it.file_key_size = 0;
|
||||
|
@ -1315,33 +1341,33 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *
|
|||
}
|
||||
it.dead = img->dead;
|
||||
it.useless = img->useless;
|
||||
D("... memcpy %p %p %i \n",
|
||||
D("... memcpy %p %p %i ",
|
||||
itt, &it, sizeof(Op_Getinfo_Item));
|
||||
memcpy(itt, &it, sizeof(Op_Getinfo_Item));
|
||||
D("... memcpy done n\n", img);
|
||||
D("... memcpy done n", img);
|
||||
p += sizeof(Op_Getinfo_Item) + it.file_key_size;
|
||||
LKU(img->lock);
|
||||
}
|
||||
D("... walk all imgs done\n");
|
||||
D("... walk all imgs done");
|
||||
msg->active.mem_total =
|
||||
(msg->active.mem_total + 1023) / 1024;
|
||||
msg->cached.mem_total =
|
||||
(msg->cached.mem_total + 1023) / 1024;
|
||||
D("... reply\n");
|
||||
D("... reply");
|
||||
evas_cserve_client_send(c, OP_GETINFO, len, msg);
|
||||
free(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
D("... reply empty\n");
|
||||
D("... reply empty");
|
||||
evas_cserve_client_send(c, OP_GETINFO, 0, NULL);
|
||||
}
|
||||
D("... free imgs list\n");
|
||||
D("... free imgs list");
|
||||
if (imgs) eina_list_free(imgs);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
D("OP_... UNKNOWN??? %i opcode: %i\n", c->pid, opcode);
|
||||
D("OP_... UNKNOWN??? %i opcode: %i", c->pid, opcode);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -1466,59 +1492,59 @@ main(int argc, char **argv)
|
|||
|
||||
unsetenv("EVAS_CSERVE");
|
||||
|
||||
D("eina init...\n");
|
||||
D("eina init...");
|
||||
eina_init();
|
||||
D("evas init...\n");
|
||||
D("evas init...");
|
||||
evas_init();
|
||||
|
||||
D("img init...");
|
||||
img_init();
|
||||
D("signal init...\n");
|
||||
D("signal init...");
|
||||
signal_init();
|
||||
D("cserve add...\n");
|
||||
D("cserve add...");
|
||||
s = evas_cserve_server_add();
|
||||
if (!s)
|
||||
{
|
||||
printf("ERROR: server socket init fail. abort.\n");
|
||||
printf("ERROR: server socket init fail. abort.");
|
||||
goto error;
|
||||
}
|
||||
D("mem open (status)...\n");
|
||||
D("mem open (status)...");
|
||||
stat_mem = evas_cserve_mem_open(0, 0, "status", sizeof(int), 0);
|
||||
if (stat_mem)
|
||||
{
|
||||
printf("WARNING: previous evas_cserve left garbage. cleaning up.\n");
|
||||
printf("WARNING: previous evas_cserve left garbage. cleaning up.");
|
||||
stat_clean(stat_mem);
|
||||
evas_cserve_mem_close(stat_mem);
|
||||
stat_mem = NULL;
|
||||
}
|
||||
D("mem new (status)...\n");
|
||||
D("mem new (status)...");
|
||||
stat_mem = evas_cserve_mem_new(sizeof(int), "status");
|
||||
if (!stat_mem)
|
||||
{
|
||||
printf("ERROR: cannot create status shmseg. abort.\n");
|
||||
printf("ERROR: cannot create status shmseg. abort.");
|
||||
goto error;
|
||||
}
|
||||
D("init status...\n");
|
||||
D("init status...");
|
||||
if (!stat_init(stat_mem))
|
||||
{
|
||||
printf("ERROR: cannot init status shmseg. abort.\n");
|
||||
printf("ERROR: cannot init status shmseg. abort.");
|
||||
evas_cserve_mem_free(stat_mem);
|
||||
stat_mem = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
D("cset server message handler...\n");
|
||||
D("cset server message handler...");
|
||||
evas_cserve_server_message_handler_set(s, message, NULL);
|
||||
last_check = time(NULL);
|
||||
t_next = 0;
|
||||
if (cache_item_timeout_check > 0) t_next = cache_item_timeout_check;
|
||||
D("LOOP!!! ...\n");
|
||||
D("LOOP!!! ...");
|
||||
for (;;)
|
||||
{
|
||||
/* fixme: timeout 0 only her - future use timeouts for timed
|
||||
* housekeping */
|
||||
if (exit_flag) break;
|
||||
D("wait for messages...\n");
|
||||
D("wait for messages...");
|
||||
evas_cserve_server_wait(s, t_next * 1000000);
|
||||
if (exit_flag) break;
|
||||
t = time(NULL);
|
||||
|
@ -1526,20 +1552,20 @@ main(int argc, char **argv)
|
|||
if ((cache_item_timeout_check > 0) &&
|
||||
((t_next) >= cache_item_timeout_check))
|
||||
{
|
||||
D("check timeout of items...\n");
|
||||
D("check timeout of items...");
|
||||
t_next = cache_item_timeout_check;
|
||||
|
||||
last_check = t;
|
||||
D("cache timeout...\n");
|
||||
D("cache timeout...");
|
||||
cache_timeout(t);
|
||||
D("meminfo check...\n");
|
||||
D("meminfo check...");
|
||||
meminfo_check();
|
||||
D("mem cache adjust...\n");
|
||||
D("mem cache adjust...");
|
||||
mem_cache_adjust();
|
||||
}
|
||||
if ((t_next <= 0) && (cache_item_timeout_check > 0))
|
||||
t_next = 1;
|
||||
D("sleep for %isec...\n", t_next);
|
||||
D("sleep for %isec...", t_next);
|
||||
|
||||
LKL(strshr_freeme_lock);
|
||||
if (strshr_freeme_count > 0)
|
||||
|
@ -1558,7 +1584,7 @@ main(int argc, char **argv)
|
|||
Eina_List *l;
|
||||
Img *img;
|
||||
Eina_List *kills = NULL;
|
||||
|
||||
|
||||
EINA_LIST_FOREACH(cache_images, l, img)
|
||||
{
|
||||
LKL(img->lock);
|
||||
|
@ -1574,40 +1600,40 @@ main(int argc, char **argv)
|
|||
cache_images = eina_list_remove(cache_images, img);
|
||||
img->incache--;
|
||||
cache_usage -= img->usage;
|
||||
D("... IMG FREE %p\n", img);
|
||||
D("... IMG FREE %p", img);
|
||||
img_free(img);
|
||||
}
|
||||
cache_cleanme = 0;
|
||||
}
|
||||
LKU(cache_lock);
|
||||
}
|
||||
D("end loop...\n");
|
||||
D("end loop...");
|
||||
error:
|
||||
D("cleanup...\n");
|
||||
D("cleanup...");
|
||||
if (stat_mem)
|
||||
{
|
||||
D("clean mem stat...\n");
|
||||
D("clean mem stat...");
|
||||
stat_clean(stat_mem);
|
||||
}
|
||||
D("signal shutdown...\n");
|
||||
D("signal shutdown...");
|
||||
signal_shutdown();
|
||||
D("img shutdown...\n");
|
||||
D("img shutdown...");
|
||||
img_shutdown();
|
||||
if (stat_mem)
|
||||
{
|
||||
D("free stat mem...\n");
|
||||
D("free stat mem...");
|
||||
evas_cserve_mem_free(stat_mem);
|
||||
stat_mem = NULL;
|
||||
}
|
||||
if (s)
|
||||
{
|
||||
D("del server...\n");
|
||||
D("del server...");
|
||||
evas_cserve_server_del(s);
|
||||
}
|
||||
D("evas shutdown...\n");
|
||||
D("evas shutdown...");
|
||||
evas_shutdown();
|
||||
D("eina shutdown...\n");
|
||||
D("eina shutdown...");
|
||||
eina_shutdown();
|
||||
D("exit..\n");
|
||||
D("exit..");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#ifdef EVAS_CSERVE
|
||||
// FIXME: cache server and threaded preload clash badly atm - disable
|
||||
#undef BUILD_ASYNC_PRELOAD
|
||||
//#undef BUILD_ASYNC_PRELOAD
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_ASYNC_PRELOAD
|
||||
|
@ -1243,7 +1243,6 @@ _evas_cache_background_load(void *data)
|
|||
while (preload)
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
if (preload)
|
||||
{
|
||||
Evas_Cache_Preload *tmp = (Evas_Cache_Preload*) preload;
|
||||
|
@ -1256,12 +1255,16 @@ _evas_cache_background_load(void *data)
|
|||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
printf("load loop!\n");
|
||||
if (current)
|
||||
{
|
||||
Evas_Cache_Image *cache;
|
||||
int error;
|
||||
int pchannel;
|
||||
|
||||
LKL(current->lock);
|
||||
pchannel = current->channel;
|
||||
current->channel++;
|
||||
cache = current->cache;
|
||||
|
||||
error = cache->func.load(current);
|
||||
|
@ -1281,11 +1284,13 @@ _evas_cache_background_load(void *data)
|
|||
|
||||
current->flags.preload = 0;
|
||||
|
||||
current->channel = pchannel;
|
||||
LKU(current->lock);
|
||||
|
||||
_evas_cache_image_async_call(current);
|
||||
current = NULL;
|
||||
}
|
||||
printf("---\n");
|
||||
|
||||
pthread_cond_signal(&cond_done);
|
||||
}
|
||||
|
|
|
@ -58,19 +58,24 @@ typedef struct _Mem Mem;
|
|||
struct _Server
|
||||
{
|
||||
char *socket_path;
|
||||
int fd;
|
||||
Eina_List *clients;
|
||||
int (*func) (void *fdata, Server *s, Client *c, int opcode, int size, unsigned char *data);
|
||||
void *data;
|
||||
pid_t pid;
|
||||
int server_id;
|
||||
int req_from, req_to;
|
||||
// for channel 2;
|
||||
struct {
|
||||
int fd;
|
||||
int req_from, req_to;
|
||||
} ch[2];
|
||||
void *main_handle;
|
||||
};
|
||||
|
||||
struct _Client
|
||||
{
|
||||
Server *server;
|
||||
unsigned char *buf;
|
||||
Client *client_main;
|
||||
int bufsize, bufalloc;
|
||||
int fd;
|
||||
unsigned char *inbuf;
|
||||
|
@ -121,6 +126,7 @@ typedef struct
|
|||
{
|
||||
pid_t pid;
|
||||
int server_id;
|
||||
void *handle;
|
||||
} Op_Init;
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -49,7 +49,8 @@ server_connect(void)
|
|||
|
||||
s = calloc(1, sizeof(Server));
|
||||
if (!s) return NULL;
|
||||
s->fd = -1;
|
||||
s->ch[0].fd = -1;
|
||||
s->ch[1].fd = -1;
|
||||
snprintf(buf, sizeof(buf), "/tmp/.evas-cserve-%x", getuid());
|
||||
s->socket_path = strdup(buf);
|
||||
if (!s->socket_path)
|
||||
|
@ -57,18 +58,30 @@ server_connect(void)
|
|||
free(s);
|
||||
return NULL;
|
||||
}
|
||||
s->fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (s->fd < 0) goto error;
|
||||
if (fcntl(s->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
||||
if (setsockopt(s->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0)
|
||||
s->ch[0].fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (s->ch[0].fd < 0) goto error;
|
||||
if (fcntl(s->ch[0].fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
||||
if (setsockopt(s->ch[0].fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0)
|
||||
goto error;
|
||||
socket_unix.sun_family = AF_UNIX;
|
||||
strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
|
||||
socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
|
||||
if (connect(s->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) goto error;
|
||||
if (connect(s->ch[0].fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) goto error;
|
||||
|
||||
s->ch[1].fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (s->ch[1].fd < 0) goto error;
|
||||
if (fcntl(s->ch[1].fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
||||
if (setsockopt(s->ch[1].fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0)
|
||||
goto error;
|
||||
socket_unix.sun_family = AF_UNIX;
|
||||
strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
|
||||
socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
|
||||
if (connect(s->ch[1].fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) goto error;
|
||||
|
||||
return s;
|
||||
error:
|
||||
if (s->fd >= 0) close(s->fd);
|
||||
if (s->ch[0].fd >= 0) close(s->ch[0].fd);
|
||||
if (s->ch[1].fd >= 0) close(s->ch[1].fd);
|
||||
free(s->socket_path);
|
||||
free(s);
|
||||
return NULL;
|
||||
|
@ -77,13 +90,14 @@ server_connect(void)
|
|||
static void
|
||||
server_disconnect(Server *s)
|
||||
{
|
||||
close(s->fd);
|
||||
close(s->ch[0].fd);
|
||||
close(s->ch[1].fd);
|
||||
free(s->socket_path);
|
||||
free(s);
|
||||
}
|
||||
|
||||
static int
|
||||
server_send(Server *s, int opcode, int size, unsigned char *data)
|
||||
server_send(Server *s, int channel, int opcode, int size, unsigned char *data)
|
||||
{
|
||||
int ints[3];
|
||||
int num;
|
||||
|
@ -91,9 +105,9 @@ server_send(Server *s, int opcode, int size, unsigned char *data)
|
|||
pipe_handle(1);
|
||||
ints[0] = size;
|
||||
ints[1] = opcode;
|
||||
s->req_to++;
|
||||
ints[2] = s->req_to;
|
||||
num = write(s->fd, ints, (sizeof(int) * 3));
|
||||
s->ch[channel].req_to++;
|
||||
ints[2] = s->ch[channel].req_to;
|
||||
num = write(s->ch[channel].fd, ints, (sizeof(int) * 3));
|
||||
if (num < 0)
|
||||
{
|
||||
pipe_handle(0);
|
||||
|
@ -101,7 +115,7 @@ server_send(Server *s, int opcode, int size, unsigned char *data)
|
|||
cserve = NULL;
|
||||
return 0;
|
||||
}
|
||||
num = write(s->fd, data, size);
|
||||
num = write(s->ch[channel].fd, data, size);
|
||||
if (num < 0)
|
||||
{
|
||||
pipe_handle(0);
|
||||
|
@ -114,12 +128,12 @@ server_send(Server *s, int opcode, int size, unsigned char *data)
|
|||
}
|
||||
|
||||
static unsigned char *
|
||||
server_read(Server *s, int *opcode, int *size)
|
||||
server_read(Server *s, int channel, int *opcode, int *size)
|
||||
{
|
||||
int ints[3], num, left;
|
||||
unsigned char *data;
|
||||
|
||||
num = read(s->fd, ints, sizeof(int) * 3);
|
||||
num = read(s->ch[channel].fd, ints, sizeof(int) * 3);
|
||||
if (num != (sizeof(int) * 3))
|
||||
{
|
||||
if (cserve) server_disconnect(cserve);
|
||||
|
@ -129,18 +143,18 @@ server_read(Server *s, int *opcode, int *size)
|
|||
*size = ints[0];
|
||||
*opcode = ints[1];
|
||||
if ((*size < 0) || (*size > (1024 * 1024))) return NULL;
|
||||
if (ints[2] != (s->req_from + 1))
|
||||
if (ints[2] != (s->ch[channel].req_from + 1))
|
||||
{
|
||||
printf("EEK! sequence number mismatch from serer with pid: %i\n"
|
||||
"---- num %i is not 1 more than %i\n"
|
||||
,
|
||||
s->pid, ints[2], s->req_from);
|
||||
s->pid, ints[2], s->ch[channel].req_from);
|
||||
return NULL;
|
||||
}
|
||||
s->req_from++;
|
||||
s->ch[channel].req_from++;
|
||||
data = malloc(*size);
|
||||
if (!data) return NULL;
|
||||
num = read(s->fd, data, *size);
|
||||
num = read(s->ch[channel].fd, data, *size);
|
||||
if (num < 0)
|
||||
{
|
||||
free(data);
|
||||
|
@ -149,7 +163,7 @@ server_read(Server *s, int *opcode, int *size)
|
|||
left = *size - num;
|
||||
while (left > 0)
|
||||
{
|
||||
num = read(s->fd, data + (*size - left), left);
|
||||
num = read(s->ch[channel].fd, data + (*size - left), left);
|
||||
if (num < 0)
|
||||
{
|
||||
free(data);
|
||||
|
@ -169,16 +183,30 @@ server_init(Server *s)
|
|||
|
||||
msg.pid = getpid();
|
||||
msg.server_id = 0;
|
||||
if (!server_send(s, OP_INIT, sizeof(msg), (unsigned char *)(&msg)))
|
||||
msg.handle = NULL;
|
||||
if (!server_send(s, 0, OP_INIT, sizeof(msg), (unsigned char *)(&msg)))
|
||||
return 0;
|
||||
rep = (Op_Init *)server_read(s, &opcode, &size);
|
||||
rep = (Op_Init *)server_read(s, 0, &opcode, &size);
|
||||
if ((rep) && (opcode == OP_INIT) && (size == sizeof(Op_Init)))
|
||||
{
|
||||
s->pid = rep->pid;
|
||||
s->server_id = rep->server_id;
|
||||
free(rep);
|
||||
s->main_handle = rep->handle;
|
||||
connect_num++;
|
||||
return 1;
|
||||
msg.pid = getpid();
|
||||
msg.server_id = 1;
|
||||
msg.handle = rep->handle;
|
||||
free(rep);
|
||||
if (!server_send(s, 1, OP_INIT, sizeof(msg), (unsigned char *)(&msg)))
|
||||
return 0;
|
||||
rep = (Op_Init *)server_read(s, 1, &opcode, &size);
|
||||
if ((rep) && (opcode == OP_INIT) && (size == sizeof(Op_Init)))
|
||||
{
|
||||
free(rep);
|
||||
return 1;
|
||||
}
|
||||
if (rep) free(rep);
|
||||
return 0;
|
||||
}
|
||||
if (rep) free(rep);
|
||||
return 0;
|
||||
|
@ -286,7 +314,7 @@ evas_cserve_image_load(Image_Entry *ie, const char *file, const char *key, RGBA_
|
|||
strcpy(buf + sizeof(msg), file);
|
||||
strcpy(buf + sizeof(msg) + flen, key);
|
||||
if (!buf) return 0;
|
||||
if (!server_send(cserve, OP_LOAD,
|
||||
if (!server_send(cserve, ie->channel, OP_LOAD,
|
||||
sizeof(msg) + flen + klen,
|
||||
buf))
|
||||
{
|
||||
|
@ -295,7 +323,7 @@ evas_cserve_image_load(Image_Entry *ie, const char *file, const char *key, RGBA_
|
|||
}
|
||||
free(buf);
|
||||
if (!cserve) return 0;
|
||||
rep = (Op_Load_Reply *)server_read(cserve, &opcode, &size);
|
||||
rep = (Op_Load_Reply *)server_read(cserve, ie->channel, &opcode, &size);
|
||||
if ((rep) && (opcode == OP_LOAD) && (size == sizeof(Op_Load_Reply)))
|
||||
{
|
||||
ie->w = rep->image.w;
|
||||
|
@ -332,10 +360,10 @@ evas_cserve_image_data_load(Image_Entry *ie)
|
|||
memset(&msg, 0, sizeof(msg));
|
||||
msg.handle = ie->data1;
|
||||
msg.server_id = cserve->server_id;
|
||||
if (!server_send(cserve, OP_LOADDATA, sizeof(msg), (unsigned char *)(&msg)))
|
||||
if (!server_send(cserve, ie->channel, OP_LOADDATA, sizeof(msg), (unsigned char *)(&msg)))
|
||||
return 0;
|
||||
if (!cserve) return 0;
|
||||
rep = (Op_Loaddata_Reply *)server_read(cserve, &opcode, &size);
|
||||
rep = (Op_Loaddata_Reply *)server_read(cserve, ie->channel, &opcode, &size);
|
||||
if ((rep) && (opcode == OP_LOADDATA) && (size == sizeof(Op_Loaddata_Reply)))
|
||||
{
|
||||
if (rep->mem.size <= 0)
|
||||
|
@ -369,7 +397,7 @@ evas_cserve_image_free(Image_Entry *ie)
|
|||
if (ie->connect_num == connect_num)
|
||||
{
|
||||
if (ie->server_id == cserve->server_id)
|
||||
server_send(cserve, OP_UNLOAD, sizeof(msg), (unsigned char *)(&msg));
|
||||
server_send(cserve, ie->channel, OP_UNLOAD, sizeof(msg), (unsigned char *)(&msg));
|
||||
}
|
||||
}
|
||||
ie->data1 = NULL;
|
||||
|
@ -394,7 +422,7 @@ evas_cserve_image_unload(Image_Entry *ie)
|
|||
if (ie->connect_num == connect_num)
|
||||
{
|
||||
if (ie->server_id == cserve->server_id)
|
||||
server_send(cserve, OP_UNLOADDATA, sizeof(msg), (unsigned char *)(&msg));
|
||||
server_send(cserve, ie->channel, OP_UNLOADDATA, sizeof(msg), (unsigned char *)(&msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,7 +444,7 @@ evas_cserve_image_useless(Image_Entry *ie)
|
|||
if (ie->connect_num == connect_num)
|
||||
{
|
||||
if (ie->server_id == cserve->server_id)
|
||||
server_send(cserve, OP_USELESSDATA, sizeof(msg), (unsigned char *)(&msg));
|
||||
server_send(cserve, ie->channel, OP_USELESSDATA, sizeof(msg), (unsigned char *)(&msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,8 +457,8 @@ evas_cserve_raw_config_get(Op_Getconfig_Reply *config)
|
|||
if (csrve_init > 0) server_reinit();
|
||||
else return 0;
|
||||
if (!cserve) return 0;
|
||||
if (!server_send(cserve, OP_GETCONFIG, 0, NULL)) return 0;
|
||||
rep = (Op_Getconfig_Reply *)server_read(cserve, &opcode, &size);
|
||||
if (!server_send(cserve, 0, OP_GETCONFIG, 0, NULL)) return 0;
|
||||
rep = (Op_Getconfig_Reply *)server_read(cserve, 0, &opcode, &size);
|
||||
if ((rep) && (opcode == OP_GETCONFIG) && (size == sizeof(Op_Getconfig_Reply)))
|
||||
{
|
||||
memcpy(config, rep, sizeof(Op_Getconfig_Reply));
|
||||
|
@ -447,7 +475,7 @@ evas_cserve_raw_config_set(Op_Setconfig *config)
|
|||
if (csrve_init > 0) server_reinit();
|
||||
else return 0;
|
||||
if (!cserve) return 0;
|
||||
if (!server_send(cserve, OP_SETCONFIG, sizeof(Op_Setconfig), (unsigned char *)config)) return 0;
|
||||
if (!server_send(cserve, 0, OP_SETCONFIG, sizeof(Op_Setconfig), (unsigned char *)config)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -460,8 +488,8 @@ evas_cserve_raw_stats_get(Op_Getstats_Reply *stats)
|
|||
if (csrve_init > 0) server_reinit();
|
||||
else return 0;
|
||||
if (!cserve) return 0;
|
||||
if (!server_send(cserve, OP_GETSTATS, 0, NULL)) return 0;
|
||||
rep = (Op_Getstats_Reply *)server_read(cserve, &opcode, &size);
|
||||
if (!server_send(cserve, 0, OP_GETSTATS, 0, NULL)) return 0;
|
||||
rep = (Op_Getstats_Reply *)server_read(cserve, 0, &opcode, &size);
|
||||
if ((rep) && (opcode == OP_GETSTATS) && (size == sizeof(Op_Getstats_Reply)))
|
||||
{
|
||||
memcpy(stats, rep, sizeof(Op_Getstats_Reply));
|
||||
|
@ -481,8 +509,8 @@ evas_cserve_raw_info_get(void)
|
|||
if (csrve_init > 0) server_reinit();
|
||||
else return NULL;
|
||||
if (!cserve) return NULL;
|
||||
if (!server_send(cserve, OP_GETINFO, 0, NULL)) return NULL;
|
||||
rep = (Op_Getinfo_Reply *)server_read(cserve, &opcode, &size);
|
||||
if (!server_send(cserve, 0, OP_GETINFO, 0, NULL)) return NULL;
|
||||
rep = (Op_Getinfo_Reply *)server_read(cserve, 0, &opcode, &size);
|
||||
if ((rep) && (opcode == OP_GETINFO) && (size >= sizeof(Op_Getinfo_Reply)))
|
||||
{
|
||||
return rep;
|
||||
|
|
|
@ -18,7 +18,7 @@ evas_cserve_server_add(void)
|
|||
|
||||
s = calloc(1, sizeof(Server));
|
||||
if (!s) return NULL;
|
||||
s->fd = -1;
|
||||
s->ch[0].fd = -1;
|
||||
snprintf(buf, sizeof(buf), "/tmp/.evas-cserve-%x", getuid());
|
||||
s->socket_path = strdup(buf);
|
||||
if (!s->socket_path)
|
||||
|
@ -28,34 +28,34 @@ evas_cserve_server_add(void)
|
|||
}
|
||||
pmode = umask(~(S_IRUSR | S_IWUSR));
|
||||
start:
|
||||
s->fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (s->fd < 0) goto error;
|
||||
if (fcntl(s->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
||||
if (fcntl(s->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
||||
s->ch[0].fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (s->ch[0].fd < 0) goto error;
|
||||
if (fcntl(s->ch[0].fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
||||
if (fcntl(s->ch[0].fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
||||
lin.l_onoff = 1;
|
||||
lin.l_linger = 0;
|
||||
if (setsockopt(s->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0)
|
||||
if (setsockopt(s->ch[0].fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0)
|
||||
goto error;
|
||||
socket_unix.sun_family = AF_UNIX;
|
||||
strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
|
||||
socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
|
||||
if (bind(s->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
|
||||
if (bind(s->ch[0].fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
|
||||
{
|
||||
if ((connect(s->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) &&
|
||||
if ((connect(s->ch[0].fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) &&
|
||||
(unlink(s->socket_path) >= 0))
|
||||
{
|
||||
close(s->fd);
|
||||
close(s->ch[0].fd);
|
||||
goto start;
|
||||
}
|
||||
else
|
||||
goto error;
|
||||
}
|
||||
if (listen(s->fd, 4096) < 0) goto error;
|
||||
if (listen(s->ch[0].fd, 4096) < 0) goto error;
|
||||
umask(pmode);
|
||||
return s;
|
||||
error:
|
||||
umask(pmode);
|
||||
if (s->fd >= 0) close(s->fd);
|
||||
if (s->ch[0].fd >= 0) close(s->ch[0].fd);
|
||||
free(s->socket_path);
|
||||
free(s);
|
||||
return NULL;
|
||||
|
@ -75,7 +75,7 @@ evas_cserve_server_del(Server *s)
|
|||
LKD(c->lock);
|
||||
free(c);
|
||||
}
|
||||
close(s->fd);
|
||||
close(s->ch[0].fd);
|
||||
unlink(s->socket_path);
|
||||
free(s->socket_path);
|
||||
free(s);
|
||||
|
@ -90,7 +90,7 @@ server_accept(Server *s)
|
|||
size_t size_in;
|
||||
|
||||
size_in = sizeof(struct sockaddr_in);
|
||||
new_fd = accept(s->fd, (struct sockaddr *)&incoming, (socklen_t *)&size_in);
|
||||
new_fd = accept(s->ch[0].fd, (struct sockaddr *)&incoming, (socklen_t *)&size_in);
|
||||
if (new_fd < 0) return;
|
||||
fcntl(new_fd, F_SETFL, O_NONBLOCK);
|
||||
fcntl(new_fd, F_SETFD, FD_CLOEXEC);
|
||||
|
@ -315,8 +315,8 @@ evas_cserve_server_wait(Server *s, int timeout)
|
|||
FD_ZERO(&rset);
|
||||
FD_ZERO(&wset);
|
||||
FD_ZERO(&xset);
|
||||
FD_SET(s->fd, &rset);
|
||||
if (s->fd > maxfd) maxfd = s->fd;
|
||||
FD_SET(s->ch[0].fd, &rset);
|
||||
if (s->ch[0].fd > maxfd) maxfd = s->ch[0].fd;
|
||||
EINA_LIST_FOREACH(s->clients, l, c)
|
||||
{
|
||||
FD_SET(c->fd, &rset);
|
||||
|
@ -360,7 +360,7 @@ evas_cserve_server_wait(Server *s, int timeout)
|
|||
if (c->dead) dead = eina_list_append(dead, c);
|
||||
}
|
||||
}
|
||||
if (FD_ISSET(s->fd, &rset))
|
||||
if (FD_ISSET(s->ch[0].fd, &rset))
|
||||
{
|
||||
server_accept(s);
|
||||
}
|
||||
|
|
|
@ -166,6 +166,7 @@ void *alloca (size_t);
|
|||
/* use exact rects for updates not tiles */
|
||||
/* #define RECTUPDATE */
|
||||
#define TILESIZE 8
|
||||
#define IMG_MAX_SIZE 65536
|
||||
|
||||
#ifdef BUILD_SMALL_DITHER_MASK
|
||||
# define DM_TABLE _evas_dither_44
|
||||
|
@ -477,6 +478,7 @@ struct _Image_Entry
|
|||
void *data1, *data2;
|
||||
int server_id;
|
||||
int connect_num;
|
||||
int channel;
|
||||
};
|
||||
|
||||
struct _Engine_Image_Entry
|
||||
|
|
|
@ -56,7 +56,7 @@ evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key
|
|||
}
|
||||
w = header[1];
|
||||
h = header[2];
|
||||
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
|
||||
if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
|
@ -120,7 +120,7 @@ evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key
|
|||
}
|
||||
w = header[1];
|
||||
h = header[2];
|
||||
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
|
||||
if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
|
|
|
@ -65,7 +65,7 @@ evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key
|
|||
}
|
||||
w = gif->Image.Width;
|
||||
h = gif->Image.Height;
|
||||
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
|
||||
if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
|
||||
{
|
||||
DGifCloseFile(gif);
|
||||
return 0;
|
||||
|
|
|
@ -104,7 +104,7 @@ evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f)
|
|||
/* head decoding */
|
||||
w = cinfo.output_width;
|
||||
h = cinfo.output_height;
|
||||
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
|
||||
if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
|
|
|
@ -85,7 +85,7 @@ evas_image_load_file_head_png(Image_Entry *ie, const char *file, const char *key
|
|||
png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32),
|
||||
(png_uint_32 *) (&h32), &bit_depth, &color_type,
|
||||
&interlace_type, NULL, NULL);
|
||||
if ((w32 < 1) || (h32 < 1) || (w32 > 8192) || (h32 > 8192))
|
||||
if ((w32 < 1) || (h32 < 1) || (w32 > IMG_MAX_SIZE) || (h32 > IMG_MAX_SIZE))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
goto close_file;
|
||||
|
|
|
@ -85,7 +85,7 @@ evas_image_load_file_head_svg(Image_Entry *ie, const char *file, const char *key
|
|||
rsvg_handle_get_dimensions(rsvg, &dim);
|
||||
w = dim.width;
|
||||
h = dim.height;
|
||||
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
|
||||
if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
|
||||
{
|
||||
// rsvg_handle_close(rsvg, NULL);
|
||||
g_object_unref(rsvg);
|
||||
|
@ -183,7 +183,7 @@ evas_image_load_file_data_svg(Image_Entry *ie, const char *file, const char *key
|
|||
rsvg_handle_get_dimensions(rsvg, &dim);
|
||||
w = dim.width;
|
||||
h = dim.height;
|
||||
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
|
||||
if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
|
||||
{
|
||||
// rsvg_handle_close(rsvg, NULL);
|
||||
g_object_unref(rsvg);
|
||||
|
|
|
@ -174,7 +174,7 @@ evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *ke
|
|||
if (tiff_image.alpha != EXTRASAMPLE_UNSPECIFIED)
|
||||
ie->flags.alpha = 1;
|
||||
if ((tiff_image.width < 1) || (tiff_image.height < 1) ||
|
||||
(tiff_image.width > 8192) || (tiff_image.height > 8192))
|
||||
(tiff_image.width > IMG_MAX_SIZE) || (tiff_image.height > IMG_MAX_SIZE))
|
||||
{
|
||||
TIFFClose(tif);
|
||||
return 0;
|
||||
|
|
|
@ -227,19 +227,19 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
|
|||
xpm_parse_done();
|
||||
return 0;
|
||||
}
|
||||
if ((w > 8192) || (w < 1))
|
||||
if ((w > IMG_MAX_SIZE) || (w < 1))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"XPM ERROR: Image width > 8192 or < 1 pixels for file\n");
|
||||
"XPM ERROR: Image width > IMG_MAX_SIZE or < 1 pixels for file\n");
|
||||
free(line);
|
||||
fclose(f);
|
||||
xpm_parse_done();
|
||||
return 0;
|
||||
}
|
||||
if ((h > 8192) || (h < 1))
|
||||
if ((h > IMG_MAX_SIZE) || (h < 1))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"XPM ERROR: Image height > 8192 or < 1 pixels for file\n");
|
||||
"XPM ERROR: Image height > IMG_MAX_SIZE or < 1 pixels for file\n");
|
||||
free(line);
|
||||
fclose(f);
|
||||
xpm_parse_done();
|
||||
|
|
Loading…
Reference in New Issue