eventmachine 0.12.4 → 0.12.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/.gitignore +13 -0
  2. data/Rakefile +66 -3
  3. data/docs/ChangeLog +38 -10
  4. data/eventmachine.gemspec +32 -0
  5. data/ext/cmain.cpp +45 -3
  6. data/ext/cplusplus.cpp +21 -0
  7. data/ext/ed.cpp +34 -1
  8. data/ext/ed.h +12 -0
  9. data/ext/em.cpp +23 -3
  10. data/ext/em.h +6 -2
  11. data/ext/eventmachine.h +9 -1
  12. data/ext/eventmachine_cpp.h +1 -0
  13. data/ext/extconf.rb +8 -29
  14. data/ext/fastfilereader/extconf.rb +50 -134
  15. data/ext/fastfilereader/mapper.cpp +12 -0
  16. data/ext/fastfilereader/mapper.h +1 -1
  17. data/ext/kb.cpp +0 -286
  18. data/ext/pipe.cpp +30 -13
  19. data/ext/rubymain.cpp +127 -12
  20. data/ext/ssl.cpp +15 -0
  21. data/ext/ssl.h +4 -0
  22. data/java/.classpath +8 -0
  23. data/java/.project +17 -0
  24. data/lib/em/processes.rb +45 -0
  25. data/lib/eventmachine.rb +260 -102
  26. data/lib/eventmachine_version.rb +1 -1
  27. data/lib/pr_eventmachine.rb +1 -1
  28. data/lib/protocols/httpcli2.rb +10 -1
  29. data/lib/protocols/httpclient.rb +2 -2
  30. data/lib/protocols/memcache.rb +293 -0
  31. data/lib/protocols/smtpserver.rb +1 -1
  32. data/setup.rb +1585 -0
  33. data/tasks/tests.rake +1 -0
  34. data/tests/test_attach.rb +19 -2
  35. data/tests/test_basic.rb +2 -2
  36. data/tests/test_connection_count.rb +45 -0
  37. data/tests/test_error_handler.rb +35 -0
  38. data/tests/test_errors.rb +3 -3
  39. data/tests/test_exc.rb +2 -2
  40. data/tests/test_handler_check.rb +37 -0
  41. data/tests/test_httpclient2.rb +1 -1
  42. data/tests/test_kb.rb +2 -2
  43. data/tests/test_next_tick.rb +7 -0
  44. data/tests/test_processes.rb +39 -0
  45. data/tests/test_pure.rb +2 -2
  46. data/tests/test_send_file.rb +1 -1
  47. data/tests/test_ssl_args.rb +3 -3
  48. data/tests/test_ssl_methods.rb +50 -0
  49. data/tests/test_timers.rb +3 -1
  50. data/web/whatis +7 -0
  51. metadata +88 -84
data/ext/em.cpp CHANGED
@@ -45,6 +45,15 @@ static int MaxOutstandingTimers = 1000;
45
45
  */
46
46
  static struct sockaddr *name2address (const char *server, int port, int *family, int *bind_size);
47
47
 
48
+ /***************************************
49
+ STATIC EventMachine_t::GetMaxTimerCount
50
+ ***************************************/
51
+
52
+ int EventMachine_t::GetMaxTimerCount()
53
+ {
54
+ return MaxOutstandingTimers;
55
+ }
56
+
48
57
 
49
58
  /***************************************
50
59
  STATIC EventMachine_t::SetMaxTimerCount
@@ -77,6 +86,7 @@ EventMachine_t::EventMachine_t (void (*event_callback)(const char*, int, const c
77
86
  LoopBreakerWriter (-1),
78
87
  bEpoll (false),
79
88
  bKqueue (false),
89
+ kqfd (-1),
80
90
  epfd (-1)
81
91
  {
82
92
  // Default time-slice is just smaller than one hundred mills.
@@ -923,8 +933,11 @@ const char *EventMachine_t::InstallOneshotTimer (int milliseconds)
923
933
  #endif
924
934
 
925
935
  Timer_t t;
926
- multimap<Int64,Timer_t>::iterator i =
927
- Timers.insert (make_pair (fire_at, t));
936
+ #ifdef OS_SOLARIS8
937
+ multimap<Int64,Timer_t>::iterator i = Timers.insert (multimap<Int64,Timer_t>::value_type (fire_at, t));
938
+ #else
939
+ multimap<Int64,Timer_t>::iterator i = Timers.insert (make_pair (fire_at, t));
940
+ #endif
928
941
  return i->second.GetBindingChars();
929
942
  }
930
943
 
@@ -1227,7 +1240,7 @@ const char *EventMachine_t::AttachFD (int fd, bool notify_readable, bool notify_
1227
1240
  if (!cd)
1228
1241
  throw std::runtime_error ("no connection allocated");
1229
1242
 
1230
- cd->SetConnectPending (true);
1243
+ cd->SetConnectPending (false);
1231
1244
  cd->SetNotifyReadable (notify_readable);
1232
1245
  cd->SetNotifyWritable (notify_writable);
1233
1246
 
@@ -1910,7 +1923,14 @@ const char *EventMachine_t::OpenKeyboard()
1910
1923
  }
1911
1924
 
1912
1925
 
1926
+ /**********************************
1927
+ EventMachine_t::GetConnectionCount
1928
+ **********************************/
1913
1929
 
1930
+ int EventMachine_t::GetConnectionCount ()
1931
+ {
1932
+ return Descriptors.size();
1933
+ }
1914
1934
 
1915
1935
 
1916
1936
  //#endif // OS_UNIX
data/ext/em.h CHANGED
@@ -42,8 +42,8 @@ See the file COPYING for complete licensing information.
42
42
  #endif
43
43
 
44
44
  // 1.9.0 compat
45
- #ifndef RUBY_UDF_IO
46
- #define RUBY_UDF_IO RB_UDF_DFL
45
+ #ifndef RUBY_UBF_IO
46
+ #define RUBY_UBF_IO RB_UBF_DFL
47
47
  #endif
48
48
  #else
49
49
  #define EmSelect select
@@ -69,6 +69,7 @@ class EventMachine_t
69
69
  class EventMachine_t
70
70
  {
71
71
  public:
72
+ static int GetMaxTimerCount();
72
73
  static void SetMaxTimerCount (int);
73
74
 
74
75
  public:
@@ -101,8 +102,11 @@ class EventMachine_t
101
102
  static void SetuidString (const char*);
102
103
  static int SetRlimitNofile (int);
103
104
 
105
+ pid_t SubprocessPid;
104
106
  int SubprocessExitStatus;
105
107
 
108
+ int GetConnectionCount();
109
+
106
110
  // Temporary:
107
111
  void _UseEpoll();
108
112
  void _UseKqueue();
@@ -32,7 +32,8 @@ extern "C" {
32
32
  EM_CONNECTION_COMPLETED = 104,
33
33
  EM_LOOPBREAK_SIGNAL = 105,
34
34
  EM_CONNECTION_NOTIFY_READABLE = 106,
35
- EM_CONNECTION_NOTIFY_WRITABLE = 107
35
+ EM_CONNECTION_NOTIFY_WRITABLE = 107,
36
+ EM_SSL_HANDSHAKE_COMPLETED = 108
36
37
 
37
38
  };
38
39
 
@@ -53,10 +54,16 @@ extern "C" {
53
54
  const char *evma_open_keyboard();
54
55
  void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filenane);
55
56
  void evma_start_tls (const char *binding);
57
+
58
+ #ifdef WITH_SSL
59
+ X509 *evma_get_peer_cert (const char *binding);
60
+ #endif
61
+
56
62
  int evma_get_peername (const char *binding, struct sockaddr*);
57
63
  int evma_get_sockname (const char *binding, struct sockaddr*);
58
64
  int evma_get_subprocess_pid (const char *binding, pid_t*);
59
65
  int evma_get_subprocess_status (const char *binding, int*);
66
+ int evma_get_connection_count();
60
67
  int evma_send_data_to_connection (const char *binding, const char *data, int data_length);
61
68
  int evma_send_datagram (const char *binding, const char *data, int data_length, const char *address, int port);
62
69
  int evma_get_comm_inactivity_timeout (const char *binding, /*out*/int *value);
@@ -68,6 +75,7 @@ extern "C" {
68
75
  int evma_report_connection_error_status (const char *binding);
69
76
  void evma_signal_loopbreak();
70
77
  void evma_set_timer_quantum (int);
78
+ int evma_get_max_timer_count();
71
79
  void evma_set_max_timer_count (int);
72
80
  void evma_setuid_string (const char *username);
73
81
  void evma_stop_machine();
@@ -48,6 +48,7 @@ namespace EM {
48
48
  virtual void Accept (const char*) {}
49
49
  virtual void Unbind() {}
50
50
  virtual void PostInit() {}
51
+ virtual void SslHandshakeCompleted() {}
51
52
 
52
53
  void StopReactor() {EM::StopReactor();}
53
54
  };
@@ -1,22 +1,4 @@
1
- # $Id$
2
- #
3
- #----------------------------------------------------------------------------
4
- #
5
- # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
6
- # Gmail: blackhedd
7
- #
8
- # This program is free software; you can redistribute it and/or modify
9
- # it under the terms of either: 1) the GNU General Public License
10
- # as published by the Free Software Foundation; either version 2 of the
11
- # License, or (at your option) any later version; or 2) Ruby's License.
12
- #
13
- # See the file COPYING for complete licensing information.
14
- #
15
- #---------------------------------------------------------------------------
16
- #
17
- # extconf.rb for Ruby/EventMachine
18
- # We have to munge LDSHARED because this code needs a C++ link.
19
- #
1
+ require 'mkmf'
20
2
 
21
3
  def check_libs libs = [], fatal = false
22
4
  libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
@@ -30,8 +12,6 @@ def add_define(name)
30
12
  $defs.push("-D#{name}")
31
13
  end
32
14
 
33
- require 'mkmf'
34
-
35
15
  add_define 'BUILD_FOR_RUBY'
36
16
  add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
37
17
  add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
@@ -48,8 +28,6 @@ else
48
28
  add_define 'OS_UNIX'
49
29
 
50
30
  add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
51
-
52
- # check_libs(%w[pthread], true)
53
31
  end
54
32
 
55
33
  # Main platform invariances:
@@ -71,15 +49,16 @@ when /solaris/
71
49
 
72
50
  add_define 'OS_SOLARIS8'
73
51
 
74
- # on Unix we need a g++ link, not gcc.
75
- CONFIG['LDSHARED'] = "$(CXX) -shared"
76
-
77
52
  # Patch by Tim Pease, fixes SUNWspro compile problems.
78
53
  if CONFIG['CC'] == 'cc'
79
- $CFLAGS = CONFIG['CFLAGS'] = "-g -O2 -fPIC"
80
- CONFIG['CCDLFLAGS'] = "-fPIC"
54
+ # SUN CHAIN
55
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC -G"
56
+ CONFIG['CCDLFLAGS'] = "-KPIC"
57
+ else
58
+ # GNU CHAIN
59
+ # on Unix we need a g++ link, not gcc.
60
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
81
61
  end
82
-
83
62
  when /openbsd/
84
63
  # OpenBSD branch contributed by Guillaume Sellier.
85
64
 
@@ -1,161 +1,77 @@
1
- # $Id: extconf.rb 4526 2007-07-03 18:04:34Z francis $
2
- #
3
- #----------------------------------------------------------------------------
4
- #
5
- # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
6
- # Gmail: garbagecat10
7
- #
8
- # This program is free software; you can redistribute it and/or modify
9
- # it under the terms of either: 1) the GNU General Public License
10
- # as published by the Free Software Foundation; either version 2 of the
11
- # License, or (at your option) any later version; or 2) Ruby's License.
12
- #
13
- # See the file COPYING for complete licensing information.
14
- #
15
- #---------------------------------------------------------------------------
16
- #
17
- # extconf.rb for Fast File Reader
18
- # We have to munge LDSHARED because this code needs a C++ link.
19
- #
20
-
21
1
  require 'mkmf'
22
2
 
23
- flags = []
3
+ def check_libs libs = [], fatal = false
4
+ libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
5
+ end
24
6
 
25
- case RUBY_PLATFORM.split('-',2)[1]
26
- when 'mswin32', 'mingw32', 'bccwin32'
27
- unless have_header('windows.h') and
28
- have_header('winsock.h') and
29
- have_library('kernel32') and
30
- have_library('rpcrt4') and
31
- have_library('gdi32')
32
- exit
33
- end
7
+ def check_heads heads = [], fatal = false
8
+ heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
9
+ end
10
+
11
+ def add_define(name)
12
+ $defs.push("-D#{name}")
13
+ end
14
+
15
+ add_define 'BUILD_FOR_RUBY'
16
+
17
+ # Minor platform details between *nix and Windows:
34
18
 
35
- flags << "-D OS_WIN32"
36
- flags << '-D BUILD_FOR_RUBY'
37
- flags << "-EHs"
38
- flags << "-GR"
39
-
40
- dir_config('ssl')
41
- if have_library('ssleay32') and
42
- have_library('libeay32') and
43
- have_header('openssl/ssl.h') and
44
- have_header('openssl/err.h')
45
- flags << '-D WITH_SSL'
19
+ if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
20
+ GNU_CHAIN = $1 == 'mingw'
21
+ OS_WIN32 = true
22
+ add_define "OS_WIN32"
23
+ else
24
+ GNU_CHAIN = true
25
+ OS_UNIX = true
26
+ add_define 'OS_UNIX'
27
+ end
28
+
29
+
30
+
31
+ case RUBY_PLATFORM
32
+ when /mswin32/, /mingw32/, /bccwin32/
33
+ check_heads(%w[windows.h winsock.h], true)
34
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
35
+
36
+ if GNU_CHAIN
37
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
46
38
  else
47
- flags << '-D WITHOUT_SSL'
39
+ $defs.push "-EHs"
40
+ $defs.push "-GR"
48
41
  end
49
42
 
50
43
  when /solaris/
51
- unless have_library('pthread') and
52
- have_library('nsl') and
53
- have_library('socket')
54
- exit
55
- end
44
+ check_libs(%w[nsl socket], true)
56
45
 
57
- flags << '-D OS_UNIX'
58
- flags << '-D OS_SOLARIS8'
59
- flags << '-D BUILD_FOR_RUBY'
46
+ add_define 'OS_SOLARIS8'
60
47
 
61
- dir_config('ssl')
62
- if have_library('ssl') and
63
- have_library('crypto') and
64
- have_header('openssl/ssl.h') and
65
- have_header('openssl/err.h')
66
- flags << '-D WITH_SSL'
48
+ # Patch by Tim Pease, fixes SUNWspro compile problems.
49
+ if CONFIG['CC'] == 'cc'
50
+ # SUN CHAIN
51
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC -G"
52
+ CONFIG['CCDLFLAGS'] = "-KPIC"
67
53
  else
68
- flags << '-D WITHOUT_SSL'
54
+ # GNU CHAIN
55
+ # on Unix we need a g++ link, not gcc.
56
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
69
57
  end
58
+ when /openbsd/
59
+ # OpenBSD branch contributed by Guillaume Sellier.
70
60
 
71
- # on Unix we need a g++ link, not gcc.
72
- CONFIG['LDSHARED'] = "$(CXX) -shared"
73
-
61
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
62
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
74
63
  when /darwin/
75
- flags << '-DOS_UNIX'
76
- flags << '-DBUILD_FOR_RUBY'
77
-
78
- dir_config('ssl')
79
- if have_library('ssl') and
80
- have_library('crypto') and
81
- have_library('C') and
82
- have_header('openssl/ssl.h') and
83
- have_header('openssl/err.h')
84
- flags << '-DWITH_SSL'
85
- else
86
- flags << '-DWITHOUT_SSL'
87
- end
88
64
  # on Unix we need a g++ link, not gcc.
89
65
  # Ff line contributed by Daniel Harple.
90
66
  CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
91
67
 
92
68
  when /linux/
93
- unless have_library('pthread')
94
- exit
95
- end
96
69
 
97
- flags << '-DOS_UNIX'
98
- flags << '-DBUILD_FOR_RUBY'
99
-
100
- # Original epoll test is inadequate because 2.4 kernels have the header
101
- # but not the code.
102
- #flags << '-DHAVE_EPOLL' if have_header('sys/epoll.h')
103
- if have_header('sys/epoll.h')
104
- File.open("hasEpollTest.c", "w") {|f|
105
- f.puts "#include <sys/epoll.h>"
106
- f.puts "int main() { epoll_create(1024); return 0;}"
107
- }
108
- (e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
109
- `rm -f hasEpollTest.c hasEpollTest`
110
- flags << '-DHAVE_EPOLL' if e == 0
111
- end
112
-
113
- dir_config('ssl')
114
- if have_library('ssl') and
115
- have_library('crypto') and
116
- have_header('openssl/ssl.h') and
117
- have_header('openssl/err.h')
118
- flags << '-DWITH_SSL'
119
- else
120
- flags << '-DWITHOUT_SSL'
121
- end
122
70
  # on Unix we need a g++ link, not gcc.
123
71
  CONFIG['LDSHARED'] = "$(CXX) -shared"
124
-
125
- # Modify the mkmf constant LINK_SO so the generated shared object is stripped.
126
- # You might think modifying CONFIG['LINK_SO'] would be a better way to do this,
127
- # but it doesn't work because mkmf doesn't look at CONFIG['LINK_SO'] again after
128
- # it initializes.
129
- linkso = Object.send :remove_const, "LINK_SO"
130
- LINK_SO = linkso + "; strip $@"
131
-
132
72
  else
133
- unless have_library('pthread')
134
- exit
135
- end
136
-
137
- flags << '-DOS_UNIX'
138
- flags << '-DBUILD_FOR_RUBY'
139
-
140
- dir_config('ssl')
141
- if have_library('ssl') and
142
- have_library('crypto') and
143
- have_header('openssl/ssl.h') and
144
- have_header('openssl/err.h')
145
- flags << '-DWITH_SSL'
146
- else
147
- flags << '-DWITHOUT_SSL'
148
- end
149
73
  # on Unix we need a g++ link, not gcc.
150
74
  CONFIG['LDSHARED'] = "$(CXX) -shared"
151
-
152
75
  end
153
76
 
154
- if $CPPFLAGS
155
- $CPPFLAGS += ' ' + flags.join(' ')
156
- else
157
- $CFLAGS += ' ' + flags.join(' ')
158
- end
159
-
160
-
161
- create_makefile "fastfilereaderext"
77
+ create_makefile "fastfilereaderext"
@@ -59,7 +59,11 @@ Mapper_t::Mapper_t (const string &filename)
59
59
  throw runtime_error (strerror (errno));
60
60
  FileSize = st.st_size;
61
61
 
62
+ #ifdef OS_WIN32
63
+ MapPoint = (char*) mmap (0, FileSize, PROT_READ, MAP_SHARED, Fd, 0);
64
+ #else
62
65
  MapPoint = (const char*) mmap (0, FileSize, PROT_READ, MAP_SHARED, Fd, 0);
66
+ #endif
63
67
  if (MapPoint == MAP_FAILED)
64
68
  throw runtime_error (strerror (errno));
65
69
  }
@@ -84,7 +88,11 @@ void Mapper_t::Close()
84
88
  // Can be called multiple times.
85
89
  // Calls to GetChunk are invalid after a call to Close.
86
90
  if (MapPoint) {
91
+ #ifdef OS_SOLARIS8
92
+ munmap ((char*)MapPoint, FileSize);
93
+ #else
87
94
  munmap ((void*)MapPoint, FileSize);
95
+ #endif
88
96
  MapPoint = NULL;
89
97
  }
90
98
  if (Fd >= 0) {
@@ -150,7 +158,11 @@ Mapper_t::Mapper_t (const string &filename)
150
158
  if (!hMapping)
151
159
  throw runtime_error ("File not mapped");
152
160
 
161
+ #ifdef OS_WIN32
162
+ MapPoint = (char*) MapViewOfFile (hMapping, FILE_MAP_WRITE, 0, 0, 0);
163
+ #else
153
164
  MapPoint = (const char*) MapViewOfFile (hMapping, FILE_MAP_WRITE, 0, 0, 0);
165
+ #endif
154
166
  if (!MapPoint)
155
167
  throw runtime_error ("Mappoint not read");
156
168
  }
@@ -49,7 +49,7 @@ class Mapper_t
49
49
  private:
50
50
  HANDLE hFile;
51
51
  HANDLE hMapping;
52
- const char *MapPoint;
52
+ char *MapPoint;
53
53
  #endif // OS_WIN32
54
54
 
55
55
  };