Example #1
0
static TOGO_M_CACHE_CHUNK * togo_m_cache_create_chunk(TOGO_M_CACHE_AREA * area)
{
	TOGO_M_CACHE_CHUNK * chunk;
	u_char * p;

	chunk = (TOGO_M_CACHE_CHUNK *) togo_pool_calloc(togo_m_cache_pool,
			sizeof(TOGO_M_CACHE_CHUNK));
	if (chunk == NULL) {
		togo_log(INFO, "create modules_cache's chunk fail.");
		return NULL;
	}

	p = (u_char *) togo_pool_alloc(togo_m_cache_pool,
			sizeof(u_char) * TOGO_M_CACHE_CHUNK_SIZE);
	if (p == NULL) {
		togo_log(INFO, "create modules_cache's chunk fail.");
		return NULL;
	}

	chunk->area = area;
	chunk->next = NULL;
	chunk->prev = NULL;
	chunk->p = p;

	togo_m_cache->total_size += TOGO_M_CACHE_CHUNK_SIZE;

	return chunk;

}
Example #2
0
static void togo_wt_setup(TOGO_WORKER_THREAD *worker_thread)
{

	int pipe_fds[2];
	if (pipe(pipe_fds) < 0) {
		togo_log(ERROR, "Can't create pipe.");
		togo_exit();
	}

	worker_thread->notify_receive_fd = pipe_fds[0];
	worker_thread->notify_send_fd = pipe_fds[1];

	if (pthread_mutex_init(&worker_thread->mutex_lock, NULL) != 0) {
		togo_log(ERROR, "Can't init pthread mutex lock.");
		togo_exit();
	}

	togo_q_init(worker_thread);

	worker_thread->base = event_base_new();
	if (!worker_thread->base) {
		togo_log(ERROR, "Can't alloc event base.");
		togo_exit();
	}

	worker_thread->pipe_event = event_new(worker_thread->base,
			worker_thread->notify_receive_fd, EV_READ | EV_PERSIST,
			togo_wt_process, worker_thread);
	event_add(worker_thread->pipe_event, NULL);

}
Example #3
0
//togo_pool.c
void togo_pool_test()
{
	togo_log(DEBUG, "Testing togo_pool.c start ============================");
	void * p;
	void * p1;

	//togo_pool_create
	TOGO_POOL * pool = togo_pool_create(10 * 1024);
	if (pool->total_size == 10288 && pool->max == 10 * 1024) {
		togo_log(DEBUG,
				"Testing function:togo_pool_create .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_pool_create .............................FAIL");
		togo_exit();
	}

	//togo_pool_calloc
	p1 = togo_pool_calloc(pool, 10 * 1024);
	p = togo_pool_calloc(pool, 10);
	togo_strcpy(p, "woshishen");
	if (strcmp(p, "woshishen") == 0 && togo_strlen(p) == 9
			&& pool->large->size == 10 * 1024) {
		togo_log(DEBUG,
				"Testing function:togo_pool_calloc .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_pool_calloc .............................FAIL");
		togo_exit();
	}

	//togo_pool_realloc(pool, 20);
	p = togo_pool_realloc(pool, (void *) p, 10, 15);
	togo_strcpy(p, "woshishen11234");
	if (strcmp(p, "woshishen11234") == 0 && togo_strlen(p) == 14) {
		togo_log(DEBUG,
				"Testing function:togo_pool_realloc .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_pool_realloc .............................FAIL");
		togo_exit();
	}

	//togo_pool_free_data
	togo_pool_free_data(pool, (void *) p);
	togo_pool_free_large(pool, (void *) p1);

	if (pool->large == NULL) {
		togo_log(DEBUG,
				"Testing function:togo_pool_free_large .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_pool_free_large .............................FAIL");
		togo_exit();
	}
	togo_log(DEBUG, "Testing togo_pool.c end ============================\r\n");
}
Example #4
0
static void * togo_mt_process(void* args)
{
	struct event_base *base_ev;
	struct event *ev;
	evutil_socket_t server_socketfd;
	struct sockaddr_in server_addr;

	togo_memzero(&server_addr, sizeof(server_addr));
	server_addr.sin_family = AF_INET;

	if (strcmp(togo_global_c->ip, TOGO_C_DEFAULT_IP) == 0) {
		server_addr.sin_addr.s_addr = INADDR_ANY;
	} else {
		server_addr.sin_addr.s_addr = inet_addr(togo_global_c->ip);
	}

	if (togo_global_c->port == 0) {
		server_addr.sin_port = htons(TOGO_C_DEFAULT_PORT);
	} else {
		server_addr.sin_port = htons(togo_global_c->port);
	}

	server_socketfd = socket(PF_INET, SOCK_STREAM, 0);
	if (server_socketfd < 0) {
		togo_log(ERROR, "Socket error.");
		togo_exit();
	}

	evutil_make_listen_socket_reuseable(server_socketfd);
	evutil_make_socket_nonblocking(server_socketfd);

	BOOL is_set = togo_wt_set_socket_opt(server_socketfd);
	if (is_set == FALSE) {
		togo_log(ERROR, "togo_wt_set_socket_opt error.");
		togo_exit();
	}

	if (bind(server_socketfd, (struct sockaddr *) &server_addr,
			sizeof(struct sockaddr)) < 0) {
		togo_log(ERROR, "bind error.");
		togo_exit();
	}

	listen(server_socketfd, 32);
	togo_log(INFO, "Togo Server Start.......");

	/* event_base */
	base_ev = event_base_new();
	ev = event_new(base_ev, server_socketfd, EV_TIMEOUT | EV_READ | EV_PERSIST,
			togo_mt_doaccept, base_ev);

	event_add(ev, NULL);
	event_base_dispatch(base_ev); //loop
	event_base_free(base_ev);

}
Example #5
0
int togo_wt_send_cb(TOGO_THREAD_ITEM * socket_item)
{
	int ret;
	char int_str[12];

	/* If sstatus equal to 3, send the big data! */
	if (socket_item->sstatus == 3) {

		BDATA_CALLBACK callback;
		if (socket_item->bsbuf == NULL || socket_item->bssize == 0) {
			return 0;
		}

		togo_itoa((uint32_t) socket_item->bssize, int_str, 10);

		/**
		 * Retrun:TOGO_S10TOGO_E/r/nAAAAAAAAAA
		 */
		ret = bufferevent_write(socket_item->bev, TOGO_SBUF_START,
				togo_strlen(TOGO_SBUF_START));
		ret = bufferevent_write(socket_item->bev, int_str,
				togo_strlen(int_str));
		ret += bufferevent_write(socket_item->bev, TOGO_SBUF_END,
				togo_strlen(TOGO_SBUF_END));
		ret += bufferevent_write(socket_item->bev, socket_item->bsbuf,
				socket_item->bssize);

		if (ret < 0) {
			togo_log(INFO, "Send data error");
		}

		callback = socket_item->bscb;
		if (callback != NULL) {
			callback(socket_item);
		}
		socket_item->sstatus = 0;

	} else {

		if (socket_item->sfd < 1 || socket_item->sbuf == NULL
				|| socket_item->ssize == 0) {
			return 0;
		}

		ret = bufferevent_write(socket_item->bev, socket_item->sbuf,
				socket_item->ssize);
		if (ret < 0) {
			togo_log(INFO, "Send data error");
		}
		socket_item->ssize = 0;
	}

	return ret;
}
Example #6
0
static void togo_mt_init()
{
	togo_thread_flist = (TOGO_THREAD_FLIST *) togo_pool_calloc(togo_global_pool,
			sizeof(TOGO_THREAD_FLIST));
	if (togo_thread_flist == NULL) {
		togo_log(ERROR, "Initialize togo_thread_flist error.");
	}

	togo_thread_flist->next = NULL;
	togo_thread_flist->total = 0;
	pthread_mutex_init(&togo_thread_flist->lock, NULL);

	pthread_create(&server_main_thread, NULL, togo_mt_process, NULL);
	togo_log(INFO, "Initialize main thread, ip:%s port:%d.", togo_global_c.ip,
			togo_global_c.port);
}
Example #7
0
static void togo_m_cache_create_area(uint32_t msize, uint32_t i,
		TOGO_M_CACHE_AREA * area)
{
	TOGO_M_CACHE_AREA * curr_area;
	TOGO_M_CACHE_CHUNK * chunk;
	uint32_t chunk_item_size;

	curr_area = (TOGO_M_CACHE_AREA *) (area + i);

	chunk = togo_m_cache_create_chunk(curr_area);
	if (chunk == NULL) {
		togo_log(INFO, "Initialize modules_cache's TOGO_M_CACHE_CHUNK fail.");
		togo_exit();
	}
	chunk_item_size = TOGO_M_CACHE_CHUNK_SIZE / msize;

	curr_area->msize = msize;

	curr_area->lru_head = NULL;
	curr_area->lru_tail = NULL;
	curr_area->free_list = NULL;
	curr_area->chunk_list = chunk;
	curr_area->chunk_curr = chunk;

	curr_area->chunk_item_curr = 0;
	curr_area->chunk_item_num = chunk_item_size;

	curr_area->total_size = TOGO_M_CACHE_CHUNK_SIZE;
	curr_area->total_chunk = 1;
	curr_area->total_item = chunk_item_size;
	curr_area->used_item = 0;
	curr_area->free_item = chunk_item_size;

	pthread_mutex_init(&curr_area->lock, NULL);
}
Example #8
0
static TOGO_M_QUEUE_BLOCK * togo_m_queue_block_get()
{
	TOGO_M_QUEUE_BLOCK * block;
	TOGO_M_QUEUE_BLOCK * block_next;

	pthread_mutex_lock(&togo_m_queue_fblock->flock);

	if (togo_m_queue_fblock->block == NULL || togo_m_queue_fblock->total == 0) {
		togo_m_queue_fblock->total = 0;
		togo_m_queue_block_create();
		if (togo_m_queue_fblock->block == NULL) {

			togo_log(ERROR, "alloc a modules_queue's block fail.");
			pthread_mutex_unlock(&togo_m_queue_fblock->flock);
			return NULL;
		}
	}

	block_next = togo_m_queue_fblock->block->next;
	block = togo_m_queue_fblock->block;
	togo_m_queue_fblock->block = block_next;
	togo_m_queue_fblock->total--;

	pthread_mutex_unlock(&togo_m_queue_fblock->flock);

	return block;
}
Example #9
0
//togo_hash.c
void togo_hash_test()
{
	togo_log(DEBUG, "Testing togo_hash.c start ============================");
	int i, j;

	//togo_djb_hash
	i = togo_djb_hash("WOSHISHEN");
	j = togo_djb_hash("asdsadsad");
	if (i == 321158909 && j == 1542131117) {
		togo_log(DEBUG,
				"Testing function:togo_djb_hash .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_djb_hash .............................FAIL");
		togo_exit();
	}

	//togo_murmur_hash2
	i = togo_murmur_hash2("WOSHISHEN", togo_strlen("WOSHISHEN"));
	j = togo_murmur_hash2("asdsadsad", togo_strlen("asdsadsad"));
	if (i == 1501669989 && j == 844110999) {
		togo_log(DEBUG,
				"Testing function:togo_djb_hash .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_djb_hash .............................FAIL");
		togo_exit();
	}

	togo_log(DEBUG, "Testing togo_hash.c end ============================\r\n");
}
Example #10
0
static void togo_config_init()
{
	BOOL ret = togo_read_config(TOGO_C_PATH);

	if (ret == FALSE) {

		BOOL retTry = togo_read_config(TOGO_C_DEFAULT);

		if (retTry == FALSE) {
			togo_log(ERROR, "Read config file Fail");
			togo_exit();
		}
	}
}
Example #11
0
static void togo_wt_process(evutil_socket_t fd, short event, void *arg)
{
	u_char bufs[1];
	TOGO_WORKER_THREAD *worker_thread = (TOGO_WORKER_THREAD *) arg;

	if (read(fd, bufs, 1) != 1) {
		togo_log(INFO, "Read pipe error.");
		return;
	}

	switch (bufs[0]) {
	case 'c':
		if (worker_thread) {

			TOGO_THREAD_ITEM * socket_item = togo_q_pop(worker_thread);

			if (socket_item == NULL) {
				togo_log(INFO, "Can not pop a socket_item from queue.");
				return;
			} else {

				int client_socketfd = socket_item->sfd;

				struct bufferevent *bev = bufferevent_socket_new(
						worker_thread->base, client_socketfd,
						BEV_OPT_CLOSE_ON_FREE);
				socket_item->bev = bev;
				bufferevent_setcb(bev, togo_wt_read_cb, NULL, togo_wt_event_cb,
						socket_item);
				bufferevent_enable(bev, EV_READ | EV_WRITE | EV_PERSIST);
				bufferevent_setwatermark(bev, EV_READ, 0, 0);
			}
		}
		break;
	}

}
Example #12
0
void togo_m_queue_init(void)
{
	togo_m_queue_pool = togo_pool_create(TOGO_M_QUEUE_POOL_SIZE);
	if (togo_m_queue_pool == NULL) {
		togo_log(ERROR, "Initialize modules_queue's pool fail.");
		togo_exit();
	}

	togo_m_queue_hashtable = togo_hashtable_init(togo_m_queue_pool);
	if (togo_m_queue_hashtable == NULL) {
		togo_log(ERROR, "Initialize modules_queue's hashtable fail.");
		togo_exit();
	}

	togo_m_queue_fblock = (TOGO_M_QUEUE_FBLOCK *) togo_pool_calloc(
			togo_m_queue_pool, sizeof(TOGO_M_QUEUE_FBLOCK));
	if (togo_m_queue_fblock == NULL) {
		togo_log(ERROR, "Initialize modules_queue's free block fail.");
		togo_exit();
	}
	pthread_mutex_init(&togo_m_queue_fblock->flock, NULL);
	pthread_mutex_init(&togo_m_queue_glock, NULL);

}
Example #13
0
static void togo_m_cache_set_cb(TOGO_THREAD_ITEM * socket_item)
{
	TOGO_M_CACHE_ITEM * item;
	u_char * new_key;

	item = (TOGO_M_CACHE_ITEM *) socket_item->bparam;
	item->status = 1;

	/* HashTable */
	new_key = togo_m_cache_get_key_addr(item);
	BOOL ret = togo_hashtable_add(togo_m_cache_hashtable, new_key,
			(void *) item);
	if (ret == FALSE) {
		togo_log(INFO, "togo_hashtable_add ERROR %s %d", new_key, item);
	}
}
Example #14
0
static void togo_m_queue_block_create()
{
	TOGO_M_QUEUE_BLOCK * block_s;
	u_char * block;
	uint32_t i;

	for (i = 0; i < TOGO_M_QUEUE_BLOCK_NUM; i++) {

		/* Alloc a large memory to store blocks.
		 * Each large memory can store TOGO_M_QUEUE_BLOCK_NUM block.*/
		block_s = (TOGO_M_QUEUE_BLOCK *) togo_pool_calloc(togo_m_queue_pool,
				sizeof(TOGO_M_QUEUE_BLOCK));
		block = (u_char *) togo_pool_calloc(togo_m_queue_pool,
				TOGO_M_QUEUE_BLOCK_SIZE);
		if (block_s == NULL || block == NULL) {

			if (block != NULL) {
				togo_pool_free_large(togo_m_queue_pool, (void *) block);
			}
			if (block_s != NULL) {
				togo_pool_free_data(togo_m_queue_pool, (void *) block_s);
			}
			togo_log(ERROR, "Initialize modules_queue's block fail.");
			return;
		}

		block_s->buf = block;
		block_s->nelt = 0;
		block_s->next = (TOGO_M_QUEUE_BLOCK *) togo_m_queue_fblock->block;
		block_s->prev = NULL;
		block_s->size = TOGO_M_QUEUE_BLOCK_SIZE;
		block_s->curr = block;

		togo_m_queue_fblock->block = block_s;
		togo_m_queue_fblock->total++;
	}
}
Example #15
0
void togo_m_cache_init(void)
{
	uint32_t total_area, curr, i;
	uint32_t * area_table;
	TOGO_M_CACHE_AREA * area;

	togo_m_cache_pool = togo_pool_create(TOGO_M_CACHE_POOL_SIZE);
	if (togo_m_cache_pool == NULL) {
		togo_log(ERROR, "Initialize modules_cache's POOL fail.");
		togo_exit();
	}

	togo_m_cache_hashtable = togo_hashtable_init(togo_m_cache_pool);
	if (togo_m_cache_hashtable == NULL) {
		togo_log(ERROR, "Initialize modules_cache's HASHTABLE fail.");
		togo_exit();
	}

	togo_m_cache = (TOGO_M_CACHE *) togo_pool_calloc(togo_m_cache_pool,
			sizeof(TOGO_M_CACHE));
	if (togo_m_cache == NULL) {
		togo_log(ERROR, "Initialize modules_cache's TOGO_M_CACHE fail.");
		togo_exit();
	}

	togo_m_cache->pool = togo_m_cache_pool;
	togo_m_cache->total_area = 0;
	togo_m_cache->total_hit = 0;
	togo_m_cache->total_read = 0;
	togo_m_cache->total_size = 0;
	togo_m_cache->total_write = 0;
	togo_m_cache->is_flush = FALSE;
	pthread_mutex_init(&togo_m_cache->glock, NULL);

	/* Initialize the area table!*/
	area_table = (uint32_t *) togo_pool_alloc(togo_m_cache_pool,
			sizeof(uint32_t) * TOGO_M_CACHE_AREA_TABLE_DEFAULT_SIZE);
	if (area_table == NULL) {
		togo_log(ERROR, "Initialize modules_cache's area_table fail.");
		togo_exit();
	}
	togo_m_cache->area_table = area_table;

	total_area = i = 1;
	curr = TOGO_M_CACHE_ITEM_START;
	*area_table = curr;
	while (curr != TOGO_M_CACHE_CHUNK_SIZE) {

		total_area++;
		curr = (uint32_t)(curr * TOGO_M_CACHE_ITEM_POWER);
		if (curr >= TOGO_M_CACHE_CHUNK_SIZE) {
			curr = TOGO_M_CACHE_CHUNK_SIZE;
		}
		*(area_table + i) = curr;
		i++;
	}
	togo_m_cache->total_area = total_area;

	/* Initialize the memory of area!*/
	area = (TOGO_M_CACHE_AREA *) togo_pool_calloc(togo_m_cache_pool,
			sizeof(TOGO_M_CACHE_AREA) * total_area);
	if (area == NULL) {
		togo_log(ERROR, "Initialize modules_cache's TOGO_M_CACHE_AREA fail.");
		togo_exit();
	}
	togo_m_cache->area = area;

	for (i = 0; i < total_area; i++) {
		curr = *(area_table + i);
		togo_m_cache_create_area(curr, i, area);
	}

}
Example #16
0
static void togo_mt_doaccept(evutil_socket_t fd, short event, void *arg)
{
	struct sockaddr_in client_addr;
	int in_size = sizeof(struct sockaddr_in);
	u_char * rbuf;
	u_char * sbuf;
	int client_socketfd = accept(fd, (struct sockaddr *) &client_addr,
			&in_size);
	if (client_socketfd < 0) {
		togo_log(ERROR, "Accept error.");
		return;
	}

	/**
	 * We through the way of polling to select a thread,
	 * Who will taking over a connection.
	 */
	int worker_thread_num = togo_global_c.worker_thread_num;
	int tid = (last_thread + 1) % worker_thread_num;
	TOGO_WORKER_THREAD * worker_thread = togo_worker_threads + tid;
	last_thread = tid;

	/**
	 * Initialize a socket_item. Each connection will have one socket_item.
	 * Through this socket_item , We store each connection details.
	 * When this connection is disconnect, The socket_item will be freed.
	 */
	TOGO_THREAD_ITEM * socket_item = NULL;
	/* Search the free list */
	if (togo_thread_flist->next != NULL) {
		pthread_mutex_lock(&togo_thread_flist->lock);
		if (togo_thread_flist->next != NULL) {
			socket_item = togo_thread_flist->next;
			togo_thread_flist->next = socket_item->next;
			togo_thread_flist->total--;
		}
		pthread_mutex_unlock(&togo_thread_flist->lock);
	}

	if (socket_item == NULL) {
		TOGO_POOL * worker_pool = togo_pool_create(TOGO_WORKER_POOL_SIZE);
		socket_item = (TOGO_THREAD_ITEM *) togo_pool_calloc(worker_pool,
				sizeof(TOGO_THREAD_ITEM));
		rbuf = (u_char *) togo_pool_alloc(worker_pool,
				sizeof(u_char) * TOGO_S_RBUF_INIT_SIZE);
		sbuf = (u_char *) togo_pool_alloc(worker_pool, TOGO_S_SBUF_INIT_SIZE);
		if (rbuf == NULL || sbuf == NULL) {
			togo_log(ERROR, "togo_pool_alloc a rbuf or sbuf error.");
			return;
		}

		socket_item->worker_pool = worker_pool;
		socket_item->rbuf = rbuf;
		socket_item->sbuf = sbuf;
		socket_item->rsize = sizeof(u_char) * TOGO_S_RBUF_INIT_SIZE;
		socket_item->sbuf_size = sizeof(u_char) * TOGO_S_SBUF_INIT_SIZE;
	}

	socket_item->sfd = client_socketfd;
	socket_item->rcurr = socket_item->rbuf;
	socket_item->rbytes = 0;
	socket_item->ssize = 0;

	togo_q_push(worker_thread, socket_item);

	u_char buf[1];
	buf[0] = 'c';
	if (write(worker_thread->notify_send_fd, buf, 1) != 1) {
		togo_log(ERROR, "Write pipe error.");
	}

}
Example #17
0
static void togo_argv_init(int argc, char *argv[])
{
	int oc;
	char ec;
	char * config_path = NULL;
	char * port = NULL;
	char * daemon = NULL;
	char * worker_thread_num = NULL;

	/* Process command-line arguments */
	while ((oc = getopt(argc, argv, "c:" /* Set configuration file */
			"p:" /* Set Tcp port*/
			"n:" /* Set the number of worker thread*/
			"d" /* Set the programs runs in the backgroud */
	)) != -1) {
		switch (oc) {
		case 'c':
			if (optarg != NULL) {
				config_path = optarg;
			}
			break;

		case 'p':
			if (optarg != NULL) {
				port = optarg;
			}
			break;

		case 'd':
			daemon = "1";
			break;

		case 'n':
			if (optarg != NULL) {
				worker_thread_num = optarg;
			}
			break;

		default:
			ec = (char) optopt;
			togo_log(ERROR, "Illegal argument.");
			togo_exit();
			break;

		}
	}

	/* Read the config file */
	if (config_path != NULL) {
		BOOL isRet = togo_read_config(config_path);
		if (isRet == FALSE) {
			togo_config_init(config_path);
		}
	} else {
		togo_config_init(config_path);
	}

	if (port != NULL) {
		togo_set_config(TOGO_C_PORT, port);
	}
	if (daemon != NULL) {
		togo_set_config(TOGO_C_DAEMON, "1");
	}
	if (worker_thread_num != NULL) {
		togo_set_config(TOGO_C_WTN, worker_thread_num);
	}
}
Example #18
0
//togo_string.c
void togo_string_test()
{
	togo_log(DEBUG, "Testing togo_string.c start ============================");
	u_char c;
	char * dst = togo_alloc(100);
	char * str2 = togo_alloc(100);

	//togo_encode_base64
	int i;
	char * str = "SAODOSADO988766556asdsad";
	i = togo_encode_base64(dst, str);
	if (strcmp(dst, "U0FPRE9TQURPOTg4NzY2NTU2YXNkc2Fk") == 0
			&& strlen("U0FPRE9TQURPOTg4NzY2NTU2YXNkc2Fk") == i) {
		togo_log(DEBUG,
				"Testing function:togo_encode_base64 .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_encode_base64 .............................FAIL");
		togo_exit();
	}

	//togo_decode_base64
	i = togo_decode_base64(str2, dst);
	if (strcmp(str, str2) == 0 && strlen(str2) == i) {
		togo_log(DEBUG,
				"Testing function:togo_decode_base64 .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_decode_base64 .............................FAIL ");
		togo_exit();
	}

	//togo_tolower
	c = togo_tolower('X');
	if (c == 'x') {
		togo_log(DEBUG,
				"Testing function:togo_tolower .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_tolower .............................FAIL ");
		togo_exit();
	}

	//togo_toupper
	c = togo_toupper('a');
	if (c == 'A') {
		togo_log(DEBUG,
				"Testing function:togo_toupper .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_toupper .............................FAIL ");
		togo_exit();
	}

	//togo_strcmp
	char * s1 = "woshishen";
	char * s2 = "woshishen";
	i = togo_strcmp(s1, s2);
	if (i == 0) {
		togo_log(DEBUG,
				"Testing function:togo_strcmp .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strcmp .............................FAIL ");
		togo_exit();
	}

	//togo_strncmp
	char * s11 = "woshishen";
	char * s22 = "woshidfdf";
	i = togo_strncmp(s11, s22, 5);
	if (i == 0) {
		togo_log(DEBUG,
				"Testing function:togo_strncmp .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strncmp .............................FAIL ");
		togo_exit();
	}

	//togo_strchr
	char * strchr_p = togo_strchr("woshishen", 's');
	if (*strchr_p == 's') {
		togo_log(DEBUG,
				"Testing function:togo_strchr .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strchr .............................FAIL ");
		togo_exit();
	}

	//togo_strstr
	char * strstr_p = togo_strstr("woshishen", "shi");
	if (*strstr_p == 's') {
		togo_log(DEBUG,
				"Testing function:togo_strstr .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strstr .............................FAIL ");
		togo_exit();
	}

	//togo_strlen
	i = togo_strlen("woshishen");
	if (i == 9) {
		togo_log(DEBUG,
				"Testing function:togo_strlen .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strlen .............................FAIL ");
		togo_exit();
	}

	//togo_atofp(u_char *line, size_t n, size_t point)
	i = togo_atofp("10.98", 5, 2);
	if (i == 1098) {
		togo_log(DEBUG,
				"Testing function:togo_atofp .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_atofp .............................FAIL ");
		togo_exit();
	}

	//togo_atoi(u_char *line, size_t n);
	i = togo_atoi("1024", 4);
	if (i == 1024) {
		togo_log(DEBUG,
				"Testing function:togo_atoi .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_atoi .............................FAIL ");
		togo_exit();
	}

	//togo_cpystrn(u_char *s1, char *s2, size_t len)
	togo_cpystrn(dst, "woshishen", 8);
	if (togo_strcmp(dst, "woshishe") == 0) {
		togo_log(DEBUG,
				"Testing function:togo_cpystrn .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_cpystrn .............................FAIL %s",
				dst);
		togo_exit();
	}

	//togo_strtolower
	togo_cpystrn(dst, "WOSHISHEN", 9);
	char * x111 = togo_strtolower(dst);
	if (togo_strcmp(x111, "woshishen") == 0) {
		togo_log(DEBUG,
				"Testing function:togo_strtolower .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strtolower .............................FAIL ");
		togo_exit();
	}

	//togo_strtolower
	togo_cpystrn(dst, "woshishen", 9);
	char * x222 = togo_strtoupper(dst);
	if (togo_strcmp(x222, "WOSHISHEN") == 0) {
		togo_log(DEBUG,
				"Testing function:togo_strtoupper .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strtoupper .............................FAIL ");
		togo_exit();
	}

	//togo_strpos
	char * ddd = "woshishen";
	int ddds = togo_strpos(ddd, 'i');
	if (ddds == 4) {
		togo_log(DEBUG,
				"Testing function:togo_strpos .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strpos .............................FAIL ");
		togo_exit();
	}

	//togo_strrpos
	int ddds2 = togo_strrpos(ddd, 'i');
	if (ddds2 == 4) {
		togo_log(DEBUG,
				"Testing function:togo_strrpos .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_strrpos .............................FAIL ");
		togo_exit();
	}

	//togo_trim
	togo_cpystrn(dst, "   woshishen   ", 15);
	char * dst1 = togo_trim(dst);
	if (togo_strcmp(dst1, "woshishen") == 0) {
		togo_log(DEBUG,
				"Testing function:togo_trim .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_trim .............................FAIL");
		togo_exit();
	}

	//togo_ltrim
	togo_cpystrn(dst, "   woshishen   ", 15);
	char * dst2 = togo_ltrim(dst);
	if (togo_strcmp(dst2, "woshishen   ") == 0) {
		togo_log(DEBUG,
				"Testing function:togo_ltrim .............................OK ");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_ltrim .............................FAIL ");
		togo_exit();
	}

	//togo_rtrim
	togo_cpystrn(dst, "   woshishen   ", 15);
	char * dst3 = togo_rtrim(dst);
	if (togo_strcmp(dst3, "   woshishen") == 0) {
		togo_log(DEBUG,
				"Testing function:togo_rtrim .............................OK");
	} else {
		togo_log(DEBUG,
				"Testing function:togo_rtrim .............................FAIL ");
		togo_exit();
	}

	togo_log(DEBUG, "Testing togo_string.c end ============================");
}
Example #19
0
static void togo_wt_create(TOGO_WORKER_THREAD *worker_thread)
{
	pthread_t worker_thread_id;
	pthread_create(&worker_thread_id, NULL, togo_wt_cb, worker_thread);
	togo_log(INFO, "Create Worker Thread TID:%d", worker_thread_id);
}