eventmachine 0.10.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/DEFERRABLES +1 -1
  2. data/LIGHTWEIGHT_CONCURRENCY +1 -1
  3. data/PURE_RUBY +1 -1
  4. data/README +1 -1
  5. data/RELEASE_NOTES +1 -1
  6. data/SMTP +1 -1
  7. data/SPAWNED_PROCESSES +1 -1
  8. data/TODO +1 -1
  9. data/ext/binder.cpp +1 -1
  10. data/ext/binder.h +1 -1
  11. data/ext/cmain.cpp +29 -1
  12. data/ext/cplusplus.cpp +1 -1
  13. data/ext/ed.cpp +79 -1
  14. data/ext/ed.h +6 -1
  15. data/ext/em.cpp +343 -27
  16. data/ext/em.h +25 -1
  17. data/ext/emwin.cpp +1 -1
  18. data/ext/emwin.h +1 -1
  19. data/ext/epoll.cpp +1 -1
  20. data/ext/epoll.h +1 -1
  21. data/ext/eventmachine.h +3 -1
  22. data/ext/eventmachine_cpp.h +1 -1
  23. data/ext/extconf.rb +31 -1
  24. data/ext/files.cpp +1 -1
  25. data/ext/files.h +1 -1
  26. data/ext/kb.cpp +4 -1
  27. data/ext/page.cpp +1 -1
  28. data/ext/page.h +1 -1
  29. data/ext/pipe.cpp +4 -1
  30. data/ext/project.h +8 -2
  31. data/ext/rubymain.cpp +73 -2
  32. data/ext/sigs.cpp +1 -1
  33. data/ext/sigs.h +1 -1
  34. data/ext/ssl.cpp +4 -1
  35. data/ext/ssl.h +1 -1
  36. data/lib/em/deferrable.rb +1 -1
  37. data/lib/em/eventable.rb +1 -1
  38. data/lib/em/future.rb +1 -1
  39. data/lib/em/messages.rb +1 -1
  40. data/lib/em/processes.rb +68 -0
  41. data/lib/em/spawnable.rb +1 -1
  42. data/lib/em/streamer.rb +1 -1
  43. data/lib/eventmachine.rb +113 -66
  44. data/lib/eventmachine_version.rb +2 -2
  45. data/lib/evma.rb +1 -1
  46. data/lib/evma/callback.rb +1 -1
  47. data/lib/evma/container.rb +1 -1
  48. data/lib/evma/factory.rb +1 -1
  49. data/lib/evma/protocol.rb +1 -1
  50. data/lib/evma/reactor.rb +1 -1
  51. data/lib/jeventmachine.rb +1 -1
  52. data/lib/pr_eventmachine.rb +35 -8
  53. data/lib/protocols/header_and_content.rb +1 -1
  54. data/lib/protocols/httpcli2.rb +1 -1
  55. data/lib/protocols/httpclient.rb +1 -1
  56. data/lib/protocols/line_and_text.rb +1 -1
  57. data/lib/protocols/linetext2.rb +1 -1
  58. data/lib/protocols/saslauth.rb +59 -1
  59. data/lib/protocols/smtpclient.rb +4 -3
  60. data/lib/protocols/smtpserver.rb +3 -3
  61. data/lib/protocols/stomp.rb +1 -1
  62. data/lib/protocols/tcptest.rb +1 -1
  63. data/tests/test_basic.rb +2 -1
  64. data/tests/test_defer.rb +63 -0
  65. data/tests/test_epoll.rb +10 -5
  66. data/tests/test_errors.rb +13 -3
  67. data/tests/test_eventables.rb +1 -1
  68. data/tests/test_exc.rb +2 -1
  69. data/tests/test_futures.rb +2 -1
  70. data/tests/test_hc.rb +26 -2
  71. data/tests/test_httpclient.rb +2 -1
  72. data/tests/test_httpclient2.rb +2 -1
  73. data/tests/test_kb.rb +2 -1
  74. data/tests/test_ltp.rb +3 -1
  75. data/tests/test_ltp2.rb +2 -1
  76. data/tests/test_next_tick.rb +2 -1
  77. data/tests/test_processes.rb +56 -0
  78. data/tests/test_pure.rb +2 -1
  79. data/tests/test_running.rb +2 -1
  80. data/tests/test_sasl.rb +73 -0
  81. data/tests/test_send_file.rb +3 -1
  82. data/tests/test_servers.rb +4 -1
  83. data/tests/test_smtpclient.rb +2 -1
  84. data/tests/test_smtpserver.rb +3 -2
  85. data/tests/test_spawn.rb +2 -1
  86. data/tests/test_timers.rb +2 -2
  87. data/tests/test_ud.rb +2 -1
  88. data/tests/testem.rb +1 -1
  89. metadata +115 -104
data/ext/em.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: em.h 585 2007-11-27 14:29:34Z blackhedd $
3
+ $Id: em.h 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: em.h
6
6
  Date: 06Apr06
@@ -79,6 +79,8 @@ class EventMachine_t
79
79
 
80
80
  void Add (EventableDescriptor*);
81
81
  void Modify (EventableDescriptor*);
82
+ void ArmKqueueWriter (EventableDescriptor*);
83
+ void ArmKqueueReader (EventableDescriptor*);
82
84
 
83
85
  void SetTimerQuantum (int);
84
86
  static void SetuidString (const char*);
@@ -88,6 +90,7 @@ class EventMachine_t
88
90
 
89
91
  // Temporary:
90
92
  void _UseEpoll();
93
+ void _UseKqueue();
91
94
 
92
95
 
93
96
  private:
@@ -99,6 +102,7 @@ class EventMachine_t
99
102
 
100
103
  bool _RunSelectOnce();
101
104
  bool _RunEpollOnce();
105
+ bool _RunKqueueOnce();
102
106
 
103
107
  void _ModifyEpollEvent (EventableDescriptor*);
104
108
 
@@ -133,9 +137,29 @@ class EventMachine_t
133
137
  private:
134
138
  bool bEpoll;
135
139
  int epfd; // Epoll file-descriptor
140
+
141
+ bool bKqueue;
142
+ int kqfd; // Kqueue file-descriptor
136
143
  };
137
144
 
138
145
 
146
+ /*******************
147
+ struct SelectData_t
148
+ *******************/
149
+
150
+ struct SelectData_t
151
+ {
152
+ SelectData_t();
153
+
154
+ int _Select();
155
+
156
+ int maxsocket;
157
+ fd_set fdreads;
158
+ fd_set fdwrites;
159
+ timeval tv;
160
+ int nSockets;
161
+ };
162
+
139
163
 
140
164
 
141
165
  #endif // __EventMachine__H_
data/ext/emwin.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: emwin.cpp 327 2007-05-26 11:10:45Z blackhedd $
3
+ $Id: emwin.cpp 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: emwin.cpp
6
6
  Date: 05May06
data/ext/emwin.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: emwin.h 318 2007-05-22 22:06:24Z blackhedd $
3
+ $Id: emwin.h 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: emwin.h
6
6
  Date: 05May06
data/ext/epoll.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: epoll.cpp 352 2007-06-06 20:24:11Z blackhedd $
3
+ $Id: epoll.cpp 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: epoll.cpp
6
6
  Date: 06Jun07
data/ext/epoll.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: epoll.h 352 2007-06-06 20:24:11Z blackhedd $
3
+ $Id: epoll.h 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: epoll.h
6
6
  Date: 06Jun07
data/ext/eventmachine.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: eventmachine.h 584 2007-11-27 07:27:32Z blackhedd $
3
+ $Id: eventmachine.h 679 2008-01-19 01:40:06Z blackhedd $
4
4
 
5
5
  File: eventmachine.h
6
6
  Date: 15Apr06
@@ -47,6 +47,7 @@ extern "C" {
47
47
  void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filenane);
48
48
  void evma_start_tls (const char *binding);
49
49
  int evma_get_peername (const char *binding, struct sockaddr*);
50
+ int evma_get_sockname (const char *binding, struct sockaddr*);
50
51
  int evma_get_subprocess_pid (const char *binding, pid_t*);
51
52
  int evma_get_subprocess_status (const char *binding, int*);
52
53
  int evma_send_data_to_connection (const char *binding, const char *data, int data_length);
@@ -71,6 +72,7 @@ extern "C" {
71
72
 
72
73
  // Temporary:
73
74
  void evma__epoll();
75
+ void evma__kqueue();
74
76
 
75
77
  #if __cplusplus
76
78
  }
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: eventmachine_cpp.h 474 2007-07-27 03:12:30Z blackhedd $
3
+ $Id: eventmachine_cpp.h 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: eventmachine_cpp.h
6
6
  Date: 27Jul07
data/ext/extconf.rb CHANGED
@@ -1,4 +1,4 @@
1
- # $Id: extconf.rb 526 2007-09-11 17:43:23Z blackhedd $
1
+ # $Id: extconf.rb 677 2008-01-08 20:37:24Z blackhedd $
2
2
  #
3
3
  #----------------------------------------------------------------------------
4
4
  #
@@ -77,10 +77,32 @@ when /solaris/
77
77
  CONFIG['CCDLFLAGS'] = "-fPIC"
78
78
  end
79
79
 
80
+ when /openbsd/
81
+ # OpenBSD branch contributed by Guillaume Sellier.
82
+ flags << '-DOS_UNIX'
83
+ flags << '-DBUILD_FOR_RUBY'
84
+
85
+ dir_config('ssl') # here I don't know why we have to check -lcrypto before -lssl otherwise -lssl is not found
86
+ if have_library('crypto') and
87
+ have_library('ssl') and
88
+ have_header('openssl/ssl.h') and
89
+ have_header('openssl/err.h')
90
+ flags << '-DWITH_SSL'
91
+ else
92
+ flags << '-DWITHOUT_SSL'
93
+ end
94
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
95
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
96
+
97
+
80
98
  when /darwin/
81
99
  flags << '-DOS_UNIX'
82
100
  flags << '-DBUILD_FOR_RUBY'
83
101
 
102
+ if have_header("sys/event.h") and have_header("sys/queue.h")
103
+ flags << "-DHAVE_KQUEUE"
104
+ end
105
+
84
106
  dir_config('ssl')
85
107
  if have_library('ssl') and
86
108
  have_library('crypto') and
@@ -116,6 +138,10 @@ when /linux/
116
138
  flags << '-DHAVE_EPOLL' if e == 0
117
139
  end
118
140
 
141
+ if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h')
142
+ flags << "-DHAVE_TBR"
143
+ end
144
+
119
145
  dir_config('ssl', "#{ENV['OPENSSL']}/include", ENV['OPENSSL'])
120
146
  # Check for libcrypto twice, before and after ssl. That's because on some platforms
121
147
  # and openssl versions, libssl will emit unresolved externals from crypto. It
@@ -149,6 +175,10 @@ else
149
175
  flags << '-DOS_UNIX'
150
176
  flags << '-DBUILD_FOR_RUBY'
151
177
 
178
+ if have_header("sys/event.h") and have_header("sys/queue.h")
179
+ flags << "-DHAVE_KQUEUE"
180
+ end
181
+
152
182
  dir_config('ssl')
153
183
  if have_library('ssl') and
154
184
  have_library('crypto') and
data/ext/files.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: ed.cpp 250 2006-08-25 02:17:58Z blackhedd $
3
+ $Id: files.cpp 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: files.cpp
6
6
  Date: 26Aug06
data/ext/files.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: ed.h 243 2006-08-23 02:00:10Z blackhedd $
3
+ $Id: files.h 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: files.h
6
6
  Date: 26Aug06
data/ext/kb.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: kb.cpp 502 2007-08-24 09:29:53Z blackhedd $
3
+ $Id: kb.cpp 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: kb.cpp
6
6
  Date: 24Aug07
@@ -33,6 +33,9 @@ KeyboardDescriptor::KeyboardDescriptor (EventMachine_t *parent_em):
33
33
  #ifdef HAVE_EPOLL
34
34
  EpollEvent.events = EPOLLIN;
35
35
  #endif
36
+ #ifdef HAVE_KQUEUE
37
+ MyEventMachine->ArmKqueueReader (this);
38
+ #endif
36
39
  }
37
40
 
38
41
 
data/ext/page.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: page.cpp 318 2007-05-22 22:06:24Z blackhedd $
3
+ $Id: page.cpp 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: page.cpp
6
6
  Date: 30Apr06
data/ext/page.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: page.h 318 2007-05-22 22:06:24Z blackhedd $
3
+ $Id: page.h 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: page.h
6
6
  Date: 30Apr06
data/ext/pipe.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: pipe.cpp 585 2007-11-27 14:29:34Z blackhedd $
3
+ $Id: pipe.cpp 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: pipe.cpp
6
6
  Date: 30May07
@@ -38,6 +38,9 @@ PipeDescriptor::PipeDescriptor (int fd, pid_t subpid, EventMachine_t *parent_em)
38
38
  #ifdef HAVE_EPOLL
39
39
  EpollEvent.events = EPOLLIN;
40
40
  #endif
41
+ #ifdef HAVE_KQUEUE
42
+ MyEventMachine->ArmKqueueReader (this);
43
+ #endif
41
44
  }
42
45
 
43
46
 
data/ext/project.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: project.h 490 2007-07-30 12:51:33Z blackhedd $
3
+ $Id: project.h 686 2008-05-14 21:21:10Z francis $
4
4
 
5
5
  File: project.h
6
6
  Date: 06Apr06
@@ -76,7 +76,8 @@ typedef int SOCKET;
76
76
  #ifdef OS_WIN32
77
77
  #define WIN32_LEAN_AND_MEAN
78
78
  #include <windows.h>
79
- #include <winsock.h>
79
+ #include <winsock2.h>
80
+ #include <ws2tcpip.h>
80
81
  #include <rpc.h>
81
82
  #include <fcntl.h>
82
83
  #include <assert.h>
@@ -96,6 +97,11 @@ using namespace std;
96
97
  #include <sys/epoll.h>
97
98
  #endif
98
99
 
100
+ #ifdef HAVE_KQUEUE
101
+ #include <sys/event.h>
102
+ #include <sys/queue.h>
103
+ #endif
104
+
99
105
  #include "binder.h"
100
106
  #include "em.h"
101
107
  #include "epoll.h"
data/ext/rubymain.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: rubymain.cpp 584 2007-11-27 07:27:32Z blackhedd $
3
+ $Id: rubymain.cpp 679 2008-01-19 01:40:06Z blackhedd $
4
4
 
5
5
  File: rubymain.cpp
6
6
  Date: 06Apr06
@@ -31,6 +31,13 @@ static VALUE EmModule;
31
31
  static VALUE EmConnection;
32
32
 
33
33
  static VALUE Intern_at_signature;
34
+ static VALUE Intern_at_timers;
35
+ static VALUE Intern_at_conns;
36
+ static VALUE Intern_event_callback;
37
+ static VALUE Intern_run_deferred_callbacks;
38
+ static VALUE Intern_delete;
39
+ static VALUE Intern_call;
40
+ static VALUE Intern_receive_data;
34
41
 
35
42
 
36
43
  /****************
@@ -39,7 +46,25 @@ t_event_callback
39
46
 
40
47
  static void event_callback (const char *a1, int a2, const char *a3, int a4)
41
48
  {
42
- rb_funcall (EmModule, rb_intern ("event_callback"), 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4));
49
+ if (a2 == EM_CONNECTION_READ) {
50
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
51
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
52
+ if (q == Qnil)
53
+ rb_raise (rb_eRuntimeError, "no connection");
54
+ rb_funcall (q, Intern_receive_data, 1, rb_str_new (a3, a4));
55
+ }
56
+ else if (a2 == EM_LOOPBREAK_SIGNAL) {
57
+ rb_funcall (EmModule, Intern_run_deferred_callbacks, 0);
58
+ }
59
+ else if (a2 == EM_TIMER_FIRED) {
60
+ VALUE t = rb_ivar_get (EmModule, Intern_at_timers);
61
+ VALUE q = rb_funcall (t, Intern_delete, 1, rb_str_new(a3, a4));
62
+ if (q == Qnil)
63
+ rb_raise (rb_eRuntimeError, "no timer");
64
+ rb_funcall (q, Intern_call, 0);
65
+ }
66
+ else
67
+ rb_funcall (EmModule, Intern_event_callback, 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4));
43
68
  }
44
69
 
45
70
 
@@ -167,6 +192,20 @@ static VALUE t_get_peername (VALUE self, VALUE signature)
167
192
  return Qnil;
168
193
  }
169
194
 
195
+ /**************
196
+ t_get_sockname
197
+ **************/
198
+
199
+ static VALUE t_get_sockname (VALUE self, VALUE signature)
200
+ {
201
+ struct sockaddr s;
202
+ if (evma_get_sockname (StringValuePtr (signature), &s)) {
203
+ return rb_str_new ((const char*)&s, sizeof(s));
204
+ }
205
+
206
+ return Qnil;
207
+ }
208
+
170
209
  /********************
171
210
  t_get_subprocess_pid
172
211
  ********************/
@@ -434,6 +473,17 @@ static VALUE t__epoll (VALUE self)
434
473
  return Qnil;
435
474
  }
436
475
 
476
+ /*********
477
+ t__kqueue
478
+ *********/
479
+
480
+ static VALUE t__kqueue (VALUE self)
481
+ {
482
+ // Temporary.
483
+ evma__kqueue();
484
+ return Qnil;
485
+ }
486
+
437
487
 
438
488
  /****************
439
489
  t_send_file_data
@@ -487,6 +537,16 @@ static VALUE conn_get_outbound_data_size (VALUE self)
487
537
  }
488
538
 
489
539
 
540
+ /******************************
541
+ conn_associate_callback_target
542
+ ******************************/
543
+
544
+ static VALUE conn_associate_callback_target (VALUE self, VALUE sig)
545
+ {
546
+ // No-op for the time being.
547
+ return Qnil;
548
+ }
549
+
490
550
 
491
551
  /*********************
492
552
  Init_rubyeventmachine
@@ -496,6 +556,14 @@ extern "C" void Init_rubyeventmachine()
496
556
  {
497
557
  // Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
498
558
  Intern_at_signature = rb_intern ("@signature");
559
+ Intern_at_timers = rb_intern ("@timers");
560
+ Intern_at_conns = rb_intern ("@conns");
561
+
562
+ Intern_event_callback = rb_intern ("event_callback");
563
+ Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks");
564
+ Intern_delete = rb_intern ("delete");
565
+ Intern_call = rb_intern ("call");
566
+ Intern_receive_data = rb_intern ("receive_data");
499
567
 
500
568
  // INCOMPLETE, we need to define class Connections inside module EventMachine
501
569
  // run_machine and run_machine_without_threads are now identical.
@@ -538,6 +606,7 @@ extern "C" void Init_rubyeventmachine()
538
606
  rb_define_module_function (EmModule, "_write_file", (VALUE(*)(...))t__write_file, 1);
539
607
 
540
608
  rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
609
+ rb_define_module_function (EmModule, "get_sockname", (VALUE(*)(...))t_get_sockname, 1);
541
610
  rb_define_module_function (EmModule, "get_subprocess_pid", (VALUE(*)(...))t_get_subprocess_pid, 1);
542
611
  rb_define_module_function (EmModule, "get_subprocess_status", (VALUE(*)(...))t_get_subprocess_status, 1);
543
612
  rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
@@ -546,8 +615,10 @@ extern "C" void Init_rubyeventmachine()
546
615
 
547
616
  // Temporary:
548
617
  rb_define_module_function (EmModule, "epoll", (VALUE(*)(...))t__epoll, 0);
618
+ rb_define_module_function (EmModule, "kqueue", (VALUE(*)(...))t__kqueue, 0);
549
619
 
550
620
  rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
621
+ rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);
551
622
 
552
623
  rb_define_const (EmModule, "TimerFired", INT2NUM(100));
553
624
  rb_define_const (EmModule, "ConnectionData", INT2NUM(101));
data/ext/sigs.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: sigs.cpp 318 2007-05-22 22:06:24Z blackhedd $
3
+ $Id: sigs.cpp 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: sigs.cpp
6
6
  Date: 06Apr06
data/ext/sigs.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: sigs.h 318 2007-05-22 22:06:24Z blackhedd $
3
+ $Id: sigs.h 668 2008-01-04 23:00:34Z blackhedd $
4
4
 
5
5
  File: sigs.h
6
6
  Date: 06Apr06