Example #1
0
static void reply_client(ACL_VSTREAM *client)
{
#define	COUNT	10
#define	SIZE	8192000
	const char *myname = "reply_client";
	struct iovec vector[COUNT];
	int   i, dlen = 0, n;

	for (i = 0; i < COUNT; i++) {
#ifdef MINGW
		vector[i].iov_base = (char*) acl_mycalloc(1,  SIZE);
#else
		vector[i].iov_base = acl_mycalloc(1,  SIZE);
#endif
		assert(vector[i].iov_base);
		vector[i].iov_len = SIZE;
		dlen += SIZE;
	}

	printf("%s: before write\n", myname);
	n = acl_vstream_writevn(client, vector, COUNT);

	for (i = 0; i < COUNT; i++) {
		acl_myfree(vector[i].iov_base);
	}

	printf("%s: writen n = %d, dlen = %d\r\n", myname, n, dlen);
}
Example #2
0
static void run_thread_pool(acl_pthread_pool_t *thr_pool)
{
	THREAD_CTX *ctx;  /* 用户自定义参数 */

	/* 设置全局静态变量 */
	__thr_pool = thr_pool;

	/* 设置线程开始时的回调函数 */
	(void) acl_pthread_pool_atinit(thr_pool, on_thread_init, thr_pool);

	/* 设置线程退出时的回调函数 */
	(void) acl_pthread_pool_atfree(thr_pool, on_thread_exit, thr_pool);

	ctx = (THREAD_CTX*) acl_mycalloc(1, sizeof(THREAD_CTX));
	assert(ctx);
	ctx->thr_pool = thr_pool;
	ctx->i = 0;

	/**
	* 向线程池中添加第一个任务,即启动第一个工作线程
	* @param wq 线程池句柄
	* @param worker_thread 工作线程的回调函数
	* @param event_type 此处写0即可
	* @param ctx 用户定义参数
	*/
	acl_pthread_pool_add(thr_pool, worker_thread, ctx);
	sleep(1);

	ctx = (THREAD_CTX*) acl_mycalloc(1, sizeof(THREAD_CTX));
	assert(ctx);
	ctx->thr_pool = thr_pool;
	ctx->i = 1;
	/* 向线程池中添加第二个任务,即启动第二个工作线程 */
	acl_pthread_pool_add(thr_pool, worker_thread, ctx);
}
Example #3
0
void locker::init_mutex(bool use_spinlock acl_unused)
{

#ifdef	ACL_HAS_SPINLOCK
	if (use_spinlock)
	{
		spinlock_ = (pthread_spinlock_t*)
			acl_mycalloc(1, sizeof(pthread_spinlock_t));
		pthread_spin_init(spinlock_, PTHREAD_PROCESS_PRIVATE);
		mutex_= NULL;
		return;
	}
	else
		spinlock_ = NULL;
#endif

	mutex_ = (acl_pthread_mutex_t*)
		acl_mycalloc(1, sizeof(acl_pthread_mutex_t));
#ifdef ACL_WINDOWS
	acl_assert(acl_pthread_mutex_init(mutex_, NULL) == 0);
#else
	acl_assert(pthread_mutexattr_init(&mutex_attr_) == 0);
	acl_assert(pthread_mutexattr_settype(&mutex_attr_,
				PTHREAD_MUTEX_RECURSIVE) == 0);
	acl_assert(acl_pthread_mutex_init(mutex_, &mutex_attr_) == 0);
#endif
}
Example #4
0
static void event_init(ACL_EVENT *eventp, int fdsize,
	int delay_sec, int delay_usec)
{
	eventp->fdsize = fdsize;
	/* eventp->fdtab_free_cnt = 0; */
	eventp->fdcnt  = 0;
	eventp->fdcnt_ready  = 0;
	eventp->fdtabs = (ACL_EVENT_FDTABLE **)
		acl_mycalloc(fdsize,sizeof(ACL_EVENT_FDTABLE *));
	eventp->fdtabs_ready = (ACL_EVENT_FDTABLE **)
		acl_mycalloc(fdsize, sizeof(ACL_EVENT_FDTABLE *));

	eventp->maxfd  = 0;
	eventp->nested = 0;

	eventp->delay_sec  = delay_sec + delay_usec / 1000000;
	eventp->delay_usec = delay_usec % 1000000;

	acl_ring_init(&eventp->timer_head);
	eventp->timer_keep = 0;
	SET_TIME(eventp->present);
	SET_TIME(eventp->last_debug);

	eventp->check_inter = 100000;  /* default: 100 ms */

	if (eventp->init_fn)
		eventp->init_fn(eventp);
}
Example #5
0
static void fiber_check(void)
{
	if (__thread_fiber != NULL)
		return;

	acl_assert(acl_pthread_once(&__once_control, thread_init) == 0);

	__thread_fiber = (FIBER_TLS *) acl_mycalloc(1, sizeof(FIBER_TLS));
#ifdef	USE_JMP
	/* set context NULL when using setjmp that setcontext will not be
	 * called in fiber_swap.
	 */
	__thread_fiber->original.context = NULL;
#else
	__thread_fiber->original.context = (ucontext_t *)
		acl_mycalloc(1, sizeof(ucontext_t));
#endif
	__thread_fiber->fibers = NULL;
	__thread_fiber->size   = 0;
	__thread_fiber->slot   = 0;
	__thread_fiber->idgen  = 0;
	__thread_fiber->count  = 0;

	acl_ring_init(&__thread_fiber->ready);
	acl_ring_init(&__thread_fiber->dead);

	if ((unsigned long) acl_pthread_self() == acl_main_thread_self()) {
		__main_fiber = __thread_fiber;
		atexit(fiber_schedule_main_free);
	} else if (acl_pthread_setspecific(__fiber_key, __thread_fiber) != 0)
		acl_msg_fatal("acl_pthread_setspecific error!");
}
Example #6
0
static int _cfg_line_dump(ACL_FILE_HANDLE filefd, const ACL_CFG_LINE *cfg_line, const char *delimiter)
{
	char  myname[] = "_cfg_line_dump";
	char *pbuf, *ptr;
	int   dlen = 0, i, j,  n;
	char  tbuf[256];

	n = cfg_line->ncount;
	if (delimiter != NULL)
		j = (int) strlen(delimiter);
	else
		j = 0;

	if (cfg_line->value != NULL) {
		for (i = 0; i < n; i++) {
			if (cfg_line->value[i] == NULL)
				break;
			dlen += (int) strlen(cfg_line->value[i]) + j;
		}
		dlen += 2;   /* for '\n' and '\0' */
		pbuf = (char *) acl_mycalloc(1, dlen);
		ptr = pbuf;
		for (i = 0; i < n; i++) {
			if (cfg_line->value[i] == NULL)
				break;
			if (i < n -1)
				sprintf(ptr, "%s%s", cfg_line->value[i], delimiter);
			else
				sprintf(ptr, "%s", cfg_line->value[i]);
			ptr = ptr + strlen(ptr);
		}
		ptr = ptr + strlen(ptr);
		strcat(ptr, "\n\0");
		i = acl_file_write(filefd, pbuf, strlen(pbuf), 0, NULL, NULL);
		if (i <= 0) {
			printf("%s: can't write pbuf, error=%s\n",
				myname, acl_last_strerror(tbuf, sizeof(tbuf)));
			acl_myfree(pbuf);
			return (-1);
		}
	} else if (cfg_line->pdata != NULL) {
		dlen = (int) strlen(cfg_line->pdata) + 2;
		pbuf = (char *) acl_mycalloc(1, dlen);
		if (pbuf == NULL)
			return (-1);
		sprintf(pbuf, "%s\n", cfg_line->pdata);
		i = acl_file_write(filefd, pbuf, strlen(pbuf), 0, NULL, NULL);
		if (i <= 0)
			return (-1);
	}

	return (0);
}
Example #7
0
http_header& http_header::add_param(const char* name, const char* value)
{
	if (name == NULL || *name == 0)
		return *this;

	std::list<HTTP_PARAM*>::iterator it = params_.begin();
	for (; it != params_.end(); ++it)
	{
		if (strcasecmp((*it)->name, name) == 0)
		{
			if ((*it)->value)
				acl_myfree((*it)->value);
			if (value)
				(*it)->value = acl_mystrdup(value);
			else
				(*it)->value = NULL;
			return *this;
		}
	}

	HTTP_PARAM* param = (HTTP_PARAM*) acl_mycalloc(1, sizeof(HTTP_PARAM));
	param->name = acl_mystrdup(name);
	if (value)
		param->value = acl_mystrdup(value);
	else
		param->value = NULL;
	params_.push_back(param);
	return *this;
}
Example #8
0
ACL_DBUF_POOL *acl_dbuf_pool_create(int block_size)
{
#ifdef	USE_VALLOC
	ACL_DBUF_POOL *pool = (ACL_DBUF_POOL*) valloc(sizeof(ACL_DBUF_POOL));
	memset(pool, 0, sizeof(ACL_DBUF_POOL));
#else
	ACL_DBUF_POOL *pool = (ACL_DBUF_POOL*) acl_mycalloc(1,
			sizeof(ACL_DBUF_POOL));
#endif
	int   size, page_size;

#ifdef ACL_UNIX
	page_size = getpagesize();
#elif defined(WIN32)
	SYSTEM_INFO info;

	memset(&info, 0, sizeof(SYSTEM_INFO));
	GetSystemInfo(&info);
	page_size = info.dwPageSize;
	if (page_size <= 0)
		page_size = 4096;
#else
	page_size = 4096;
#endif

	size = (block_size / page_size) * page_size;
	if (size == 0)
		size = page_size;

	pool->block_size = size;
	pool->head = NULL;
	return pool;
}
Example #9
0
ACL_MBOX *acl_mbox_create(void)
{
	ACL_MBOX *mbox;
	ACL_SOCKET fds[2];

	if (acl_sane_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
		acl_msg_error("%s(%d), %s: acl_duplex_pipe error %s",
			__FILE__, __LINE__, __FUNCTION__, acl_last_serror());
		return NULL;
	}

	mbox        = (ACL_MBOX *) acl_mymalloc(sizeof(ACL_MBOX));
	mbox->in    = acl_vstream_fdopen(fds[0], O_RDONLY, sizeof(__key),
			0, ACL_VSTREAM_TYPE_SOCK);
	mbox->out   = acl_vstream_fdopen(fds[1], O_WRONLY, sizeof(__key),
			0, ACL_VSTREAM_TYPE_SOCK);
	mbox->nsend = 0;
	mbox->nread = 0;
	mbox->ypipe = acl_ypipe_new();
	mbox->lock  = (acl_pthread_mutex_t *)
		acl_mycalloc(1, sizeof(acl_pthread_mutex_t));
	if (acl_pthread_mutex_init(mbox->lock, NULL) != 0)
		acl_msg_fatal("%s(%d), %s: acl_pthread_mutex_init error",
			__FILE__, __LINE__, __FUNCTION__);

	return mbox;
}
Example #10
0
ACL_ARRAY *acl_array_create(int init_size)
{
	int   ret;
	ACL_ARRAY *a;

	a = (ACL_ARRAY *) acl_mycalloc(1, sizeof(ACL_ARRAY));

	a->push_back = array_push_back;
	a->push_front = array_push_front;
	a->pop_back = array_pop_back;
	a->pop_front = array_pop_front;
	a->iter_head = array_iter_head;
	a->iter_next = array_iter_next;
	a->iter_tail = array_iter_tail;
	a->iter_prev = array_iter_prev;

	if(init_size > 0) {
		ret = acl_array_pre_append(a, init_size);
		if(ret < 0) {
			acl_myfree(a);
			return(NULL);
		}
	}

	return(a);
}
Example #11
0
redis_client_cluster::redis_client_cluster(int max_slot /* = 16384 */)
: max_slot_(max_slot)
, redirect_max_(15)
, redirect_sleep_(100)
{
	slot_addrs_ = (const char**) acl_mycalloc(max_slot_, sizeof(char*));
}
Example #12
0
PROCTL_MSG *proctl_msg_new(int msg_type)
{
	PROCTL_MSG *msg = (PROCTL_MSG *) acl_mycalloc(1, sizeof(PROCTL_MSG));

	msg->msg_type = msg_type;
	return (msg);
}
Example #13
0
/**
 * 创建索引
 */
static ACL_MDT_IDX *mdt_idx_create(ACL_MDT *mdt, size_t init_capacity,
	const char *name, unsigned int flag)
{
	ACL_MDT_IDX_BHASH *idx;
	unsigned int flag2 = 0;

	if (init_capacity < 128)
		init_capacity = 128;
	idx = (ACL_MDT_IDX_BHASH*) acl_mycalloc(1, sizeof(ACL_MDT_IDX_BHASH));

	if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE1))
		flag2 |= ACL_BINHASH_FLAG_SLICE1;
	else if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE2))
		flag2 |= ACL_BINHASH_FLAG_SLICE2;
	else if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE3))
		flag2 |= ACL_BINHASH_FLAG_SLICE3;

	if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE_RTGC_OFF))
		flag2 |= ACL_BINHASH_FLAG_SLICE_RTGC_OFF;
	if ((flag & ACL_MDT_FLAG_KMR))
		flag2 |= ACL_BINHASH_FLAG_KEY_REUSE;

	idx->table = acl_binhash_create(init_capacity, flag2);
	idx->idx.name = acl_mystrdup(name);
	idx->idx.flag = flag;
	return ((ACL_MDT_IDX*) idx);
}
Example #14
0
File: rpc.cpp Project: 2202877/acl
rpc_request::rpc_request()
: ipc_(NULL)
, wait_timedout_(false)
{
	dat_.req = this;
	dat_.ctx = NULL;

	cond_count_ = 0;
	cond_ = (acl_pthread_cond_t*) acl_mycalloc(
		1, sizeof(acl_pthread_cond_t));
	acl_pthread_cond_init(cond_, NULL);

	lock_ = (acl_pthread_mutex_t*) acl_mycalloc(
		1, sizeof(acl_pthread_mutex_t));
	acl_pthread_mutex_init(lock_, NULL);
}
Example #15
0
static ACL_CFG_LINE *_backup_junk_line(const char *ptr)
{
	char  myname[] = "_backup_junk_line";
	ACL_CFG_LINE *cfg_line;
	char  tbuf[256];

	if (ptr == NULL)
		return (NULL);

	cfg_line = (ACL_CFG_LINE *) acl_mycalloc(1, sizeof(ACL_CFG_LINE));
	if (cfg_line == NULL) {
		printf("%s: calloc ACL_CFG_LINE, errmsg=%s",
				myname, acl_last_strerror(tbuf, sizeof(tbuf)));
		return (NULL);
	}

	cfg_line->ncount = 0;
	cfg_line->value = NULL;
	cfg_line->pdata = acl_mystrdup(ptr);
	if (cfg_line->pdata == NULL) {
		printf("%s: strdup pdata, errmsg=%s",
				myname, acl_last_strerror(tbuf, sizeof(tbuf)));
		return (NULL);
	}

	return (cfg_line);
}
Example #16
0
void acl_netdb_add_addr(ACL_DNS_DB *dns_db, const char *ip, int hport)
{
	const char *myname = "acl_netdb_add_addr";
	ACL_HOSTNAME *phost;
	char  buf[256];

	if (dns_db == NULL || dns_db->h_db == NULL || ip == NULL) {
		acl_msg_error("%s(%d): input invalid", myname, __LINE__);
		return;
	}

	phost = acl_mycalloc(1, sizeof(ACL_HOSTNAME));
	if (phost == NULL) {
		acl_msg_error("%s(%d): calloc error(%s)",
			myname, __LINE__, acl_last_strerror(buf, sizeof(buf)));
		return;
	}

	memset(&phost->saddr, 0, sizeof(phost->saddr));
	ACL_SAFE_STRNCPY(phost->ip, ip, sizeof(phost->ip));
	phost->saddr.sin_addr.s_addr = (unsigned long) inet_addr(ip);
	phost->hport = hport;

	if (acl_array_append(dns_db->h_db, phost) < 0) {
		acl_msg_error("%s(%d): array append error(%s)",
			myname, __LINE__, acl_last_strerror(buf, sizeof(buf)));
		return;
	}

	dns_db->size++;
}
Example #17
0
HTTP_UTIL *http_util_res_new(int status)
{
	HTTP_UTIL *http_util = (HTTP_UTIL*) acl_mycalloc(1, sizeof(HTTP_UTIL));

	http_util->hdr_res = http_hdr_res_static(status);
	return (http_util);
}
Example #18
0
ACL_DNS_DB *acl_netdb_new(const char *domain)
{
	const char *myname = "acl_netdb_new";
	ACL_DNS_DB *dns_db;
	char  buf[256];

	dns_db = acl_mycalloc(1, sizeof(ACL_DNS_DB));
	if (dns_db == NULL) {
		acl_msg_error("%s, %s(%d): calloc error(%s)",
			__FILE__, myname, __LINE__,
			acl_last_strerror(buf, sizeof(buf)));
		return (NULL);
	}

	dns_db->h_db = acl_array_create(5);
	if (dns_db->h_db == NULL) {
		acl_msg_error("%s, %s(%d): create array error(%s)",
			__FILE__, myname, __LINE__,
			acl_last_strerror(buf, sizeof(buf)));
		acl_myfree(dns_db);
		return (NULL);
	}

	snprintf(dns_db->name, sizeof(dns_db->name), "%s", domain);
	acl_lowercase(dns_db->name);

	dns_db->iter_head = netdb_iter_head;
	dns_db->iter_next = netdb_iter_next;
	dns_db->iter_tail = netdb_iter_tail;
	dns_db->iter_prev = netdb_iter_prev;
	dns_db->iter_info = netdb_iter_info;

	return (dns_db);
}
Example #19
0
/*----------------------------------------------------------------------------*/
ACL_DB_POOL *acl_dbpool_mysql_create(const ACL_DB_INFO *db_info)
{
	char  myname[] = "acl_dbpool_mysql_create";
	ACL_DB_POOL_MYSQL *mysql_pool;

	mysql_pool = (ACL_DB_POOL_MYSQL *) acl_mycalloc(1, sizeof(ACL_DB_POOL_MYSQL));
	if (mysql_pool == NULL) {
		char  tbuf[256];
		acl_msg_fatal("%s, %s(%d): calloc error=%s",
			__FILE__, myname, __LINE__, acl_last_strerror(tbuf, sizeof(tbuf)));
	}

	mysql_pool->db_pool.dbh_peek    = &__dbpool_mysql_peek;
	mysql_pool->db_pool.dbh_check   = &__dbpool_mysql_check;
	mysql_pool->db_pool.dbh_release = &__dbpool_mysql_release;
	mysql_pool->db_pool.dbh_export  = &__dbpool_mysql_export;
	mysql_pool->db_pool.dbh_close   = &__dbpool_mysql_close;

	mysql_pool->db_pool.destroy     = &__dbpool_mysql_destroy;

	mysql_pool->handles  = acl_array_create(db_info->db_max);
	acl_pthread_mutex_init(&mysql_pool->mutex, NULL);

	return ((ACL_DB_POOL *) mysql_pool);
}
Example #20
0
thread_mutex::thread_mutex(bool recursive /* = true */)
{
	mutex_ = (acl_pthread_mutex_t*)
		acl_mycalloc(1, sizeof(acl_pthread_mutex_t));

#ifdef	ACL_UNIX
	int ret = pthread_mutexattr_init(&mutex_attr_);
	if (ret)
	{
		SET_ERRNO(ret);
		logger_fatal("pthread_mutexattr_init error=%s", last_serror());
	}
	if (recursive && (ret = pthread_mutexattr_settype(&mutex_attr_,
					PTHREAD_MUTEX_RECURSIVE)))
	{
		SET_ERRNO(ret);
		logger_fatal("pthread_mutexattr_settype error=%s", last_serror());
	}
	ret = acl_pthread_mutex_init(mutex_, &mutex_attr_);
	if (ret)
	{
		SET_ERRNO(ret);
		logger_fatal("pthread_mutex_init error=%s", last_serror());
	}
#else
	(void) recursive;
	int ret = acl_pthread_mutex_init(mutex_, NULL);
	if (ret)
	{
		SET_ERRNO(ret);
		logger_fatal("pthread_mutex_init error=%s", last_serror());
	}
#endif
}
Example #21
0
ACL_EVENT_FDTABLE *event_fdtable_alloc()
{
	ACL_EVENT_FDTABLE *fdp = acl_mycalloc(1, sizeof(ACL_EVENT_FDTABLE));
	fdp->fdidx = -1;
	fdp->fdidx_ready = -1;
	return (fdp);
}
Example #22
0
void acl_netdb_add_addr(ACL_DNS_DB *db, const char *ip, int hport)
{
	ACL_HOSTNAME *phost;
	ACL_SOCKADDR  saddr;

	if (db == NULL || db->h_db == NULL || ip == NULL) {
		acl_msg_error("%s(%d): input invalid", __FUNCTION__, __LINE__);
		return;
	}

	memset(&saddr, 0, sizeof(saddr));

	if (ip2addr(ip, 0, &saddr) == 0) {
		acl_msg_error("%s(%d): invalid ip=%s",
			__FUNCTION__, __LINE__, ip);
		return;
	}

	phost = acl_mycalloc(1, sizeof(ACL_HOSTNAME));
	memcpy(&phost->saddr, &saddr, sizeof(phost->saddr));
	ACL_SAFE_STRNCPY(phost->ip, ip, sizeof(phost->ip));
	phost->hport = hport;

	(void) acl_array_append(db->h_db, phost);
	db->size++;
}
Example #23
0
ACL_DNS_DB *acl_netdb_clone(const ACL_DNS_DB *db)
{
	ACL_DNS_DB *dbp;
	ACL_HOSTNAME *phost, *h_host;
	int  i, n;

	if (db == NULL || db->h_db == NULL)
		return NULL;

	n = acl_array_size(db->h_db);
	if (n <= 0) {
		acl_msg_error("%s, %s(%d): h_db's size(%d) <= 0",
			__FILE__, __FUNCTION__, __LINE__, n);
		return NULL;
	}

	dbp = acl_netdb_new(db->name);

	for (i = 0; i < n; i++) {
		phost = (ACL_HOSTNAME *) acl_array_index(db->h_db, i);
		acl_assert(phost);

		h_host = acl_mycalloc(1, sizeof(ACL_HOSTNAME));
		memcpy(&h_host->saddr, &phost->saddr, sizeof(h_host->saddr));
		ACL_SAFE_STRNCPY(h_host->ip, phost->ip, sizeof(h_host->ip));
		h_host->hport = phost->hport;

		(void) acl_array_append(dbp->h_db, h_host);
		dbp->size++;
	}

	return dbp;
}
Example #24
0
acl_pthread_mutex_t *acl_pthread_mutex_create(void)
{
	const char *myname = "acl_pthread_mutex_create";
	acl_pthread_mutex_t *mutex;

	mutex = acl_mycalloc(1, sizeof(acl_pthread_mutex_t));
	if (mutex == NULL) {
		acl_msg_error("%s, %s(%d): calloc error(%s)",
			__FILE__, myname, __LINE__, acl_last_serror());
		return NULL;
	}

	mutex->dynamic = 1;

	/* Create the mutex, with initial value signaled */
	mutex->id = CreateMutex(NULL, FALSE, NULL);
	if (!mutex->id) {
		acl_msg_error("%s, %s(%d): CreateMutex error(%s)",
			__FILE__, myname, __LINE__, acl_last_serror());
		acl_myfree(mutex);
		return NULL;
	}

	return mutex;
}
Example #25
0
File: main.c Project: 10jschen/acl
static void init(void)
{
#ifdef	USE_LOG
	char logfile[] = "test.log";
	char logpre[] = "thread_test";
#endif

	int   i;

	if (__use_slice)
		acl_mem_slice_init(8, 10240, 100000,
			ACL_SLICE_FLAG_GC2 | ACL_SLICE_FLAG_RTGC_OFF | ACL_SLICE_FLAG_LP64_ALIGN);

	acl_init();
#ifdef	USE_LOG
	acl_msg_open(logfile, logpre);
#endif

	if (__send_size <= 0)
		__send_size = 100;

	__data = acl_mycalloc(1, __send_size);
	assert(__data);

	for (i = 0; i < __send_size - 2; i++) {
		__data[i] = 'i';
	}

	__data[i++] = '\n';
	__data[i] = 0;

	echo_server_init(__data, (int) strlen(__data),
		__echo_src, __line_length);
}
Example #26
0
ICMP_CHAT *icmp_chat_create(ACL_AIO* aio, int check_tid)
{
	ICMP_CHAT *chat;

	chat = (ICMP_CHAT*) acl_mycalloc(1, sizeof(ICMP_CHAT));
	chat->aio = aio;
	acl_ring_init(&chat->host_head);
	chat->is = icmp_stream_open(aio);
	chat->seq_no = 0;
	chat->count = 0;
#ifdef ACL_UNIX
	chat->pid = getpid();
#elif defined(ACL_WINDOWS)
	chat->pid = _getpid();
#endif
	chat->tid = (unsigned long) acl_pthread_self();
	chat->check_tid = check_tid;

	if (aio != NULL)
		icmp_chat_aio_init(chat, aio);
	else
		icmp_chat_sio_init(chat);

	return (chat);
}
Example #27
0
void fiber_io_check(void)
{
	if (__thread_fiber != NULL)
		return;

	acl_assert(acl_pthread_once(&__once_control, thread_init) == 0);

	__maxfd = acl_open_limit(0);
	if (__maxfd <= 0)
		__maxfd = MAXFD;

	__thread_fiber = (FIBER_TLS *) acl_mymalloc(sizeof(FIBER_TLS));
	__thread_fiber->event = event_create(__maxfd);
	__thread_fiber->io_fibers = (ACL_FIBER **)
		acl_mycalloc(__maxfd, sizeof(ACL_FIBER *));
	__thread_fiber->ev_fiber = acl_fiber_create(fiber_io_loop,
			__thread_fiber->event, STACK_SIZE);
	__thread_fiber->io_count = 0;
	__thread_fiber->nsleeping = 0;
	__thread_fiber->io_stop = 0;
	acl_ring_init(&__thread_fiber->ev_timer);

	if ((unsigned long) acl_pthread_self() == acl_main_thread_self()) {
		__main_fiber = __thread_fiber;
		atexit(fiber_io_main_free);
	} else if (acl_pthread_setspecific(__fiber_key, __thread_fiber) != 0)
		acl_msg_fatal("acl_pthread_setspecific error!");
}
Example #28
0
void domain_info::add_ip(const char* ip, int ttl)
{
	IP_INFO* info = (IP_INFO*) acl_mycalloc(1, sizeof(IP_INFO));
	ACL_SAFE_STRNCPY(info->ip, ip, sizeof(info->ip));
	info->ttl = ttl;
	ip_list_.push_back(info);
}
Example #29
0
/**
 * 创建索引
 */
static ACL_MDT_IDX *mdt_idx_create(ACL_MDT *mdt, size_t init_capacity acl_unused,
	const char *name, unsigned int flag)
{
	ACL_MDT_IDX_AVL *idx;
#ifdef	_LP64
	unsigned int slice_align = ACL_SLICE_FLAG_LP64_ALIGN;
#else
	unsigned int slice_align = 0;
#endif
	unsigned int rtgc_off = 0;

	idx = (ACL_MDT_IDX_AVL*) acl_mycalloc(1, sizeof(ACL_MDT_IDX_AVL));
	avl_create(&idx->avl, cmp_fn, sizeof(TREE_NODE), offsetof(TREE_NODE, node));

	if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE_RTGC_OFF))
		rtgc_off = 1;

	if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE1))
		idx->slice = acl_slice_create("ACL_MDT_IDX_AVL->slice", 0,
			sizeof(TREE_NODE), ACL_SLICE_FLAG_GC1 | slice_align | rtgc_off);
	else if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE2))
		idx->slice = acl_slice_create("ACL_MDT_IDX_AVL->slice", 0,
			sizeof(TREE_NODE), ACL_SLICE_FLAG_GC2 | slice_align | rtgc_off);
	else if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE3))
		idx->slice = acl_slice_create("ACL_MDT_IDX_AVL->slice", 0,
			sizeof(TREE_NODE), ACL_SLICE_FLAG_GC3 | slice_align | rtgc_off);

	idx->idx.name = acl_mystrdup(name);
	idx->idx.flag = flag;
	return ((ACL_MDT_IDX*) idx);
}
Example #30
0
bool polarssl_conf::add_cert(const char* crt_file)
{
	if (crt_file == NULL || *crt_file == 0)
	{
		logger_error("crt_file null");
		return false;
	}

#ifdef HAS_POLARSSL
	if (cert_chain_ == NULL)
	{
		cert_chain_ = acl_mycalloc(1, sizeof(_X509_CERT));
		_X509_INIT_FN((_X509_CERT*) cert_chain_);
	}

	int ret = _X509_PARSE_FILE_FN((_X509_CERT*) cert_chain_, crt_file);
	if (ret != 0)
	{
		logger_error("x509_crt_parse_file(%s) error: -0x%04x",
			crt_file, ret);

		_X509_FREE_FN((_X509_CERT*) cert_chain_);
		acl_myfree(cert_chain_);
		cert_chain_ = NULL;
		return false;
	}

	return true;
#else
	(void) crt_file;
	logger_error("HAS_POLARSSL not defined!");
	return false;
#endif
}