#pragma once

class req_callback;

class res_callback : public acl::aio_open_callback
{
public:
	res_callback(req_callback* req, acl::ofstream* res_fp);
	~res_callback();

	bool start(acl::aio_handle& handle, const char* server_addr);

	acl::aio_socket_stream& get_conn();
	void disconnect();
	void on_closed();

protected:
	/** 
	 * ʵָе麯ͻĶɹص 
	 * @param data {char*} ݵַ 
	 * @param len {int} ݳ 
	 * @return {bool}  true ʾϣرո첽 
	 */
	virtual bool read_callback(char* data, int len);

	/** 
	 * ʵָе麯ͻдɹص 
	 * @return {bool}  true ʾϣرո첽 
	 */  
	virtual bool write_callback()
	{
		return true;  
	}

	/** 
	 * ʵָе麯ͻĹرջص 
	 */  
	virtual void close_callback();

	/** 
	 * ʵָе麯ͻĳʱص 
	 * @return {bool}  true ʾϣرո첽 
	 */  
	virtual bool timeout_callback()
	{
		//  false ֪ͨ첽ܹرո첽
		return false;
	}

	/**
	 * 麯, 첽ӳɹô˺
	 * @return {bool} ظ true ʾʾҪر첽
	 */
	virtual bool open_callback();

private:
	acl::aio_socket_stream* conn_;
	req_callback* req_;
	acl::ofstream* res_fp_;
};
