#ifndef _MULTICURL_H_
#define _MULTICURL_H_

#include "XABase.h"
#include <curl/curl.h>

#include <ext/hash_map>
using __gnu_cxx::hash_map;

typedef void (*MultiCurlCallback)(int ret, void *ptr, const char *buf, int len);



class CMultiCurl
{
	public:
		int Init(MultiCurlCallback callback, int bufLen = 1024);
		int Poll(int timeout/*msec*/);
		int Exit();

		// if ptr==NULL, callback will not be invoked
		int Post(const char *url, const char *param, void *ptr=NULL,
					const char *host=NULL, int timeout=5000/*msec*/,
					const char *encoding="gzip");

	private:
		MultiCurlCallback m_callback;
		CURLM *m_mcurl;
		int m_bufLen;

	private:
		void AddToMap(CURL* key, void *value);
		void DelFromMap(CURL *key);
		void *GetFromMap(CURL *key);
		hash_map<unsigned long, void *> m_mcbMap;
};

#endif

