示例#1
0
int http_client::on_head(int status, void* ctx)
{
	http_client* hc = (http_client*) ctx;

	acl_aio_disable_readwrite(hc->conn_);

	if (status != HTTP_CHAT_OK) {
		logger_error("invalid status=%d", status);
		acl_aio_iocp_close(hc->conn_);
		return -1;
	}

	if (http_hdr_req_parse(hc->hdr_req_) < 0) {
		logger_error("parse http header error");
		acl_aio_iocp_close(hc->conn_);
		return -1;
	}

	hc->content_length_ = hc->hdr_req_->hdr.content_length;
	if (hc->content_length_ <= 0)
		return hc->handle() ? 0 : -1;

	hc->req_ = http_req_new(hc->hdr_req_);
	http_req_body_get_async(hc->req_, hc->conn_, on_body,
		hc, hc->rw_timeout_);

	return 0;
}
示例#2
0
int http_client::on_body(int status, char *data, int dlen, void *ctx)
{
	http_client* hc = (http_client*) ctx;

	if (status >= HTTP_CHAT_ERR_MIN) {
		logger_error("status=%d", status);
		acl_aio_iocp_close(hc->conn_);
		return -1;
	}

	if (dlen <= 0) {
		logger_error("invalid dlen=%d", dlen);
		acl_aio_iocp_close(hc->conn_);
		return -1;
	}

	hc->json_.update(data);

	if (status == HTTP_CHAT_OK) {
		acl_aio_disable_readwrite(hc->conn_);
		return hc->handle() ? 0 : -1;
	}

	return 0;
}
示例#3
0
文件: forward.c 项目: aaronshang/acl
void forward_complete(CLIENT_ENTRY *entry)
{
	if (entry->server) {
		acl_aio_iocp_close(entry->server);
	}
	if (entry->client) {
		acl_aio_iocp_close(entry->client);
	}
}
示例#4
0
void http_client::on_finish(void)
{
	if (hdr_req_->hdr.keep_alive)
		wait();
	else
		acl_aio_iocp_close(conn_);
}
示例#5
0
static void close_stream(PROBE_SERVER *server)
{
	if (server->stream != NULL) {
		ACL_ASTREAM *stream = server->stream;
		server->stream = NULL;
		acl_aio_iocp_close(stream);
	}
}
示例#6
0
bool http_client::handle(void)
{
	const char* cmd = http_hdr_req_param(hdr_req_, "cmd");
	if (cmd == NULL || *cmd == 0) {
		//logger_error("cmd null");
		acl::string dummy;
		do_reply(400, "none", dummy, false);
		if (hdr_req_->hdr.keep_alive)
			wait();
		else
			acl_aio_iocp_close(conn_);
		return true;
	}

#define EQ !strcasecmp

	int i;

	for (i = 0; handlers[i].cmd != NULL; i++) {
		if (EQ(cmd, handlers[i].cmd))
			break;
	}

	if (handlers[i].handler == NULL) {
		logger_warn("invalid cmd=%s", cmd);
		acl::string dummy;
		do_reply(400, "unknown", dummy, false);
		if (hdr_req_->hdr.keep_alive)
			wait();
		else
			acl_aio_iocp_close(conn_);
		return true;
	}

	if ((this->*handlers[i].handler)())
		return true;

	acl_aio_iocp_close(conn_);
	return false;
}
示例#7
0
static void disable_listen(void)
{
	int   i;

	if (__listen_astreams == NULL)
		return;
	for (i = 0; __listen_astreams[i] != NULL; i++) {
		acl_aio_disable_read(__listen_astreams[i]);
		acl_aio_iocp_close(__listen_astreams[i]);
		__listen_astreams[i] = NULL;
	}

	acl_myfree(__listen_astreams);
	__listen_astreams = NULL;
}
示例#8
0
	aio_stream::~aio_stream()
	{
		if (stream_)
		{
			handle_->decrease();
			acl_aio_iocp_close(stream_);
		}
		std::list<AIO_CALLBACK*>::iterator it = close_callbacks_.begin();
		for (; it != close_callbacks_.end(); ++it)
			acl_myfree((*it));
		close_callbacks_.clear();

		it = timeout_callbacks_.begin();
		for (; it != timeout_callbacks_.end(); ++it)
			acl_myfree((*it));
		timeout_callbacks_.clear();
	}
示例#9
0
void aio_stream::close()
{
	acl_assert(stream_);
	acl_aio_iocp_close(stream_);
}