eventmachine 0.5.3 → 0.7.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.
data/ext/files.cpp ADDED
@@ -0,0 +1,101 @@
1
+ /*****************************************************************************
2
+
3
+ $Id: ed.cpp 250 2006-08-25 02:17:58Z blackhedd $
4
+
5
+ File: files.cpp
6
+ Date: 26Aug06
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 "project.h"
28
+
29
+
30
+ /******************************************
31
+ FileStreamDescriptor::FileStreamDescriptor
32
+ ******************************************/
33
+
34
+ FileStreamDescriptor::FileStreamDescriptor (int fd):
35
+ EventableDescriptor (fd),
36
+ OutboundDataSize (0)
37
+ {
38
+ cerr << "#####";
39
+ }
40
+
41
+
42
+ /*******************************************
43
+ FileStreamDescriptor::~FileStreamDescriptor
44
+ *******************************************/
45
+
46
+ FileStreamDescriptor::~FileStreamDescriptor()
47
+ {
48
+ // Run down any stranded outbound data.
49
+ for (size_t i=0; i < OutboundPages.size(); i++)
50
+ OutboundPages[i].Free();
51
+ }
52
+
53
+
54
+ /**************************
55
+ FileStreamDescriptor::Read
56
+ **************************/
57
+
58
+ void FileStreamDescriptor::Read()
59
+ {
60
+ }
61
+
62
+ /***************************
63
+ FileStreamDescriptor::Write
64
+ ***************************/
65
+
66
+ void FileStreamDescriptor::Write()
67
+ {
68
+ }
69
+
70
+
71
+ /*******************************
72
+ FileStreamDescriptor::Heartbeat
73
+ *******************************/
74
+
75
+ void FileStreamDescriptor::Heartbeat()
76
+ {
77
+ }
78
+
79
+
80
+ /***********************************
81
+ FileStreamDescriptor::SelectForRead
82
+ ***********************************/
83
+
84
+ bool FileStreamDescriptor::SelectForRead()
85
+ {
86
+ cerr << "R?";
87
+ return false;
88
+ }
89
+
90
+
91
+ /************************************
92
+ FileStreamDescriptor::SelectForWrite
93
+ ************************************/
94
+
95
+ bool FileStreamDescriptor::SelectForWrite()
96
+ {
97
+ cerr << "W?";
98
+ return false;
99
+ }
100
+
101
+
data/ext/files.h ADDED
@@ -0,0 +1,72 @@
1
+ /*****************************************************************************
2
+
3
+ $Id: ed.h 243 2006-08-23 02:00:10Z blackhedd $
4
+
5
+ File: files.h
6
+ Date: 26Aug06
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 __FileStreamDescriptor__H_
29
+ #define __FileStreamDescriptor__H_
30
+
31
+
32
+
33
+ /**************************
34
+ class FileStreamDescriptor
35
+ **************************/
36
+
37
+ class FileStreamDescriptor: public EventableDescriptor
38
+ {
39
+ public:
40
+ FileStreamDescriptor (int);
41
+ virtual ~FileStreamDescriptor();
42
+
43
+ virtual void Read();
44
+ virtual void Write();
45
+ virtual void Heartbeat();
46
+
47
+ virtual bool SelectForRead();
48
+ virtual bool SelectForWrite();
49
+
50
+ // Do we have any data to write? This is used by ShouldDelete.
51
+ virtual int GetOutboundDataSize() {return OutboundDataSize;}
52
+
53
+ protected:
54
+ struct OutboundPage {
55
+ OutboundPage (const char *b, int l, int o=0): Buffer(b), Length(l), Offset(o) {}
56
+ void Free() {if (Buffer) free ((char*)Buffer); }
57
+ const char *Buffer;
58
+ int Length;
59
+ int Offset;
60
+ };
61
+
62
+ protected:
63
+ deque<OutboundPage> OutboundPages;
64
+ int OutboundDataSize;
65
+
66
+ private:
67
+
68
+ };
69
+
70
+
71
+ #endif // __FileStreamDescriptor__H_
72
+
data/ext/project.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: project.h 47 2006-05-15 21:42:38Z blackhedd $
3
+ $Id: project.h 265 2006-10-05 19:07:45Z blackhedd $
4
4
 
5
5
  File: project.h
6
6
  Date: 06Apr06
@@ -47,6 +47,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
47
47
  #include <netdb.h>
48
48
  #include <sys/types.h>
49
49
  #include <sys/socket.h>
50
+ #include <sys/un.h>
50
51
  #include <assert.h>
51
52
  #include <unistd.h>
52
53
  #include <fcntl.h>
@@ -86,6 +87,7 @@ using namespace std;
86
87
  #include "em.h"
87
88
  #include "sigs.h"
88
89
  #include "ed.h"
90
+ #include "files.h"
89
91
  #include "page.h"
90
92
  #include "ssl.h"
91
93
 
data/ext/rubymain.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: rubymain.cpp 50 2006-05-15 22:16:39Z blackhedd $
3
+ $Id: rubymain.cpp 265 2006-10-05 19:07:45Z blackhedd $
4
4
 
5
5
  File: libmain.cpp
6
6
  Date: 06Apr06
@@ -97,6 +97,19 @@ static VALUE t_start_server (VALUE self, VALUE server, VALUE port)
97
97
  }
98
98
 
99
99
 
100
+ /*******************
101
+ t_start_unix_server
102
+ *******************/
103
+
104
+ static VALUE t_start_unix_server (VALUE self, VALUE filename)
105
+ {
106
+ const char *f = evma_create_unix_domain_server (StringValuePtr(filename));
107
+ if (!f || !*f)
108
+ rb_raise (rb_eRuntimeError, "no unix-domain acceptor");
109
+ return rb_str_new2 (f);
110
+ }
111
+
112
+
100
113
 
101
114
  /***********
102
115
  t_send_data
@@ -119,6 +132,44 @@ static VALUE t_start_tls (VALUE self, VALUE signature)
119
132
  return Qnil;
120
133
  }
121
134
 
135
+ /**************
136
+ t_get_peername
137
+ **************/
138
+
139
+ static VALUE t_get_peername (VALUE self, VALUE signature)
140
+ {
141
+ struct sockaddr s;
142
+ if (evma_get_peername (StringValuePtr (signature), &s)) {
143
+ return rb_str_new ((const char*)&s, sizeof(s));
144
+ }
145
+
146
+ return Qnil;
147
+ }
148
+
149
+ /*****************************
150
+ t_get_comm_inactivity_timeout
151
+ *****************************/
152
+
153
+ static VALUE t_get_comm_inactivity_timeout (VALUE self, VALUE signature)
154
+ {
155
+ int timeout;
156
+ if (evma_get_comm_inactivity_timeout (StringValuePtr (signature), &timeout))
157
+ return INT2FIX (timeout);
158
+ return Qnil;
159
+ }
160
+
161
+ /*****************************
162
+ t_set_comm_inactivity_timeout
163
+ *****************************/
164
+
165
+ static VALUE t_set_comm_inactivity_timeout (VALUE self, VALUE signature, VALUE timeout)
166
+ {
167
+ int ti = FIX2INT (timeout);
168
+ if (evma_set_comm_inactivity_timeout (StringValuePtr (signature), &ti));
169
+ return Qtrue;
170
+ return Qnil;
171
+ }
172
+
122
173
 
123
174
  /***************
124
175
  t_send_datagram
@@ -190,6 +241,50 @@ static VALUE t_stop (VALUE self)
190
241
  return Qnil;
191
242
  }
192
243
 
244
+ /******************
245
+ t_signal_loopbreak
246
+ ******************/
247
+
248
+ static VALUE t_signal_loopbreak (VALUE self)
249
+ {
250
+ evma_signal_loopbreak();
251
+ return Qnil;
252
+ }
253
+
254
+ /**************
255
+ t_library_type
256
+ **************/
257
+
258
+ static VALUE t_library_type (VALUE self)
259
+ {
260
+ return rb_eval_string (":extension");
261
+ }
262
+
263
+
264
+
265
+ /*******************
266
+ t_set_timer_quantum
267
+ *******************/
268
+
269
+ static VALUE t_set_timer_quantum (VALUE self, VALUE interval)
270
+ {
271
+ evma_set_timer_quantum (FIX2INT (interval));
272
+ return Qnil;
273
+ }
274
+
275
+
276
+
277
+ /*************
278
+ t__write_file
279
+ *************/
280
+
281
+ static VALUE t__write_file (VALUE self, VALUE filename)
282
+ {
283
+ const char *f = evma__write_file (StringValuePtr (filename));
284
+ if (!f || !*f)
285
+ rb_raise (rb_eRuntimeError, "file not opened");
286
+ return rb_str_new2 (f);
287
+ }
193
288
 
194
289
 
195
290
  /*********************
@@ -207,6 +302,7 @@ extern "C" void Init_rubyeventmachine()
207
302
  rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine_without_threads, 0);
208
303
  rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
209
304
  rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
305
+ rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1);
210
306
  rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1);
211
307
  rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
212
308
  rb_define_module_function (EmModule, "send_datagram", (VALUE(*)(...))t_send_datagram, 5);
@@ -215,14 +311,26 @@ extern "C" void Init_rubyeventmachine()
215
311
  rb_define_module_function (EmModule, "open_udp_socket", (VALUE(*)(...))t_open_udp_socket, 2);
216
312
  rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
217
313
  rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
314
+ rb_define_module_function (EmModule, "signal_loopbreak", (VALUE(*)(...))t_signal_loopbreak, 0);
315
+ rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0);
316
+ rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
317
+
318
+ // Provisional:
319
+ rb_define_module_function (EmModule, "_write_file", (VALUE(*)(...))t__write_file, 1);
320
+
321
+ rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
322
+ rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
323
+ rb_define_module_function (EmModule, "set_comm_inactivity_timeout", (VALUE(*)(...))t_set_comm_inactivity_timeout, 2);
218
324
 
219
325
  rb_define_class_under (EmModule, "ConnectionNotBound", rb_eException);
220
326
  rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eException);
221
327
  rb_define_class_under (EmModule, "UnknownTimerFired", rb_eException);
222
328
 
223
- rb_define_const (EmModule, "TimerFired", (100 << 1) | 1);
224
- rb_define_const (EmModule, "ConnectionData", (101 << 1) | 1);
225
- rb_define_const (EmModule, "ConnectionUnbound", (102 << 1) | 1);
226
- rb_define_const (EmModule, "ConnectionAccepted", (103 << 1) | 1);
329
+ rb_define_const (EmModule, "TimerFired", INT2NUM(100));
330
+ rb_define_const (EmModule, "ConnectionData", INT2NUM(101));
331
+ rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(102));
332
+ rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(103));
333
+ rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(104));
334
+ rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(105));
227
335
  }
228
336
 
@@ -0,0 +1,89 @@
1
+ # $Id: deferrable.rb 216 2006-07-17 10:20:42Z blackhedd $
2
+ #
3
+ # Author:: blackhedd (gmail address: garbagecat10).
4
+ # Date:: 16 July 2006
5
+ #
6
+ # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
7
+ #
8
+ # This program is made available under the terms of the GPL version 2.
9
+ #
10
+ # See EventMachine and EventMachine::Connection for documentation and
11
+ # usage examples.
12
+ #
13
+ #----------------------------------------------------------------------------
14
+ #
15
+ # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
+ #
17
+ # Gmail: garbagecat10
18
+ #
19
+ # This program is free software; you can redistribute it and/or modify
20
+ # it under the terms of the GNU General Public License as published by
21
+ # the Free Software Foundation; either version 2 of the License, or
22
+ # (at your option) any later version.
23
+ #
24
+ # This program is distributed in the hope that it will be useful,
25
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ # GNU General Public License for more details.
28
+ #
29
+ # You should have received a copy of the GNU General Public License
30
+ # along with this program; if not, write to the Free Software
31
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32
+ #
33
+ #---------------------------------------------------------------------------
34
+ #
35
+ #
36
+
37
+ require 'forwardable'
38
+
39
+ module EventMachine
40
+
41
+ module Deferrable
42
+ def callback &block
43
+ return unless block
44
+ if @deferred_status == :succeeded
45
+ block.call
46
+ else
47
+ @callbacks ||= []
48
+ @callbacks << block
49
+ end
50
+ end
51
+
52
+ def errback &block
53
+ return unless block
54
+ if @deferred_status == :failed
55
+ block.call
56
+ else
57
+ @errbacks ||= []
58
+ @errbacks << block
59
+ end
60
+ end
61
+
62
+ # Note that if you call this method without arguments,
63
+ # no arguments will be passed to the callback/errback.
64
+ # If the user has coded these with arguments, then the
65
+ # user code will throw an argument exception.
66
+ # Implementors of deferrable classes <b>must</b>
67
+ # document the arguments they will supply to user callbacks.
68
+ def set_deferred_status arg, *args
69
+ @deferred_status = arg
70
+ @deferred_args = args
71
+ case @deferred_status
72
+ when :succeeded
73
+ if @callbacks
74
+ while cb = @callbacks.shift
75
+ cb.call *@deferred_args
76
+ end
77
+ end
78
+ when :failed
79
+ if @errbacks
80
+ while eb = @errbacks.shift
81
+ eb.call *@deferred_args
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+
@@ -0,0 +1,50 @@
1
+ # $Id: eventable.rb 252 2006-09-02 19:23:20Z blackhedd $
2
+ #
3
+ # Author:: blackhedd (gmail address: garbagecat10).
4
+ # Date:: 16 July 2006
5
+ #
6
+ # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
7
+ #
8
+ # This program is made available under the terms of the GPL version 2.
9
+ #
10
+ # See EventMachine and EventMachine::Connection for documentation and
11
+ # usage examples.
12
+ #
13
+ #----------------------------------------------------------------------------
14
+ #
15
+ # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
+ #
17
+ # Gmail: garbagecat10
18
+ #
19
+ # This program is free software; you can redistribute it and/or modify
20
+ # it under the terms of the GNU General Public License as published by
21
+ # the Free Software Foundation; either version 2 of the License, or
22
+ # (at your option) any later version.
23
+ #
24
+ # This program is distributed in the hope that it will be useful,
25
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ # GNU General Public License for more details.
28
+ #
29
+ # You should have received a copy of the GNU General Public License
30
+ # along with this program; if not, write to the Free Software
31
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32
+ #
33
+ #---------------------------------------------------------------------------
34
+ #
35
+ #
36
+
37
+
38
+ module EventMachine
39
+ module Eventable
40
+
41
+ def listen_event event_name
42
+ end
43
+
44
+ def post_event event_name, arg
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+