Example #1
0
static __inline__ int32_t
init_this(network_client *nc, uint32_t factory, void *io)
{
	int32_t fd = (int32_t)io;

	nc->ip[0] = '\0';
	unix_sock_get_peer(fd, nc->ip, MAX_IP4_LEN);

	nc->factory = factory;
	nc->proto_watch = proto_watch_new(io, DEFAULT_TIMEOUT_SEC * DEFAULT_CHECK_TIMES * 1000, 
		&network_client_watch_impl, nc, proto_watch_on_finalize);
	if (!nc->proto_watch)
	{
		TRACE_WARNING("network_client()->proto_watch_new() failed.");
		unix_sock_close((int32_t)io);
		return -EINVAL;
	}

	proto_watch_set_window(nc->proto_watch, DEFAULT_PW_WINSIZE);

    obj_ref(nc); // *****
    
	nc->state = 0;
    
	nc->lock = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(nc->lock, NULL);

	return 0;
}
Example #2
0
obj_lock
#else
obj_lock_debug
#endif
(obj_id_t id, const object_type_t *assumed_type
#ifdef OBJ_DEBUG
 ,const char *file, int line
#endif
)
{
#ifdef OBJ_DEBUG
  if (assumed_type)
    fprintf(stderr,"%s:%i obj_lock(%lu, %s)\n",file,line,id,assumed_type->name);
  else
    fprintf(stderr,"%s:%i obj_lock(%lu, NULL)\n",file,line,id);
#endif  
  if (id)
    {
      unsigned int hash = hash_id(id);
      object_t *p = obj_tab[hash];
      while (p && p->id != id)
	p = p->objlist_next;
      if (p)
	obj_ref(p,assumed_type);
      return p;
    }
  else
    {
      return NULL;
    }
}
Example #3
0
media_sinker *
media_sinker_ref(media_sinker *sinker)
{
	if (sinker)
	{
		obj_ref(sinker);
	}

	return sinker;
}
Example #4
0
int objlist_insert(struct objlist *list, void *obj)
{
  if (list->size >= list->max_size)
    {
      list->max_size *= 2;
      list->items = xrealloc(list->items,
			      list->max_size*sizeof(*list->items));
    }
  list->items[list->size] = obj_ref(obj,NULL);
#ifdef OBJ_DEBUG
  printf("objlist_insert(): inserted object of type %s\n",obj_type(obj)->name);
#endif
  return list->size++;
}