示例#1
0
文件: ipcs.c 项目: ip1981/libqb
void
qb_ipcs_connection_unref(struct qb_ipcs_connection *c)
{
	int32_t free_it;

	if (c == NULL) {
		return;
	}
	if (c->refcount < 1) {
		qb_util_log(LOG_ERR, "ref:%d state:%d fd:%d",
			    c->refcount, c->state,
			    c->setup.u.us.sock);
		assert(0);
	}
	free_it = qb_atomic_int_dec_and_test(&c->refcount);
	if (free_it) {
		qb_list_del(&c->list);
		if (c->service->serv_fns.connection_destroyed) {
			c->service->serv_fns.connection_destroyed(c);
		}
		c->service->funcs.disconnect(c);
		free(c->receive_buf);
		free(c);
	}
}
示例#2
0
void
qb_log_thread_stop(void)
{
	int res;
	int value;
	struct qb_log_record *rec;

	if (wthread_active == QB_FALSE && logt_wthread_lock == NULL) {
		return;
	}
	if (wthread_active == QB_FALSE) {
		for (;;) {
			res = sem_getvalue(&logt_print_finished, &value);
			if (res != 0 || value == 0) {
				break;
			}
			sem_wait(&logt_print_finished);

			(void)qb_thread_lock(logt_wthread_lock);

			rec = qb_list_first_entry(&logt_print_finished_records,
					    struct qb_log_record, list);
			qb_list_del(&rec->list);
			logt_memory_used = logt_memory_used -
					   strlen(rec->buffer) -
					   sizeof(struct qb_log_record) - 1;
			(void)qb_thread_unlock(logt_wthread_lock);

			qb_log_thread_log_write(rec->cs, rec->timestamp,
						rec->buffer);
			free(rec->buffer);
			free(rec);
		}
	} else {
示例#3
0
文件: skiplist.c 项目: beekhof/libqb
static int32_t
skiplist_notify_del(qb_map_t * m, const char *key,
		    qb_map_notify_fn fn, int32_t events,
		    int32_t cmp_userdata, void *user_data)
{
	struct skiplist *t = (struct skiplist *)m;
	struct skiplist_node *n;
	struct qb_map_notifier *f;
	struct qb_list_head *head = NULL;
	struct qb_list_head *list;
	struct qb_list_head *next;
	int32_t found = QB_FALSE;

	if (key) {
		n = skiplist_lookup(t, key);
		if (n) {
			head = &n->notifier_head;
		}
	} else {
		head = &t->header->notifier_head;
	}
	if (head == NULL) {
		return -ENOENT;
	}
	for (list = head->next;
	     list != head; list = next) {
		f = qb_list_entry(list, struct qb_map_notifier, list);
		next = list->next;

		if (f->events == events && f->callback == fn) {
			if (cmp_userdata && (f->user_data == user_data)) {
				found = QB_TRUE;
				qb_list_del(&f->list);
				free(f);
			} else if (!cmp_userdata) {
				found = QB_TRUE;
				qb_list_del(&f->list);
				free(f);
			}
		}
	}
	if (found) {
		return 0;
	} else {
		return -ENOENT;
	}
}
示例#4
0
static void *
qb_logt_worker_thread(void *data)
{
	struct qb_log_record *rec;
	int dropped = 0;
	int res;

	/*
	 * Signal wthread_create that the initialization process may continue
	 */
	sem_post(&logt_thread_start);
	for (;;) {
retry_sem_wait:
		res = sem_wait(&logt_print_finished);
		if (res == -1 && errno == EINTR) {
			goto retry_sem_wait;
		} else if (res == -1) {
			/*
			 * This case shouldn't happen
			 */
			pthread_exit(NULL);
		}

		(void)qb_thread_lock(logt_wthread_lock);
		if (wthread_should_exit) {
			int value = -1;

			(void)sem_getvalue(&logt_print_finished, &value);
			if (value == 0) {
				(void)qb_thread_unlock(logt_wthread_lock);
				pthread_exit(NULL);
			}
		}

		rec =
		    qb_list_first_entry(&logt_print_finished_records,
				  struct qb_log_record, list);
		qb_list_del(&rec->list);
		logt_memory_used = logt_memory_used - strlen(rec->buffer) -
		    sizeof(struct qb_log_record) - 1;
		dropped = logt_dropped_messages;
		logt_dropped_messages = 0;
		(void)qb_thread_unlock(logt_wthread_lock);
		if (dropped) {
			printf("%d messages lost\n", dropped);
		}

		qb_log_thread_log_write(rec->cs, rec->timestamp, rec->buffer);
		free(rec->buffer);
		free(rec);
	}
}
示例#5
0
static void read_config_event (int sock)
{
	const char *empty = "None";
	struct qb_list_head * list = config_chg_log_head.next;
	log_entry_t *entry;
	ssize_t rc;
	size_t send_len;

	if (list != &config_chg_log_head) {
		entry = qb_list_entry (list, log_entry_t, list);
		send_len = strlen (entry->log);
		rc = send (sock, entry->log, send_len, 0);
		qb_list_del (&entry->list);
		free (entry);
	} else {
		qb_log (LOG_DEBUG, "no events in list");
		send_len = strlen (empty);
		rc = send (sock, empty, send_len, 0);
	}
	assert(rc == send_len);
}
示例#6
0
static void read_messages (int sock, char* atmost_str)
{
	struct qb_list_head * list;
	log_entry_t *entry;
	int atmost = atoi (atmost_str);
	int packed = 0;
	ssize_t rc;

	if (atmost == 0)
		atmost = 1;
	if (atmost > (HOW_BIG_AND_BUF / LOG_STR_SIZE))
		atmost = (HOW_BIG_AND_BUF / LOG_STR_SIZE);

	big_and_buf[0] = '\0';

	for (list = msg_log_head.next;
		(!qb_list_empty (&msg_log_head) && packed < atmost); ) {

		entry = qb_list_entry (list, log_entry_t, list);

		strcat (big_and_buf, entry->log);
		packed++;

		list = list->next;
		qb_list_del (&entry->list);
		free (entry);

		total_stored_msgs--;
	}
	if (packed == 0) {
		strcpy (big_and_buf, "None");
	} else {
		if ((total_stored_msgs % 1000) == 0) {
			qb_log(LOG_INFO, "sending %d; total_stored_msgs:%d; len:%d",
				packed, total_stored_msgs, (int)strlen (big_and_buf));
		}
	}
	rc = send (sock, big_and_buf, strlen (big_and_buf), 0);
	assert(rc == strlen (big_and_buf));
}
示例#7
0
文件: loop.c 项目: fjrti/libqb
static void
qb_loop_run_level(struct qb_loop_level *level)
{
	struct qb_loop_item *job;
	int32_t processed = 0;

Ill_have_another:

	if (!qb_list_empty(&level->job_head)) {
		job = qb_list_first_entry(&level->job_head, struct qb_loop_item, list);
		qb_list_del(&job->list);
		qb_list_init(&job->list);
		job->source->dispatch_and_take_back(job, level->priority);
		level->todo--;
		processed++;
		if (level->l->stop_requested) {
			return;
		}
		if (processed < level->to_process) {
			goto Ill_have_another;
		}
	}