Example #1
0
void shmap_print(shmap_t *h, shbuf_t *ret_buff)
{
  shmap_entry_t *ent;
  shmap_value_t mval;
  shmap_index_t *hi;
  shkey_t *key;
  char buf[256];
  char *val;
  char str[4096];
  ssize_t len;
  int flag;
  int idx;
  int i;

  if (!h || !ret_buff)
    return; /* all done */

  i = 0;

  for (hi = shmap_first(h); hi; hi = shmap_next(hi)) {
    shmap_self(hi, &key, &val, &len, &flag);
    if (!len || !val)
      continue;

    flag &= ~SHMAP_ALLOC;

    memset(&mval, 0, sizeof(mval));
    memcpy(&mval.name, key, sizeof(mval.name));
    mval.magic = SHMEM32_MAGIC;
    mval.stamp = shtime();
    mval.crc = shcrc(val, len); 
    mval.pf = flag;
    mval.sz = len;

    shbuf_cat(ret_buff, &mval, sizeof(shmap_value_t));
    shbuf_cat(ret_buff, val, len);

#if 0
    hdr = (shmap_value_t *)val;
    memcpy(&hdr->name, key, sizeof(shkey_t));
    shbuf_cat(ret_buff, hdr, sizeof(shmap_value_t));
    shbuf_cat(ret_buff, ((char *)val + sizeof(shmap_value_t)), hdr->sz);
#endif

    i++;
  }

}
Example #2
0
/*
 * Expanding a hash table
 */
static void _expand_array(shmap_t *ht)
{
  shmap_index_t *hi;
  shmap_entry_t **new_array;
  unsigned int new_max;

  new_max = ht->max * 2;
  new_array = alloc_array(ht, new_max);
  for (hi = shmap_first(ht); hi; hi = shmap_next(hi)) {
    unsigned int i = hi->tthis->hash & new_max;
    hi->tthis->next = new_array[i];
    new_array[i] = hi->tthis;
  }
  if (ht->array)
    free(ht->array);
  ht->array = new_array;
  ht->max = new_max;
}
Example #3
0
int sexe_event_handle(lua_State *L, int e_type, shjson_t *json)
{
  const shmap_t *h = event_map;
  shmap_index_t *hi;
  sexe_event_t *event;
  char *key;
  char *val;
  size_t len;
  int flag;

  for (hi = shmap_first(h); hi; hi = shmap_next(hi)) {
    shmap_self(hi,(void*) &key, (void*) &val, &len, &flag);
    if (!(flag & SHMAP_BINARY))
      continue;

    event = (sexe_event_t *)val;
    if (event->event_type != e_type)
      continue; /* wrong event type */

    sexe_event_call(L, shkey_hex(&event->reg_key), e_type, json);
  }

}