Ejemplo n.º 1
0
Archivo: main.c Proyecto: iYefeng/acl
static void fiber_producer(ACL_FIBER *fiber, void *ctx)
{
	ACL_CHANNEL *chan = (ACL_CHANNEL *) ctx;

	while (__nsend < __max) {
		int ret = acl_channel_sendul(chan, __nsend);
		__nsend++;

		if (ret <= 0) {
			printf("fiber-%d, channel_sendul error!\r\n",
				acl_fiber_id(fiber));
			break;
		}

		if (__nsend < __display)
			printf(">>fiber-%d, send: %d %s\r\n",
				acl_fiber_id(fiber), __nsend,
				ret > 0 ? "ok" : "error");
	}
}
Ejemplo n.º 2
0
static void fiber_result(ACL_FIBER *fiber, void *ctx)
{
	MYCHANS *mychans  = (MYCHANS *) ctx;
	MYCHAN  *mychan   = &mychans->chans[mychans->off++];
	ACL_CHANNEL *chan = mychan->chan;
	PKT pkt;

	if (mychans->off == mychans->size)
		mychans->off = 0;

	pkt.cmd = mychan->cmd;

	for (int i = 0; i < __oper_count; i++)
	{
		pkt.key.format("key-%d-%d", acl_fiber_id(fiber), i);
		pkt.val.format("val-%d-%d", acl_fiber_id(fiber), i);

		if (acl_channel_sendp(chan, &pkt) < 0)
		{
			printf("%s(%d): fiber-%d: acl_channel_sendp error, key = %s\r\n",
				__FUNCTION__, __LINE__, acl_fiber_id(fiber),
				pkt.key.c_str());
			break;
		}

		PKT* res = (PKT *) acl_channel_recvp(chan);
		if (res == NULL)
		{
			printf("%s(%d): fiber-%d: acl_channel_recvp error, key = %s\r\n",
				__FUNCTION__, __LINE__, acl_fiber_id(fiber),
				pkt.key.c_str());
			break;
		}

		//assert(res == &pkt);

		if (!res->success)
		{
			printf("%s(%d): fiber-%d: cmd = %s, key = %s, failed\r\n",
				__FUNCTION__, __LINE__, acl_fiber_id(fiber),
				pkt.cmd.c_str(), pkt.key.c_str());
			continue;
		}

		if (++__display >= 10)
			continue;

		if (pkt.cmd.equal("get", false))
			printf("fiber-%d: cmd = %s, key = %s, val = %s\r\n",
				acl_fiber_id(fiber), pkt.cmd.c_str(),
				pkt.key.c_str(), res->val.c_str());
		else
			printf("fiber-%d: cmd = %s, key = %s\r\n",
				acl_fiber_id(fiber), pkt.cmd.c_str(),
				pkt.key.c_str());
	}

	if (--__fibers_count == 0)
	{
		printf("---All fibers are over!---\r\n");
		unsigned long n = 100;
		acl_channel_sendul(__chan_exit, n);
	}
}