Revision e11386c0 chunker_streamer/chunk_pusher_curl.c

View differences:

chunker_streamer/chunk_pusher_curl.c
1
#define CURL_STATICLIB
1 2
#include <curl/curl.h>
2 3

  
3 4
#include "streamer_commons.h"
......
6 7
void finalizeChunkPusher();
7 8
int sendViaCurl(Chunk gchunk, int buffer_size, char *url);
8 9

  
10
//MAKE THE CURL EASY HANDLE GLOBAL TO REUSE IT CONNECTIONS
11
CURL *curl_handle = 0;
9 12

  
10
void initChunkPusher() {	
13
void initChunkPusher() {
11 14
	/* In windows, this will init the winsock stuff */ 
12 15
	curl_global_init(CURL_GLOBAL_ALL);
16
	/* get a curl handle */ 
17
	curl_handle = curl_easy_init();
18
	fprintf(stderr, "CURL client initialized with handle %p\n", curl_handle);
13 19
}
14 20

  
15 21
void finalizeChunkPusher() {
22
	/* always cleanup curl */ 
23
	curl_easy_cleanup(curl_handle);
24
	fprintf(stderr, "CURL client finalized handle %p\n", curl_handle);
16 25
	curl_global_cleanup();
17 26
}
18 27

  
19 28
int sendViaCurl(Chunk gchunk, int buffer_size, char *url) {
20
	//MAKE THE CURL EASY HANDLE GLOBAL? TO REUSE IT?
21
	CURL *curl_handle;
22 29
	struct curl_slist *headers=NULL;
23 30
	uint8_t *buffer=NULL;
24 31

  
......
27 34
	if( (buffer = malloc(buffer_size)) != NULL) {
28 35
		/* encode the GRAPES chunk into network bytes */
29 36
		encodeChunk(&gchunk, buffer, buffer_size);
30
		/* get a curl handle */ 
31
		curl_handle = curl_easy_init();
37

  
32 38
		if(curl_handle) {
33 39
			curl_easy_setopt(curl_handle, CURLOPT_URL, url);
34 40
			/* fill the headers */
35 41
			headers = curl_slist_append(headers, "Content-Type: application/octet-stream");
36 42
			/* disable Expect: header */
37 43
			headers = curl_slist_append(headers, "Expect:");
44
			/* enable Connection: keep-alive */
45
			//headers = curl_slist_append(headers, "Connection: keep-alive");
46
			/* enable chunked */
47
			//headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
48
			/* force HTTP 1.0 */
49
			//curl_easy_setopt (curl_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
38 50
			/* post binary data */
39 51
			curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, buffer);
40 52
			/* set the size of the postfields data */
......
45 57
			curl_slist_free_all(headers); /* free the header list */
46 58
			ret = STREAMER_OK_RETURN;
47 59
		}
48
		/* always cleanup curl */ 
49
		curl_easy_cleanup(curl_handle);
60

  
50 61
		free(buffer);
51 62
	}
52 63
	return ret;

Also available in: Unified diff