eventmachine 0.3.1 → 0.4.0

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 (80) hide show
  1. data/RELEASE_NOTES +5 -1
  2. data/ext/binder.cpp +125 -0
  3. data/ext/binder.h +54 -0
  4. data/ext/ed.cpp +528 -0
  5. data/ext/ed.h +152 -0
  6. data/ext/em.cpp +475 -0
  7. data/ext/em.h +90 -0
  8. data/ext/extconf.rb +31 -0
  9. data/ext/libmain.cpp +312 -0
  10. data/ext/project.h +63 -0
  11. data/ext/sigs.cpp +60 -0
  12. data/ext/sigs.h +35 -0
  13. data/lib/eventmachine.rb +39 -1
  14. metadata +18 -80
  15. data/doc/classes/Echo.html +0 -180
  16. data/doc/classes/Echo.src/M000033.html +0 -23
  17. data/doc/classes/Echo.src/M000034.html +0 -19
  18. data/doc/classes/Echo.src/M000035.html +0 -19
  19. data/doc/classes/Echo.src/M000036.html +0 -18
  20. data/doc/classes/EventMachine.html +0 -369
  21. data/doc/classes/EventMachine.src/M000002.html +0 -24
  22. data/doc/classes/EventMachine.src/M000003.html +0 -24
  23. data/doc/classes/EventMachine.src/M000004.html +0 -26
  24. data/doc/classes/EventMachine.src/M000005.html +0 -21
  25. data/doc/classes/EventMachine.src/M000006.html +0 -23
  26. data/doc/classes/EventMachine.src/M000007.html +0 -28
  27. data/doc/classes/EventMachine.src/M000008.html +0 -20
  28. data/doc/classes/EventMachine.src/M000009.html +0 -19
  29. data/doc/classes/EventMachine.src/M000010.html +0 -18
  30. data/doc/classes/EventMachine.src/M000011.html +0 -18
  31. data/doc/classes/EventMachine/Connection.html +0 -341
  32. data/doc/classes/EventMachine/Connection.src/M000020.html +0 -19
  33. data/doc/classes/EventMachine/Connection.src/M000021.html +0 -17
  34. data/doc/classes/EventMachine/Connection.src/M000022.html +0 -18
  35. data/doc/classes/EventMachine/Connection.src/M000023.html +0 -17
  36. data/doc/classes/EventMachine/Connection.src/M000024.html +0 -18
  37. data/doc/classes/EventMachine/Connection.src/M000025.html +0 -18
  38. data/doc/classes/EventMachine/Connection.src/M000026.html +0 -18
  39. data/doc/classes/EventMachine/Connection.src/M000027.html +0 -18
  40. data/doc/classes/EventMachine/Connection.src/M000028.html +0 -17
  41. data/doc/classes/EventMachine/Connection.src/M000029.html +0 -18
  42. data/doc/classes/EventMachine/Connection.src/M000030.html +0 -18
  43. data/doc/classes/EventMachine/Connection.src/M000031.html +0 -18
  44. data/doc/classes/EventMachine/Connection.src/M000032.html +0 -18
  45. data/doc/classes/EventMachine/ConnectionAlreadyBound.html +0 -111
  46. data/doc/classes/EventMachine/ConnectionNotBound.html +0 -111
  47. data/doc/classes/EventMachine/Connections.html +0 -292
  48. data/doc/classes/EventMachine/Connections.src/M000012.html +0 -20
  49. data/doc/classes/EventMachine/Connections.src/M000013.html +0 -23
  50. data/doc/classes/EventMachine/Connections.src/M000014.html +0 -23
  51. data/doc/classes/EventMachine/Connections.src/M000015.html +0 -24
  52. data/doc/classes/EventMachine/Connections.src/M000016.html +0 -19
  53. data/doc/classes/EventMachine/Connections.src/M000017.html +0 -21
  54. data/doc/classes/EventMachine/Connections.src/M000018.html +0 -19
  55. data/doc/classes/EventMachine/Connections.src/M000019.html +0 -20
  56. data/doc/classes/EventMachine/EventCodes.html +0 -133
  57. data/doc/classes/EventMachine/NoConnectionMade.html +0 -111
  58. data/doc/classes/EventMachine/NoHandlerForAcceptedConnection.html +0 -111
  59. data/doc/classes/EventMachine/NoServerCreated.html +0 -111
  60. data/doc/classes/EventMachine/TimerNotInstalled.html +0 -111
  61. data/doc/classes/EventMachine/TooManyAcceptors.html +0 -111
  62. data/doc/classes/EventMachine/TooManyTimersPending.html +0 -111
  63. data/doc/classes/EventMachine/UnknownTimerFired.html +0 -111
  64. data/doc/classes/Zzz.html +0 -131
  65. data/doc/classes/Zzz.src/M000001.html +0 -18
  66. data/doc/created.rid +0 -1
  67. data/doc/files/binder_cpp.html +0 -101
  68. data/doc/files/ed_cpp.html +0 -101
  69. data/doc/files/em_cpp.html +0 -101
  70. data/doc/files/event_machine_rb.html +0 -118
  71. data/doc/files/g_rb.html +0 -108
  72. data/doc/files/lib/eventmachine_rb.html +0 -114
  73. data/doc/files/libmain_cpp.html +0 -101
  74. data/doc/files/sigs_cpp.html +0 -101
  75. data/doc/files/tests/testem_rb.html +0 -110
  76. data/doc/fr_class_index.html +0 -41
  77. data/doc/fr_file_index.html +0 -35
  78. data/doc/fr_method_index.html +0 -62
  79. data/doc/index.html +0 -24
  80. data/ext/libeventmachine.so +0 -0
@@ -0,0 +1,90 @@
1
+ /*****************************************************************************
2
+
3
+ $Id: em.h 2291 2006-04-14 03:56:18Z francis $
4
+
5
+ File: ed.h
6
+ Date: 06Apr06
7
+
8
+ Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: garbagecat20
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation; either version 2 of the License, or
14
+ (at your option) any later version.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
+
25
+ *****************************************************************************/
26
+
27
+
28
+ #ifndef __EventMachine__H_
29
+ #define __EventMachine__H_
30
+
31
+
32
+ extern time_t gCurrentLoopTime;
33
+
34
+ class EventableDescriptor;
35
+
36
+
37
+ /********************
38
+ class EventMachine_t
39
+ ********************/
40
+
41
+ class EventMachine_t
42
+ {
43
+ public:
44
+ EventMachine_t (void(*event_callback)(const char*, int, const char*, int));
45
+ virtual ~EventMachine_t();
46
+
47
+ void Run();
48
+ void ScheduleHalt();
49
+ const char *InstallOneshotTimer (int);
50
+ const char *ConnectToServer (const char *, int);
51
+ const char *CreateTcpServer (const char *, int);
52
+
53
+ void Add (EventableDescriptor*);
54
+
55
+ public:
56
+ enum { // Event names
57
+ TIMER_FIRED = 100,
58
+ CONNECTION_READ = 101,
59
+ CONNECTION_UNBOUND = 102,
60
+ CONNECTION_ACCEPTED = 103
61
+ };
62
+
63
+
64
+ private:
65
+ bool _RunOnce();
66
+ bool _RunTimers();
67
+ void _AddNewDescriptors();
68
+
69
+ private:
70
+ enum {
71
+ MaxOutstandingTimers = 40,
72
+ HeartbeatInterval = 2
73
+ };
74
+ void (*EventCallback)(const char*, int, const char*, int);
75
+
76
+ class Timer_t: public Bindable_t {
77
+ };
78
+
79
+ multimap<time_t, Timer_t> Timers;
80
+ vector<EventableDescriptor*> Descriptors;
81
+ vector<EventableDescriptor*> NewDescriptors;
82
+
83
+ time_t NextHeartbeatTime;
84
+ };
85
+
86
+
87
+
88
+
89
+ #endif // __EventMachine__H_
90
+
@@ -0,0 +1,31 @@
1
+ # $Id: extconf.rb 2291 2006-04-14 03:56:18Z francis $
2
+ #
3
+ #----------------------------------------------------------------------------
4
+ #
5
+ # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
6
+ #
7
+ # Gmail: garbagecat20
8
+ #
9
+ # This program is free software; you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation; either version 2 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # This program is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with this program; if not, write to the Free Software
21
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
+ #
23
+ #---------------------------------------------------------------------------
24
+ #
25
+ # extconf.rb for Ruby/EventMachine
26
+ # We have to munge LDSHARED because this code needs a C++ link.
27
+ #
28
+
29
+ require 'mkmf'
30
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
31
+ create_makefile "libeventmachine"
@@ -0,0 +1,312 @@
1
+ /*****************************************************************************
2
+
3
+ $Id: libmain.cpp 2291 2006-04-14 03:56:18Z francis $
4
+
5
+ File: libmain.cpp
6
+ Date: 06Apr06
7
+
8
+ Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: garbagecat20
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation; either version 2 of the License, or
14
+ (at your option) any later version.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
+
25
+ *****************************************************************************/
26
+
27
+ #include <ruby.h>
28
+ #include "project.h"
29
+
30
+
31
+ static EventMachine_t *EventMachine;
32
+
33
+
34
+ /******************
35
+ initialize_library
36
+ ******************/
37
+
38
+ extern "C" void initialize_library (void(*cb)(const char*, int, const char*, int))
39
+ {
40
+ InstallSignalHandlers();
41
+ if (EventMachine)
42
+ throw std::runtime_error ("already initialized");
43
+ EventMachine = new EventMachine_t (cb);
44
+ }
45
+
46
+
47
+ /***************
48
+ release_library
49
+ ***************/
50
+
51
+ extern "C" void release_library()
52
+ {
53
+ if (!EventMachine)
54
+ throw std::runtime_error ("not initialized");
55
+ delete EventMachine;
56
+ EventMachine = NULL;
57
+ }
58
+
59
+
60
+ /***********
61
+ run_machine
62
+ ***********/
63
+
64
+ extern "C" void run_machine()
65
+ {
66
+ if (!EventMachine)
67
+ throw std::runtime_error ("not initialized");
68
+ EventMachine->Run();
69
+ }
70
+
71
+
72
+ /*********************
73
+ install_oneshot_timer
74
+ *********************/
75
+
76
+ extern "C" const char *install_oneshot_timer (int seconds)
77
+ {
78
+ if (!EventMachine)
79
+ throw std::runtime_error ("not initialized");
80
+ return EventMachine->InstallOneshotTimer (seconds);
81
+ }
82
+
83
+
84
+ /*****************
85
+ connect_to_server
86
+ *****************/
87
+
88
+ extern "C" const char *connect_to_server (const char *server, int port)
89
+ {
90
+ if (!EventMachine)
91
+ throw std::runtime_error ("not initialized");
92
+ return EventMachine->ConnectToServer (server, port);
93
+ }
94
+
95
+
96
+ /*****************
97
+ create_tcp_server
98
+ *****************/
99
+
100
+ extern "C" const char *create_tcp_server (const char *address, int port)
101
+ {
102
+ if (!EventMachine)
103
+ throw std::runtime_error ("not initialized");
104
+ return EventMachine->CreateTcpServer (address, port);
105
+ }
106
+
107
+
108
+ /***********************
109
+ send_data_to_connection
110
+ ***********************/
111
+
112
+ extern "C" int send_data_to_connection (const char *binding, const char *data, int data_length)
113
+ {
114
+ if (!EventMachine)
115
+ throw std::runtime_error ("not initialized");
116
+ return ConnectionDescriptor::SendDataToConnection (binding, data, data_length);
117
+ }
118
+
119
+
120
+ /****************
121
+ close_connection
122
+ ****************/
123
+
124
+ extern "C" void close_connection (const char *binding, int after_writing)
125
+ {
126
+ if (!EventMachine)
127
+ throw std::runtime_error ("not initialized");
128
+ ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false));
129
+ }
130
+
131
+
132
+
133
+
134
+ /*******
135
+ Statics
136
+ *******/
137
+
138
+ static VALUE EmModule;
139
+
140
+ /****************
141
+ t_event_callback
142
+ ****************/
143
+
144
+ static void event_callback (const char *a1, int a2, const char *a3, int a4)
145
+ {
146
+ rb_funcall (EmModule, rb_intern ("event_callback"), 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4));
147
+ }
148
+
149
+ /**************************
150
+ t_initialize_event_machine
151
+ **************************/
152
+
153
+ static VALUE t_initialize_event_machine (VALUE self)
154
+ {
155
+ InstallSignalHandlers();
156
+ if (EventMachine)
157
+ rb_raise (rb_eRuntimeError, "event-machine already initialized");
158
+ EventMachine = new EventMachine_t (event_callback);
159
+ return Qnil;
160
+ }
161
+
162
+
163
+ /*************
164
+ t_run_machine
165
+ *************/
166
+
167
+ static VALUE t_run_machine (VALUE self)
168
+ {
169
+ if (!EventMachine)
170
+ rb_raise (rb_eRuntimeError, "event-machine not initialized");
171
+ EventMachine->Run();
172
+ return Qnil;
173
+ }
174
+
175
+
176
+ /*******************
177
+ t_add_oneshot_timer
178
+ *******************/
179
+
180
+ static VALUE t_add_oneshot_timer (VALUE self, VALUE interval)
181
+ {
182
+ if (!EventMachine)
183
+ rb_raise (rb_eRuntimeError, "event-machine not initialized");
184
+ const char *f = EventMachine->InstallOneshotTimer (FIX2INT (interval));
185
+ if (!f || !*f)
186
+ rb_raise (rb_eRuntimeError, "no timer");
187
+ return rb_str_new2 (f);
188
+ }
189
+
190
+
191
+ /**************
192
+ t_start_server
193
+ **************/
194
+
195
+ static VALUE t_start_server (VALUE self, VALUE server, VALUE port)
196
+ {
197
+ if (!EventMachine)
198
+ rb_raise (rb_eRuntimeError, "event-machine not initialized");
199
+ const char *f = EventMachine->CreateTcpServer (StringValuePtr(server), FIX2INT(port));
200
+ if (!f || !*f)
201
+ rb_raise (rb_eRuntimeError, "no acceptor");
202
+ return rb_str_new2 (f);
203
+ }
204
+
205
+
206
+
207
+ /***********
208
+ t_send_data
209
+ ***********/
210
+
211
+ static VALUE t_send_data (VALUE self, VALUE signature, VALUE data, VALUE data_length)
212
+ {
213
+ if (!EventMachine)
214
+ rb_raise (rb_eRuntimeError, "event-machine not initialized");
215
+ int b = ConnectionDescriptor::SendDataToConnection (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length));
216
+ return (b << 1) | 1;
217
+ }
218
+
219
+
220
+ /******************
221
+ t_close_connection
222
+ ******************/
223
+
224
+ static VALUE t_close_connection (VALUE self, VALUE signature, VALUE after_writing)
225
+ {
226
+ if (!EventMachine)
227
+ rb_raise (rb_eRuntimeError, "event-machine not initialized");
228
+ ConnectionDescriptor::CloseConnection (StringValuePtr(signature), ((after_writing == Qtrue) ? true : false));
229
+ return Qnil;
230
+ }
231
+
232
+
233
+
234
+ /****************
235
+ t_connect_server
236
+ ****************/
237
+
238
+ static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
239
+ {
240
+ if (!EventMachine)
241
+ rb_raise (rb_eRuntimeError, "event-machine not initialized");
242
+ const char *f = EventMachine->ConnectToServer (StringValuePtr(server), FIX2INT(port));
243
+ if (!f || !*f)
244
+ rb_raise (rb_eRuntimeError, "no connection");
245
+ return rb_str_new2 (f);
246
+ }
247
+
248
+
249
+
250
+ /*****************
251
+ t_release_machine
252
+ *****************/
253
+
254
+ static VALUE t_release_machine (VALUE self)
255
+ {
256
+ if (!EventMachine)
257
+ rb_raise (rb_eRuntimeError, "event-machine not initialized");
258
+ delete EventMachine;
259
+ EventMachine = NULL;
260
+ // ff line is a mistake, removed 11Apr06. EmModule is set permanently
261
+ // for the process when we create the EventMachine module in Init_libeventmachine.
262
+ //EmModule = Qnil;
263
+ return Qnil;
264
+ }
265
+
266
+
267
+ /******
268
+ t_stop
269
+ ******/
270
+
271
+ static VALUE t_stop (VALUE self)
272
+ {
273
+ if (!EventMachine)
274
+ rb_raise (rb_eRuntimeError, "event-machine not initialized");
275
+ EventMachine->ScheduleHalt();
276
+ return Qnil;
277
+ }
278
+
279
+
280
+
281
+ /********************
282
+ Init_libeventmachine
283
+ ********************/
284
+
285
+ extern "C" void Init_libeventmachine()
286
+ {
287
+ // INCOMPLETE, we need to define class Connectons inside module EventMachine
288
+ EmModule = rb_define_module ("EventMachine");
289
+ rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
290
+ rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine, 0);
291
+ rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
292
+ rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
293
+ rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
294
+ rb_define_module_function (EmModule, "close_connection", (VALUE(*)(...))t_close_connection, 2);
295
+ rb_define_module_function (EmModule, "connect_server", (VALUE(*)(...))t_connect_server, 2);
296
+ rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
297
+ rb_define_module_function (EmModule, "start_server", (VALUE(*)(...))t_release_machine, 0);
298
+ rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
299
+
300
+ // Why am I missing the rb_ function that converts a class/module name to a VALUE?
301
+ VALUE exception = rb_eval_string ("Exception");
302
+ rb_define_class_under (EmModule, "ConnectionNotBound", exception);
303
+ rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", exception);
304
+ rb_define_class_under (EmModule, "UnknownTimerFired", exception);
305
+
306
+ rb_define_const (EmModule, "TimerFired", (100 << 1) | 1);
307
+ rb_define_const (EmModule, "ConnectionData", (101 << 1) | 1);
308
+ rb_define_const (EmModule, "ConnectionUnbound", (102 << 1) | 1);
309
+ rb_define_const (EmModule, "ConnectionAccepted", (103 << 1) | 1);
310
+
311
+ }
312
+
@@ -0,0 +1,63 @@
1
+ /*****************************************************************************
2
+
3
+ $Id: project.h 2291 2006-04-14 03:56:18Z francis $
4
+
5
+ File: project.h
6
+ Date: 06Apr06
7
+
8
+ Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: garbagecat20
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation; either version 2 of the License, or
14
+ (at your option) any later version.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
+
25
+ *****************************************************************************/
26
+
27
+
28
+ #ifndef __Project__H_
29
+ #define __Project__H_
30
+
31
+
32
+ #include <iostream>
33
+ #include <map>
34
+ #include <vector>
35
+ #include <deque>
36
+ #include <string>
37
+ #include <sstream>
38
+ #include <stdexcept>
39
+ #include <signal.h>
40
+ #include <netdb.h>
41
+ #include <sys/types.h>
42
+ #include <sys/socket.h>
43
+ #include <assert.h>
44
+ #include <unistd.h>
45
+ #include <fcntl.h>
46
+ #include <errno.h>
47
+ #include <netinet/in.h>
48
+ #include <netinet/tcp.h>
49
+ #include <arpa/inet.h>
50
+ #include <uuid/uuid.h>
51
+ using namespace std;
52
+
53
+
54
+
55
+ #include "binder.h"
56
+ #include "em.h"
57
+ #include "sigs.h"
58
+ #include "ed.h"
59
+
60
+
61
+
62
+
63
+ #endif // __Project__H_