evas/cserve2: Remap indexes when count is wrong

When advertised count is wrong, try to remap the index.
This will avoid errors with string_get().
This commit is contained in:
Jean-Philippe Andre 2013-08-23 18:31:30 +09:00
parent 8b39c443fe
commit 3f30fae818
2 changed files with 27 additions and 2 deletions

View File

@ -498,6 +498,8 @@ _image_loaded_msg_create(Image_Entry *ientry, Image_Data *idata, int *size)
else
idata->shm_id = cserve2_shared_string_add(shmpath);
idata->valid = EINA_TRUE;
buf = (char *)msg + sizeof(*msg);
memcpy(buf, shmpath, path_len);
@ -832,7 +834,6 @@ _load_request_response(Image_Entry *ientry,
idata = _image_data_find(ENTRYID(ientry));
if (!idata) return NULL;
idata->valid = EINA_TRUE;
_entry_load_finish(ASENTRY(ientry));
ASENTRY(ientry)->request = NULL;

View File

@ -1969,7 +1969,17 @@ _shared_index_item_get_by_id(Shared_Index *si, int elemsize, unsigned int id)
high = si->header->emptyidx; // Should be si->header->sortedidx
if (high > si->count)
high = si->count;
{
if (eina_file_refresh(si->f))
{
WRN("Refreshing indexes.");
_string_index_refresh();
_shared_index_remap_check(si, elemsize);
high = MIN(si->header->emptyidx, si->count);
}
else
high = si->count;
}
base = si->data + sizeof(Shared_Array_Header);
@ -2128,12 +2138,26 @@ _shared_index_remap_check(Shared_Index *si, int elemsize)
if (si->count != si->header->count)
{
int oldcount;
// generation_id should have been incremented. Maybe we are hitting
// a race condition here, when cserve2 grows an index.
WRN("Reported index count differs from known count: %d vs %d",
si->header->count, si->count);
oldcount = si->count;
eina_file_refresh(si->f);
filesize = eina_file_size_get(si->f);
si->count = (filesize - sizeof(Shared_Array_Header)) / elemsize;
if (si->count != oldcount)
{
DBG("Remapping current index");
eina_file_map_free(si->f, si->data);
si->data = eina_file_map_all(si->f, EINA_FILE_RANDOM);
if (!si->data)
{
ERR("Failed to remap index: %m");
return EINA_FALSE;
}
}
if (si->count > si->header->count)
{
WRN("Index reports %d elements, but file can contain only %d",