Exemplo n.º 1
0
static void fiber_monitor(void)
{
    int n;

    // 等待消息通知
    __chan_monitor.pop(n);

    printf("--- kill fiber_accept ---\r\n");
    // 杀死监听协程
    acl_fiber_kill(__fiber_accept);

    printf("--- stop fiber schedule ---\r\n");
    // 停止协程调度过程
    acl_fiber_schedule_stop();
}
Exemplo n.º 2
0
static void fiber_wait(ACL_FIBER *, void *ctx)
{
	ACL_CHANNEL *chan = (ACL_CHANNEL *) ctx;
	unsigned long n = acl_channel_recvul(chan);
	
	printf("----fiber-%d: get n: %lu---\r\n", acl_fiber_self(), n);

	for (int i = 0; __workers[i] != NULL; i++)
	{
		printf("kill fiber-%d\r\n", acl_fiber_id(__workers[i]));
		acl_fiber_kill(__workers[i]);
	}

	printf("---- fiber schedul stopping now ----\r\n");
	acl_fiber_schedule_stop();
}
Exemplo n.º 3
0
static void fiber_client(const char* addr, const char* user,
	const char* to, int loop)
{
	acl::socket_stream conn;
	if (conn.open(addr, 0, 10) == false)
	{
		printf("connect %s error %s\r\n", addr, acl::last_serror());
	}
	else
	{
		printf("fiber-%d, connect %s ok\r\n", acl_fiber_self(), addr);

		user_client* client = new user_client(conn, user, to, loop);
		go[=] {
			fiber_reader(client);
		};

		client->wait_exit();
		printf("--- client %s exit now ----\r\n", client->get_name());
		delete client;
	}

	__cur_client--;

	if (__cur_client == 0)
	{
		printf("-----All fibers over!-----\r\n");
		struct timeval end;
		gettimeofday(&end, NULL);
		double spent = stamp_sub(&end, &__begin);
		printf("---Total read: %d, spent: %.2f, speed: %.2f---\r\n",
			__total_read, spent,
			(1000 * __total_read) / (spent < 1 ? 1 : spent));

		acl_fiber_schedule_stop();
	}
}
Exemplo n.º 4
0
void fiber::schedule_stop(void)
{
	acl_fiber_schedule_stop();
}