Example #1
0
void aio_listen_stream::hook_accept()
{
	acl_assert(stream_);
	if (accept_hooked_)
		return;
	accept_hooked_ = true;

	acl_aio_ctl(stream_,
		ACL_AIO_CTL_ACCEPT_FN, accept_callback,
		ACL_AIO_CTL_CTX, this,
		ACL_AIO_CTL_END);
	acl_aio_accept(stream_);
}
Example #2
0
SERVICE *service_create(const char *local_ip, short local_port,
	const char *dns_ip, short dns_port)
{
	const char *myname = "service_create";
	SERVICE *service;
	ACL_VSTREAM *sstream;
	char addr[64];

	// 创建提供 TCP 方式查询时的监听流
	snprintf(addr, sizeof(addr), "%s:%d", local_ip, local_port);
	sstream = acl_vstream_listen_ex(addr, 128, ACL_NON_BLOCKING, 1024, 10);
	if (sstream == NULL) {
		acl_msg_error("%s(%d): can't listen on addr(%s)",
			myname, __LINE__, addr);
		return (NULL);
	}

	service = (SERVICE*) acl_mycalloc(1, sizeof(SERVICE));
	ACL_SAFE_STRNCPY(service->listen_addr,
		addr, sizeof(service->listen_addr));
	ACL_SAFE_STRNCPY(service->dns_ip, dns_ip, sizeof(service->dns_ip));
	service->dns_port = dns_port;
	snprintf(service->dns_addr, sizeof(service->dns_addr),
		"%s:%d", dns_ip, dns_port);
	service->conn_timeout = 10;
	service->rw_timeout = 10;

	service->table = acl_htable_create(100, 0);
	service->aio = acl_aio_create(ACL_EVENT_SELECT);
	service->sstream = acl_aio_open(service->aio, sstream);
	acl_aio_ctl(service->sstream, ACL_AIO_CTL_ACCEPT_FN, accept_callback,
		ACL_AIO_CTL_CTX, service, ACL_AIO_CTL_END);

	acl_aio_accept(service->sstream);
	service_udp_init(service, local_ip, local_port, dns_ip, dns_port);
	return (service);
}