summaryrefslogtreecommitdiff
path: root/libadhocutil/curlMultiHandle.h
blob: 6dc79b91045e7f36bf2bb6959d9d21f21653e206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef ADHOCUTIL_CURLMULTIHANDLE_H
#define ADHOCUTIL_CURLMULTIHANDLE_H

#include <boost/function.hpp>
#include <set>
#include <map>
#include "intrusivePtrBase.h"
#include "visibility.h"
#include "curlHandle.h"

namespace AdHoc {
namespace Net {

class RunningCurl;
typedef boost::intrusive_ptr<RunningCurl> RunningCurlPtr;

/// Perform multiple CURL operations at once.
class DLL_PUBLIC CurlMultiHandle : public IntrusivePtrBase {
	public:
		/** A function that should consume the inbound byte stream. */
		typedef boost::function<void(std::istream &)> Consumer;

		CurlMultiHandle();
		~CurlMultiHandle();

		/** Adds a new consumer for the given URL to the set of operations to perform. */
		CurlHandlePtr addCurl(const std::string &, const Consumer &);
		/** Perform all queued operations. */
		void performAll();

	private:
		typedef std::set<RunningCurlPtr> CURLs;
		typedef std::map<CURL *, RunningCurlPtr> Running;

		DLL_PRIVATE void addRunner(CURLM * curlm, Running & running, CURLs & curls);

		CURLs curls;
};
typedef boost::intrusive_ptr<CurlMultiHandle> CurlMultiHandlePtr;

}
}

#endif