evdispatch 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
- # Makefile.in generated by automake 1.10 from Makefile.am.
1
+ # Makefile.in generated by automake 1.9.6 from Makefile.am.
2
2
  # @configure_input@
3
3
 
4
4
  # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5
- # 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
5
+ # 2003, 2004, 2005 Free Software Foundation, Inc.
6
6
  # This Makefile.in is free software; the Free Software Foundation
7
7
  # gives unlimited permission to copy and/or distribute it,
8
8
  # with or without modifications, as long as this notice is preserved.
@@ -15,11 +15,15 @@
15
15
  @SET_MAKE@
16
16
 
17
17
 
18
+ srcdir = @srcdir@
19
+ top_srcdir = @top_srcdir@
18
20
  VPATH = @srcdir@
19
21
  pkgdatadir = $(datadir)/@PACKAGE@
20
22
  pkglibdir = $(libdir)/@PACKAGE@
21
23
  pkgincludedir = $(includedir)/@PACKAGE@
24
+ top_builddir = ..
22
25
  am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
26
+ INSTALL = @INSTALL@
23
27
  install_sh_DATA = $(install_sh) -c -m 644
24
28
  install_sh_PROGRAM = $(install_sh) -c
25
29
  install_sh_SCRIPT = $(install_sh) -c
@@ -57,22 +61,17 @@ libdispatch_la_LIBADD =
57
61
  am_libdispatch_la_OBJECTS = libdispatch_la-ev_dispatch.lo \
58
62
  libdispatch_la-ev_http.lo
59
63
  libdispatch_la_OBJECTS = $(am_libdispatch_la_OBJECTS)
60
- libdispatch_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
61
- $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
62
- $(libdispatch_la_CXXFLAGS) $(CXXFLAGS) \
63
- $(libdispatch_la_LDFLAGS) $(LDFLAGS) -o $@
64
- DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
64
+ DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
65
65
  depcomp =
66
66
  am__depfiles_maybe =
67
67
  CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
68
68
  $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
69
- LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
70
- --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
71
- $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
69
+ LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) \
70
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
71
+ $(AM_CXXFLAGS) $(CXXFLAGS)
72
72
  CXXLD = $(CXX)
73
- CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
74
- --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
75
- $(LDFLAGS) -o $@
73
+ CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
74
+ $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
76
75
  SOURCES = $(libdispatch_la_SOURCES)
77
76
  DIST_SOURCES = $(libdispatch_la_SOURCES)
78
77
  includeHEADERS_INSTALL = $(INSTALL_HEADER)
@@ -81,6 +80,8 @@ ETAGS = etags
81
80
  CTAGS = ctags
82
81
  DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
83
82
  ACLOCAL = @ACLOCAL@
83
+ AMDEP_FALSE = @AMDEP_FALSE@
84
+ AMDEP_TRUE = @AMDEP_TRUE@
84
85
  AMTAR = @AMTAR@
85
86
  AR = @AR@
86
87
  AUTOCONF = @AUTOCONF@
@@ -107,8 +108,6 @@ EGREP = @EGREP@
107
108
  EXEEXT = @EXEEXT@
108
109
  F77 = @F77@
109
110
  FFLAGS = @FFLAGS@
110
- GREP = @GREP@
111
- INSTALL = @INSTALL@
112
111
  INSTALL_DATA = @INSTALL_DATA@
113
112
  INSTALL_PROGRAM = @INSTALL_PROGRAM@
114
113
  INSTALL_SCRIPT = @INSTALL_SCRIPT@
@@ -121,8 +120,9 @@ LIBTOOL = @LIBTOOL@
121
120
  LN_S = @LN_S@
122
121
  LTLIBOBJS = @LTLIBOBJS@
123
122
  MAINT = @MAINT@
123
+ MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
124
+ MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
124
125
  MAKEINFO = @MAKEINFO@
125
- MKDIR_P = @MKDIR_P@
126
126
  OBJEXT = @OBJEXT@
127
127
  PACKAGE = @PACKAGE@
128
128
  PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
@@ -132,18 +132,20 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
132
132
  PACKAGE_VERSION = @PACKAGE_VERSION@
133
133
  PATH_SEPARATOR = @PATH_SEPARATOR@
134
134
  RANLIB = @RANLIB@
135
- SED = @SED@
136
135
  SET_MAKE = @SET_MAKE@
137
136
  SHELL = @SHELL@
138
137
  STRIP = @STRIP@
139
138
  VERSION = @VERSION@
140
- abs_builddir = @abs_builddir@
141
- abs_srcdir = @abs_srcdir@
142
- abs_top_builddir = @abs_top_builddir@
143
- abs_top_srcdir = @abs_top_srcdir@
139
+ ac_ct_AR = @ac_ct_AR@
144
140
  ac_ct_CC = @ac_ct_CC@
145
141
  ac_ct_CXX = @ac_ct_CXX@
146
142
  ac_ct_F77 = @ac_ct_F77@
143
+ ac_ct_RANLIB = @ac_ct_RANLIB@
144
+ ac_ct_STRIP = @ac_ct_STRIP@
145
+ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
146
+ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
147
+ am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
148
+ am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
147
149
  am__include = @am__include@
148
150
  am__leading_dot = @am__leading_dot@
149
151
  am__quote = @am__quote@
@@ -155,39 +157,28 @@ build_alias = @build_alias@
155
157
  build_cpu = @build_cpu@
156
158
  build_os = @build_os@
157
159
  build_vendor = @build_vendor@
158
- builddir = @builddir@
159
160
  datadir = @datadir@
160
- datarootdir = @datarootdir@
161
- docdir = @docdir@
162
- dvidir = @dvidir@
163
161
  exec_prefix = @exec_prefix@
164
162
  host = @host@
165
163
  host_alias = @host_alias@
166
164
  host_cpu = @host_cpu@
167
165
  host_os = @host_os@
168
166
  host_vendor = @host_vendor@
169
- htmldir = @htmldir@
170
167
  includedir = @includedir@
171
168
  infodir = @infodir@
172
169
  install_sh = @install_sh@
173
170
  libdir = @libdir@
174
171
  libexecdir = @libexecdir@
175
- localedir = @localedir@
176
172
  localstatedir = @localstatedir@
177
173
  mandir = @mandir@
178
174
  mkdir_p = @mkdir_p@
179
175
  oldincludedir = @oldincludedir@
180
- pdfdir = @pdfdir@
181
176
  prefix = @prefix@
182
177
  program_transform_name = @program_transform_name@
183
- psdir = @psdir@
184
178
  sbindir = @sbindir@
185
179
  sharedstatedir = @sharedstatedir@
186
- srcdir = @srcdir@
187
180
  sysconfdir = @sysconfdir@
188
181
  target_alias = @target_alias@
189
- top_builddir = @top_builddir@
190
- top_srcdir = @top_srcdir@
191
182
  AUTOMAKE_OPTIONS = foreign no-dependencies
192
183
  VERSION_INFO = 0:1
193
184
  include_HEADERS = ev_dispatch.h ev_http.h
@@ -230,7 +221,7 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
230
221
  cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
231
222
  install-libLTLIBRARIES: $(lib_LTLIBRARIES)
232
223
  @$(NORMAL_INSTALL)
233
- test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
224
+ test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
234
225
  @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
235
226
  if test -f $$p; then \
236
227
  f=$(am__strip_dir) \
@@ -241,7 +232,7 @@ install-libLTLIBRARIES: $(lib_LTLIBRARIES)
241
232
 
242
233
  uninstall-libLTLIBRARIES:
243
234
  @$(NORMAL_UNINSTALL)
244
- @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
235
+ @set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
245
236
  p=$(am__strip_dir) \
246
237
  echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
247
238
  $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
@@ -256,7 +247,7 @@ clean-libLTLIBRARIES:
256
247
  rm -f "$${dir}/so_locations"; \
257
248
  done
258
249
  libdispatch.la: $(libdispatch_la_OBJECTS) $(libdispatch_la_DEPENDENCIES)
259
- $(libdispatch_la_LINK) -rpath $(libdir) $(libdispatch_la_OBJECTS) $(libdispatch_la_LIBADD) $(LIBS)
250
+ $(CXXLINK) -rpath $(libdir) $(libdispatch_la_LDFLAGS) $(libdispatch_la_OBJECTS) $(libdispatch_la_LIBADD) $(LIBS)
260
251
 
261
252
  mostlyclean-compile:
262
253
  -rm -f *.$(OBJEXT)
@@ -274,19 +265,23 @@ distclean-compile:
274
265
  $(LTCXXCOMPILE) -c -o $@ $<
275
266
 
276
267
  libdispatch_la-ev_dispatch.lo: ev_dispatch.cc
277
- $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdispatch_la_CXXFLAGS) $(CXXFLAGS) -c -o libdispatch_la-ev_dispatch.lo `test -f 'ev_dispatch.cc' || echo '$(srcdir)/'`ev_dispatch.cc
268
+ $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdispatch_la_CXXFLAGS) $(CXXFLAGS) -c -o libdispatch_la-ev_dispatch.lo `test -f 'ev_dispatch.cc' || echo '$(srcdir)/'`ev_dispatch.cc
278
269
 
279
270
  libdispatch_la-ev_http.lo: ev_http.cc
280
- $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdispatch_la_CXXFLAGS) $(CXXFLAGS) -c -o libdispatch_la-ev_http.lo `test -f 'ev_http.cc' || echo '$(srcdir)/'`ev_http.cc
271
+ $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdispatch_la_CXXFLAGS) $(CXXFLAGS) -c -o libdispatch_la-ev_http.lo `test -f 'ev_http.cc' || echo '$(srcdir)/'`ev_http.cc
281
272
 
282
273
  mostlyclean-libtool:
283
274
  -rm -f *.lo
284
275
 
285
276
  clean-libtool:
286
277
  -rm -rf .libs _libs
278
+
279
+ distclean-libtool:
280
+ -rm -f libtool
281
+ uninstall-info-am:
287
282
  install-includeHEADERS: $(include_HEADERS)
288
283
  @$(NORMAL_INSTALL)
289
- test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
284
+ test -z "$(includedir)" || $(mkdir_p) "$(DESTDIR)$(includedir)"
290
285
  @list='$(include_HEADERS)'; for p in $$list; do \
291
286
  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
292
287
  f=$(am__strip_dir) \
@@ -351,21 +346,22 @@ distclean-tags:
351
346
  -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
352
347
 
353
348
  distdir: $(DISTFILES)
354
- @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
355
- topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
356
- list='$(DISTFILES)'; \
357
- dist_files=`for file in $$list; do echo $$file; done | \
358
- sed -e "s|^$$srcdirstrip/||;t" \
359
- -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
360
- case $$dist_files in \
361
- */*) $(MKDIR_P) `echo "$$dist_files" | \
362
- sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
363
- sort -u` ;; \
364
- esac; \
365
- for file in $$dist_files; do \
349
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
350
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
351
+ list='$(DISTFILES)'; for file in $$list; do \
352
+ case $$file in \
353
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
354
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
355
+ esac; \
366
356
  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
357
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
358
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
359
+ dir="/$$dir"; \
360
+ $(mkdir_p) "$(distdir)$$dir"; \
361
+ else \
362
+ dir=''; \
363
+ fi; \
367
364
  if test -d $$d/$$file; then \
368
- dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
369
365
  if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
370
366
  cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
371
367
  fi; \
@@ -381,7 +377,7 @@ check: check-am
381
377
  all-am: Makefile $(LTLIBRARIES) $(HEADERS)
382
378
  installdirs:
383
379
  for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"; do \
384
- test -z "$$dir" || $(MKDIR_P) "$$dir"; \
380
+ test -z "$$dir" || $(mkdir_p) "$$dir"; \
385
381
  done
386
382
  install: install-am
387
383
  install-exec: install-exec-am
@@ -415,7 +411,7 @@ clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
415
411
  distclean: distclean-am
416
412
  -rm -f Makefile
417
413
  distclean-am: clean-am distclean-compile distclean-generic \
418
- distclean-tags
414
+ distclean-libtool distclean-tags
419
415
 
420
416
  dvi: dvi-am
421
417
 
@@ -429,20 +425,12 @@ info-am:
429
425
 
430
426
  install-data-am: install-includeHEADERS
431
427
 
432
- install-dvi: install-dvi-am
433
-
434
428
  install-exec-am: install-libLTLIBRARIES
435
429
 
436
- install-html: install-html-am
437
-
438
430
  install-info: install-info-am
439
431
 
440
432
  install-man:
441
433
 
442
- install-pdf: install-pdf-am
443
-
444
- install-ps: install-ps-am
445
-
446
434
  installcheck-am:
447
435
 
448
436
  maintainer-clean: maintainer-clean-am
@@ -462,23 +450,21 @@ ps: ps-am
462
450
 
463
451
  ps-am:
464
452
 
465
- uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
466
-
467
- .MAKE: install-am install-strip
453
+ uninstall-am: uninstall-includeHEADERS uninstall-info-am \
454
+ uninstall-libLTLIBRARIES
468
455
 
469
456
  .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
470
457
  clean-libLTLIBRARIES clean-libtool ctags distclean \
471
458
  distclean-compile distclean-generic distclean-libtool \
472
459
  distclean-tags distdir dvi dvi-am html html-am info info-am \
473
- install install-am install-data install-data-am install-dvi \
474
- install-dvi-am install-exec install-exec-am install-html \
475
- install-html-am install-includeHEADERS install-info \
476
- install-info-am install-libLTLIBRARIES install-man install-pdf \
477
- install-pdf-am install-ps install-ps-am install-strip \
478
- installcheck installcheck-am installdirs maintainer-clean \
479
- maintainer-clean-generic mostlyclean mostlyclean-compile \
480
- mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
481
- tags uninstall uninstall-am uninstall-includeHEADERS \
460
+ install install-am install-data install-data-am install-exec \
461
+ install-exec-am install-includeHEADERS install-info \
462
+ install-info-am install-libLTLIBRARIES install-man \
463
+ install-strip installcheck installcheck-am installdirs \
464
+ maintainer-clean maintainer-clean-generic mostlyclean \
465
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
466
+ pdf pdf-am ps ps-am tags uninstall uninstall-am \
467
+ uninstall-includeHEADERS uninstall-info-am \
482
468
  uninstall-libLTLIBRARIES
483
469
 
484
470
  # Tell versions [3.59,3.63) of GNU make to not export all variables.
@@ -23,6 +23,41 @@
23
23
 
24
24
  namespace EVD {
25
25
 
26
+ double Timer::elapsed_time( struct timeval *y )
27
+ {
28
+ struct timeval duration;
29
+ struct timeval now;
30
+ current_time( &now );
31
+ struct timeval *x = &now;
32
+ struct timeval *result = &duration;
33
+
34
+ // see: http://www.gnu.org/software/libtool/manual/libc/Elapsed-Time.html
35
+ // Perform the carry for the later subtraction by updating y.
36
+ if (x->tv_usec < y->tv_usec) {
37
+ int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
38
+ y->tv_usec -= 1000000 * nsec;
39
+ y->tv_sec += nsec;
40
+ }
41
+
42
+ if (x->tv_usec - y->tv_usec > 1000000) {
43
+ int nsec = (x->tv_usec - y->tv_usec) / 1000000;
44
+ y->tv_usec += 1000000 * nsec;
45
+ y->tv_sec -= nsec;
46
+ }
47
+
48
+ // Compute the time remaining to wait.
49
+ // tv_usec is certainly positive.
50
+ result->tv_sec = x->tv_sec - y->tv_sec;
51
+ result->tv_usec = x->tv_usec - y->tv_usec;
52
+
53
+ double elasped = ((double)duration.tv_sec + ((double)duration.tv_usec/1000000.0));
54
+ // Return 1 if result is negative.
55
+ if( x->tv_sec < y->tv_sec ){
56
+ return (-1.0 * elasped);
57
+ }
58
+ return elasped;
59
+ }
60
+
26
61
  Dispatch::Dispatch() : m_loop(NULL), m_counter(0), m_loop_started(false), m_http_client(NULL), m_pending(0)
27
62
  {
28
63
  // zero everything out
@@ -16,13 +16,25 @@ namespace EVD {
16
16
  // unique id to represent a request
17
17
  typedef unsigned long request_t;
18
18
 
19
+ struct Timer {
20
+ Timer( long int seconds, long int nanoseconds ) {
21
+ struct timeval now;
22
+ current_time( &now );
23
+ m_time.tv_sec = now.tv_sec + seconds;
24
+ m_time.tv_nsec = (now.tv_usec * 1000) + nanoseconds;
25
+ }
26
+ inline static int current_time( struct timeval *now) { return gettimeofday(now, NULL); }
27
+ static double elapsed_time( struct timeval *then );
28
+ struct timespec m_time;
29
+ };
30
+
19
31
  struct Request {
20
32
  enum Type{
21
33
  HTTP,
22
34
  SPHINX,
23
35
  MEMCACHED
24
36
  };
25
- Request( request_t k, const std::string &u ) : key(k), url(u){ time( &start_time); }
37
+ Request( request_t k, const std::string &u ) : key(k), url(u){ Timer::current_time( &start_time); }
26
38
  virtual ~Request (){ }
27
39
 
28
40
  // by default this does nothing, each real request object can do as it pleases with this feature
@@ -36,18 +48,12 @@ namespace EVD {
36
48
  // key will be set by the dispatch object when you invoke this request
37
49
  request_t key;
38
50
  std::string url;
39
- time_t start_time;
51
+ struct timeval start_time;
40
52
  };
41
53
 
42
- // TODO:
43
- //struct MemcachedRequesst : public Request {
44
- //};
45
-
46
- // TODO:
47
- //struct SphinxRequest : public Request {
48
- //};
49
-
50
54
  struct Response {
55
+ Response(){}
56
+ Response( const std::string &n ) : name(n){}
51
57
  virtual ~Response(){}
52
58
  std::string name;
53
59
  std::string body;
@@ -72,16 +78,6 @@ namespace EVD {
72
78
  pthread_mutex_t m_lock;
73
79
  };
74
80
 
75
- struct Timer {
76
- Timer( long int seconds, long int nanoseconds ){
77
- struct timeval now;
78
- gettimeofday(&now, NULL);
79
- m_time.tv_sec = now.tv_sec + seconds;
80
- m_time.tv_nsec = (now.tv_usec * 1000) + nanoseconds;
81
- }
82
- struct timespec m_time;
83
- };
84
-
85
81
  struct Cond {
86
82
  Cond() {
87
83
  pthread_cond_init( &m_cond, NULL );
@@ -170,14 +170,19 @@ size_t HttpRequest::write_cb(void *ptr, size_t size, size_t nmemb, void *data)
170
170
  size_t realsize = size * nmemb;
171
171
  HttpRequest *req = (HttpRequest *)data;
172
172
 
173
- if( req->response ) {
174
- req->response->body.append((const char*)ptr,realsize);
175
- //fprintf(stderr, "Write: %s (%lu) => (%d)%s\n", req->url.c_str(), realsize, (int)req->response, req->response->body.c_str() );
176
- }
177
- else if( req->m_fd ) {
178
- write( req->m_fd, ptr, realsize );
179
- }
173
+ req->m_response->write( ptr, realsize, size, nmemb );
174
+
175
+ return realsize;
176
+ }
180
177
 
178
+ // CURLOPT_HEADERFUNCTION
179
+ size_t HttpRequest::header_write_cb(void *ptr, size_t size, size_t nmemb, void *data)
180
+ {
181
+ size_t realsize = size * nmemb;
182
+ HttpRequest *req = (HttpRequest *)data;
183
+
184
+ req->m_response->write_header( ptr, realsize, size, nmemb );
185
+
181
186
  return realsize;
182
187
  }
183
188
 
@@ -189,35 +194,45 @@ int HttpRequest::prog_cb(void *p, double dltotal, double dlnow, double ult, doub
189
194
  return 0;
190
195
  }
191
196
 
192
- HttpRequest::HttpRequest( Dispatch &dispatch, const std::string &url )
193
- : Request( 0, url ), response(new Response()), m_handle(curl_easy_init()), m_client(dispatch.getHttpClient())
197
+ void HttpRequest::init_curl()
194
198
  {
195
- memset(error,'\0', CURL_ERROR_SIZE);
196
199
  curl_easy_setopt(m_handle, CURLOPT_URL, url.c_str());
200
+ curl_easy_setopt(m_handle, CURLOPT_HEADERFUNCTION, header_write_cb);
201
+ curl_easy_setopt(m_handle, CURLOPT_HEADERDATA, this);
197
202
  curl_easy_setopt(m_handle, CURLOPT_WRITEFUNCTION, write_cb);
198
203
  curl_easy_setopt(m_handle, CURLOPT_WRITEDATA, this);
199
204
  curl_easy_setopt(m_handle, CURLOPT_VERBOSE, 0);
200
- curl_easy_setopt(m_handle, CURLOPT_ERRORBUFFER, error);
205
+ curl_easy_setopt(m_handle, CURLOPT_ERRORBUFFER, m_error);
201
206
  curl_easy_setopt(m_handle, CURLOPT_PRIVATE, this);
202
207
  curl_easy_setopt(m_handle, CURLOPT_NOPROGRESS, 0);
203
208
  curl_easy_setopt(m_handle, CURLOPT_PROGRESSFUNCTION, prog_cb);
204
209
  curl_easy_setopt(m_handle, CURLOPT_PROGRESSDATA, this);
205
210
 
206
- // setup the response object
207
- this->response->name = url;
208
211
  }
209
212
 
210
- void HttpRequest::set_response_fd( int fd )
213
+ HttpRequest::HttpRequest( Dispatch &dispatch, const std::string &url, int fd )
214
+ : Request( 0, url ),
215
+ m_response(new HttpResponse(url,fd)),
216
+ m_handle(curl_easy_init()),
217
+ m_client(dispatch.getHttpClient())
211
218
  {
212
- if( this->response ){ delete this->response; this->response = NULL; }
213
- m_fd = fd;
219
+ init_curl();
220
+ }
221
+
222
+ HttpRequest::HttpRequest( Dispatch &dispatch, const std::string &url )
223
+ : Request( 0, url ),
224
+ m_response(new HttpResponse(url)),
225
+ m_handle(curl_easy_init()),
226
+ m_client(dispatch.getHttpClient())
227
+ {
228
+ init_curl();
214
229
  }
215
230
 
216
231
  HttpRequest::~HttpRequest()
217
232
  {
218
233
  curl_easy_cleanup( m_handle );
219
234
  #ifdef DEBUG
220
- response = NULL;
235
+ m_response = NULL;
221
236
  m_handle = NULL;
222
237
  m_client = NULL;
223
238
  #endif
@@ -239,16 +254,82 @@ void HttpRequest::finish(CURLcode rc)
239
254
  {
240
255
  curl_multi_remove_handle( m_client->m_handle, m_handle );
241
256
 
242
- if( this->response ) {
243
- // add the response object here to the responses queue in the dispatcher?
244
- // signaling to any waiting clients that their response is available
245
- this->response->response_time = difftime( time(NULL), this->start_time );
246
- m_client->m_disp->send_response( this->response );
257
+ // add the response object here to the responses queue in the dispatcher?
258
+ // signaling to any waiting clients that their response is available
259
+ m_response->response_time = Timer::elapsed_time( &(this->start_time) );
260
+ m_response->finish( m_client, rc );
261
+
262
+ //fprintf( stderr, "DONE: (%s/%s) => (%d), body(%d): '%s'\n", url.c_str(), url.c_str(), rc, (int)m_response, m_response->body.c_str() );
263
+ }
264
+ void HttpRequest::set_key( request_t key )
265
+ {
266
+ Request::set_key(key);
267
+ m_response->id = key;
268
+ }
269
+
270
+ void HttpRequest::set_opt( const std::string &key, const std::string &value )
271
+ {
272
+ Request::set_opt(key,value);
273
+ // convert the key into a curl value
274
+ // #define CURLOPTTYPE_LONG 0
275
+ // #define CURLOPTTYPE_OBJECTPOINT 10000
276
+ // #define CURLOPTTYPE_FUNCTIONPOINT 20000
277
+ // #define CURLOPTTYPE_OFF_T 30000
278
+
279
+ std::map<std::string,CURLoption> key_loopup;
280
+ // TODO: define this once for each resquest?
281
+ key_loopup["port"] = CURLOPT_PORT;
282
+ key_loopup["autoreferer"] = CURLOPT_AUTOREFERER;
283
+ key_loopup["followlocation"] = CURLOPT_FOLLOWLOCATION;
284
+ key_loopup["maxredirs"] = CURLOPT_MAXREDIRS;
285
+ key_loopup["referer"] = CURLOPT_REFERER;
286
+ key_loopup["useragent"] = CURLOPT_USERAGENT;
287
+ key_loopup["cookie"] = CURLOPT_COOKIE;
288
+
289
+ std::map<std::string,CURLoption>::iterator loc = key_loopup.find(key);
290
+ if( loc != key_loopup.end() ){
291
+ CURLoption val_type = loc->second;
292
+ if( val_type >= CURLOPTTYPE_LONG && val_type < CURLOPTTYPE_OBJECTPOINT ) {
293
+ long val = atoi(value.c_str());
294
+ printf( "set opt %s : %ld\n", key.c_str(), val );
295
+ curl_easy_setopt( m_handle, val_type, val );
296
+ }
297
+ else if( val_type >= CURLOPTTYPE_OBJECTPOINT && val_type < CURLOPTTYPE_FUNCTIONPOINT ) {
298
+ printf( "set opt %s : %s\n", key.c_str(), value.c_str() );
299
+ curl_easy_setopt( m_handle, val_type, value.c_str() );
300
+ }
301
+ }
302
+ }
303
+
304
+ HttpResponse::HttpResponse( const std::string &url )
305
+ : Response(url), m_fd(-1)
306
+ {
307
+ }
308
+ HttpResponse::HttpResponse( const std::string &url, int fd )
309
+ : Response(url), m_fd(fd)
310
+ {
311
+ }
312
+ void HttpResponse::write( void *ptr, size_t realsize, size_t size, size_t nmemb )
313
+ {
314
+ if( m_fd == -1 ) {
315
+ body.append((const char*)ptr,realsize);
316
+ }
317
+ else {
318
+ ::write( m_fd, ptr, realsize );
319
+ }
320
+ }
321
+ void HttpResponse::write_header( void *ptr, size_t realsize, size_t size, size_t nmemb )
322
+ {
323
+ m_header.append((const char*)ptr,realsize);
324
+ }
325
+ void HttpResponse::finish( HttpClient *client, CURLcode rc )
326
+ {
327
+ if( m_fd == -1 ) {
328
+ client->m_disp->send_response( this );
247
329
  }
248
330
  else {
249
331
  close( this->m_fd );
250
332
  }
251
- //fprintf( stderr, "DONE: (%s/%s) => (%d), body(%d): '%s'\n", url.c_str(), url.c_str(), rc, (int)this->response, this->response->body.c_str() );
252
333
  }
253
334
 
254
335
  }
@@ -44,27 +44,41 @@ namespace EVD {
44
44
  // follow the curl handle for the duration of it's request
45
45
  struct HttpRequest : public Request {
46
46
  HttpRequest( Dispatch &dispatch, const std::string &url );
47
+ // use this to have the response be written to the file instead, using a response object.
48
+ // you can not get the response to return over the normal get_next_response or wait_for_response_by_id method if you use this.
49
+ HttpRequest( Dispatch &dispatch, const std::string &url, int fd );
47
50
  virtual ~HttpRequest();
48
51
 
49
52
  virtual bool enable();
50
53
 
51
54
  void finish( CURLcode rc );
52
55
 
53
- virtual void set_key( request_t key ){ Request::set_key(key); if( this->response ) this->response->id = key; }
54
-
55
- // use this to have the response be written to the file instead, using a response object.
56
- // you can not get the response to return over the normal get_next_response or wait_for_response_by_id method if you use this.
57
- void set_response_fd( int fd );
56
+ virtual void set_key( request_t key );
57
+ virtual void set_opt( const std::string &key, const std::string &value );
58
58
 
59
59
  static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data);
60
+ static size_t header_write_cb(void *ptr, size_t size, size_t nmemb, void *data);
60
61
  static int prog_cb(void *p, double dltotal, double dlnow, double ult, double uln);
61
62
 
62
- Response *response;
63
+ struct HttpResponse *m_response;
63
64
 
64
65
  CURL *m_handle;
65
66
  HttpClient *m_client;
66
- char error[CURL_ERROR_SIZE];
67
+ char m_error[CURL_ERROR_SIZE];
68
+ private:
69
+ void init_curl();
70
+ };
71
+
72
+ struct HttpResponse : public Response {
73
+ HttpResponse( const std::string &url );
74
+ HttpResponse( const std::string &url, int fd );
75
+
76
+ void write( void *ptr, size_t realsize, size_t size, size_t nmemb );
77
+ void write_header( void *ptr, size_t realsize, size_t size, size_t nmemb );
78
+ void finish( HttpClient *client, CURLcode rc );
79
+
67
80
  int m_fd;
81
+ std::string m_header;
68
82
  };
69
83
 
70
84
  }
@@ -1,4 +1,4 @@
1
- bin_PROGRAMS = next_test key_test pipe_test
1
+ bin_PROGRAMS = next_test key_test pipe_test opt_test
2
2
  next_test_SOURCES = next_test.cc
3
3
  next_test_CPPFLAGS = -I$(top_srcdir)/src/ -I$(LIBEV_PATH)
4
4
  next_test_LDADD = -ldispatch -lev
@@ -13,3 +13,8 @@ pipe_test_SOURCES = pipe_test.cc
13
13
  pipe_test_CPPFLAGS = -I$(top_srcdir)/src/ -I$(LIBEV_PATH)
14
14
  pipe_test_LDADD = -ldispatch -lev
15
15
  pipe_test_LDFLAGS = -L$(top_srcdir)/src/.libs/ `curl-config --libs` -L$(LIBEV_PATH)/.libs/
16
+
17
+ opt_test_SOURCES = opt_test.cc
18
+ opt_test_CPPFLAGS = -I$(top_srcdir)/src/ -I$(LIBEV_PATH)
19
+ opt_test_LDADD = -ldispatch -lev
20
+ opt_test_LDFLAGS = -L$(top_srcdir)/src/.libs/ `curl-config --libs` -L$(LIBEV_PATH)/.libs/