summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkuri igen <kuri@e4.enlightenment.org>2011-01-26 09:30:34 +0100
committerkuri igen <kuri@e4.enlightenment.org>2011-01-26 09:30:34 +0100
commit807baaaa00dfebd0ef77fc84232449aab045cd37 (patch)
tree497d8999f81a508330e93153fb36cb51bef6110e /src
parent455e282537d8690bfebf9348b765df758f741f5d (diff)
We dont reconnect to ES for each message we have to send.
We will connect at first message (wich takes 9ms here) and then all other messages will be processed in 0.2ms, kind of big perf improvement =)
Diffstat (limited to 'src')
-rw-r--r--src/bin/main.c3
-rw-r--r--src/bin/send.c52
-rw-r--r--src/bin/send.h7
3 files changed, 49 insertions, 13 deletions
diff --git a/src/bin/main.c b/src/bin/main.c
index 812314e..3e6ff8b 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -93,6 +93,9 @@ int main(int argc, char **argv)
93 eina_init(); 93 eina_init();
94 ecore_init(); 94 ecore_init();
95 ecore_file_init(); 95 ecore_file_init();
96 //send_init();
97
98 send_connected = EINA_FALSE;
96 99
97 while( 1 ) 100 while( 1 )
98 { 101 {
diff --git a/src/bin/send.c b/src/bin/send.c
index 76ef6e6..63921a2 100644
--- a/src/bin/send.c
+++ b/src/bin/send.c
@@ -161,6 +161,40 @@ char *send_escape(char *src, char **dst)
161} 161}
162 162
163/** 163/**
164 * @fn int send_destroy(void)
165 * @brief Inits the curl object, and set necessary params
166 *
167 * @return 0
168 */
169int send_init(void)
170{
171 curl = curl_easy_init();
172 if( !curl )
173 {
174 EINA_LOG_DOM_ERR(einadom_send, "Can't init curl.");
175 return(-1);
176 }
177 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, EINA_TRUE);
178 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, send_fromES);
179 curl_easy_setopt(curl, CURLOPT_URL, global_ESserver);
180 send_connected = EINA_TRUE;
181
182 return(0);
183}
184
185/**
186 * @fn int send_destroy(void)
187 * @brief Destroys the curl object
188 *
189 * @return 0
190 */
191int send_destroy(void)
192{
193 curl_easy_cleanup(curl);
194 return(0);
195}
196
197/**
164 * @fn int send_toES(char *jsondata) 198 * @fn int send_toES(char *jsondata)
165 * @brief This function will send a given JSON data to the configured 199 * @brief This function will send a given JSON data to the configured
166 * JSON server 200 * JSON server
@@ -196,26 +230,20 @@ int send_toES(char *jsondata)
196 ecore_con_url_free(ecu); 230 ecore_con_url_free(ecu);
197 ecore_con_url_shutdown(); 231 ecore_con_url_shutdown();
198*/ 232*/
199 CURL *curl; 233 if( send_connected == EINA_FALSE )
200 CURLcode res;
201
202 curl = curl_easy_init();
203 if( !curl )
204 { 234 {
205 EINA_LOG_DOM_ERR(einadom_send, "Can't init curl."); 235 send_init();
206 return(-1);
207 } 236 }
208 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, EINA_TRUE);
209 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, send_fromES);
210 curl_easy_setopt(curl, CURLOPT_URL, global_ESserver);
211 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsondata);
212 237
238 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsondata);
213 res = curl_easy_perform(curl); 239 res = curl_easy_perform(curl);
214 if( res ) 240 if( res )
215 { 241 {
216 EINA_LOG_DOM_ERR(einadom_send, "Sending of JSON query failed, curl returned : %d", res); 242 EINA_LOG_DOM_ERR(einadom_send, "Sending of JSON query failed, curl returned : %d", res);
243 send_destroy();
244 send_connected == EINA_FALSE;
217 } 245 }
218 curl_easy_cleanup(curl); 246
219 return(0); 247 return(0);
220} 248}
221 249
diff --git a/src/bin/send.h b/src/bin/send.h
index 2f1ab08..b97c444 100644
--- a/src/bin/send.h
+++ b/src/bin/send.h
@@ -30,9 +30,14 @@
30 30
31#include "global.h" 31#include "global.h"
32 32
33CURL *curl;
34CURLcode res;
35unsigned char send_connected;
36
33int send_logmessage(struct logmessage *new_logmessage); 37int send_logmessage(struct logmessage *new_logmessage);
34int send_convJSON(char *source_host, char *source_path, char *type, char *message, char *tags, char *timestamp, char **jsondata); 38int send_convJSON(char *source_host, char *source_path, char *type, char *message, char *tags, char *timestamp, char **jsondata);
35char *send_escape(char *src, char **dst); 39char *send_escape(char *src, char **dst);
36int send_toES(char *jsondata); 40int send_toES(char *jsondata);
37size_t send_fromES(void *ptr, size_t size, size_t nmemb, void *data); 41size_t send_fromES(void *ptr, size_t size, size_t nmemb, void *data);
38 42int send_init(void);
43int send_destroy(void);