eventmachine 0.12.8-x86-mswin32-60 → 0.12.10-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.gitignore +14 -13
  2. data/Rakefile +374 -264
  3. data/eventmachine.gemspec +4 -5
  4. data/ext/binder.cpp +125 -126
  5. data/ext/binder.h +46 -48
  6. data/ext/cmain.cpp +184 -42
  7. data/ext/cplusplus.cpp +202 -202
  8. data/ext/ed.cpp +242 -81
  9. data/ext/ed.h +39 -22
  10. data/ext/em.cpp +127 -108
  11. data/ext/em.h +27 -18
  12. data/ext/emwin.cpp +3 -3
  13. data/ext/eventmachine.h +49 -38
  14. data/ext/eventmachine_cpp.h +96 -96
  15. data/ext/extconf.rb +147 -132
  16. data/ext/fastfilereader/extconf.rb +82 -76
  17. data/ext/project.h +151 -140
  18. data/ext/rubymain.cpp +222 -103
  19. data/ext/ssl.cpp +460 -460
  20. data/ext/ssl.h +94 -94
  21. data/java/src/com/rubyeventmachine/EmReactor.java +570 -423
  22. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -57
  23. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -171
  24. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -244
  25. data/java/src/com/rubyeventmachine/{Application.java → application/Application.java} +194 -200
  26. data/java/src/com/rubyeventmachine/{Connection.java → application/Connection.java} +74 -74
  27. data/java/src/com/rubyeventmachine/{ConnectionFactory.java → application/ConnectionFactory.java} +36 -36
  28. data/java/src/com/rubyeventmachine/{DefaultConnectionFactory.java → application/DefaultConnectionFactory.java} +46 -46
  29. data/java/src/com/rubyeventmachine/{PeriodicTimer.java → application/PeriodicTimer.java} +38 -38
  30. data/java/src/com/rubyeventmachine/{Timer.java → application/Timer.java} +54 -54
  31. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -108
  32. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -146
  33. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -53
  34. data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -74
  35. data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -89
  36. data/lib/em/connection.rb +71 -12
  37. data/lib/em/deferrable.rb +191 -186
  38. data/lib/em/protocols.rb +36 -35
  39. data/lib/em/protocols/httpclient2.rb +590 -582
  40. data/lib/em/protocols/line_and_text.rb +125 -126
  41. data/lib/em/protocols/linetext2.rb +161 -160
  42. data/lib/em/protocols/object_protocol.rb +45 -39
  43. data/lib/em/protocols/smtpclient.rb +357 -331
  44. data/lib/em/protocols/socks4.rb +66 -0
  45. data/lib/em/queue.rb +60 -60
  46. data/lib/em/timers.rb +56 -55
  47. data/lib/em/version.rb +1 -1
  48. data/lib/eventmachine.rb +125 -169
  49. data/lib/jeventmachine.rb +257 -142
  50. data/tasks/{cpp.rake → cpp.rake_example} +76 -76
  51. data/tests/test_attach.rb +125 -100
  52. data/tests/test_basic.rb +1 -2
  53. data/tests/test_connection_count.rb +34 -44
  54. data/tests/test_epoll.rb +0 -2
  55. data/tests/test_get_sock_opt.rb +30 -0
  56. data/tests/test_httpclient2.rb +3 -3
  57. data/tests/test_inactivity_timeout.rb +21 -1
  58. data/tests/test_ltp.rb +182 -188
  59. data/tests/test_next_tick.rb +0 -2
  60. data/tests/test_pause.rb +70 -0
  61. data/tests/test_pending_connect_timeout.rb +48 -0
  62. data/tests/test_ssl_args.rb +78 -67
  63. data/tests/test_timers.rb +162 -141
  64. metadata +13 -11
  65. data/tasks/project.rake +0 -79
  66. data/tasks/tests.rake +0 -193
@@ -1,57 +1,69 @@
1
- /**
2
- * $Id$
3
- *
4
- * Author:: Francis Cianfrocca (gmail: blackhedd)
5
- * Homepage:: http://rubyeventmachine.com
6
- * Date:: 15 Jul 2007
7
- *
8
- * See EventMachine and EventMachine::Connection for documentation and
9
- * usage examples.
10
- *
11
- *
12
- *----------------------------------------------------------------------------
13
- *
14
- * Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
15
- * Gmail: blackhedd
16
- *
17
- * This program is free software; you can redistribute it and/or modify
18
- * it under the terms of either: 1) the GNU General Public License
19
- * as published by the Free Software Foundation; either version 2 of the
20
- * License, or (at your option) any later version; or 2) Ruby's License.
21
- *
22
- * See the file COPYING for complete licensing information.
23
- *
24
- *---------------------------------------------------------------------------
25
- *
26
- *
27
- */
28
-
29
-
30
- package com.rubyeventmachine;
31
-
32
- import java.nio.ByteBuffer;
33
-
34
- public interface EventableChannel {
35
-
36
- public void scheduleOutboundData (ByteBuffer bb);
37
-
38
- public void scheduleOutboundDatagram (ByteBuffer bb, String recipAddress, int recipPort);
39
-
40
- public void scheduleClose (boolean afterWriting);
41
-
42
- public void startTls();
43
-
44
- public String getBinding();
45
-
46
- public void readInboundData (ByteBuffer dst);
47
-
48
- /**
49
- * This is called by the reactor after it finishes running.
50
- * The idea is to free network resources.
51
- */
52
- public void close();
53
-
54
- public boolean writeOutboundData();
55
-
56
- public void setCommInactivityTimeout (long seconds);
57
- }
1
+ /**
2
+ * $Id$
3
+ *
4
+ * Author:: Francis Cianfrocca (gmail: blackhedd)
5
+ * Homepage:: http://rubyeventmachine.com
6
+ * Date:: 15 Jul 2007
7
+ *
8
+ * See EventMachine and EventMachine::Connection for documentation and
9
+ * usage examples.
10
+ *
11
+ *
12
+ *----------------------------------------------------------------------------
13
+ *
14
+ * Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
15
+ * Gmail: blackhedd
16
+ *
17
+ * This program is free software; you can redistribute it and/or modify
18
+ * it under the terms of either: 1) the GNU General Public License
19
+ * as published by the Free Software Foundation; either version 2 of the
20
+ * License, or (at your option) any later version; or 2) Ruby's License.
21
+ *
22
+ * See the file COPYING for complete licensing information.
23
+ *
24
+ *---------------------------------------------------------------------------
25
+ *
26
+ *
27
+ */
28
+
29
+
30
+ package com.rubyeventmachine;
31
+
32
+ import java.nio.ByteBuffer;
33
+ import java.io.IOException;
34
+ import java.nio.channels.ClosedChannelException;
35
+
36
+ public interface EventableChannel {
37
+
38
+ public void scheduleOutboundData (ByteBuffer bb);
39
+
40
+ public void scheduleOutboundDatagram (ByteBuffer bb, String recipAddress, int recipPort);
41
+
42
+ public boolean scheduleClose (boolean afterWriting);
43
+
44
+ public void startTls();
45
+
46
+ public long getBinding();
47
+
48
+ public void readInboundData (ByteBuffer dst) throws IOException;
49
+
50
+ public void register() throws ClosedChannelException;
51
+
52
+ /**
53
+ * This is called by the reactor after it finishes running.
54
+ * The idea is to free network resources.
55
+ */
56
+ public void close();
57
+
58
+ public boolean writeOutboundData() throws IOException;
59
+
60
+ public void setCommInactivityTimeout (long seconds);
61
+
62
+ public Object[] getPeerName();
63
+
64
+ public boolean isWatchOnly();
65
+
66
+ public boolean isNotifyReadable();
67
+ public boolean isNotifyWritable();
68
+
69
+ }
@@ -1,171 +1,189 @@
1
- /**
2
- * $Id$
3
- *
4
- * Author:: Francis Cianfrocca (gmail: blackhedd)
5
- * Homepage:: http://rubyeventmachine.com
6
- * Date:: 15 Jul 2007
7
- *
8
- * See EventMachine and EventMachine::Connection for documentation and
9
- * usage examples.
10
- *
11
- *
12
- *----------------------------------------------------------------------------
13
- *
14
- * Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
15
- * Gmail: blackhedd
16
- *
17
- * This program is free software; you can redistribute it and/or modify
18
- * it under the terms of either: 1) the GNU General Public License
19
- * as published by the Free Software Foundation; either version 2 of the
20
- * License, or (at your option) any later version; or 2) Ruby's License.
21
- *
22
- * See the file COPYING for complete licensing information.
23
- *
24
- *---------------------------------------------------------------------------
25
- *
26
- *
27
- */
28
-
29
-
30
- package com.rubyeventmachine;
31
-
32
- import java.nio.ByteBuffer;
33
- import java.nio.channels.ClosedChannelException;
34
- import java.nio.channels.SelectionKey;
35
- import java.nio.channels.Selector;
36
- import java.nio.channels.DatagramChannel;
37
- import java.util.LinkedList;
38
- import java.io.*;
39
- import java.net.*;
40
-
41
- public class EventableDatagramChannel implements EventableChannel {
42
-
43
- class Packet {
44
- public ByteBuffer bb;
45
- public SocketAddress recipient;
46
- public Packet (ByteBuffer _bb, SocketAddress _recipient) {
47
- bb = _bb;
48
- recipient = _recipient;
49
- }
50
- }
51
-
52
- DatagramChannel channel;
53
- String binding;
54
- Selector selector;
55
- boolean bCloseScheduled;
56
- LinkedList<Packet> outboundQ;
57
- SocketAddress returnAddress;
58
-
59
-
60
- public EventableDatagramChannel (DatagramChannel dc, String _binding, Selector sel) throws ClosedChannelException {
61
- channel = dc;
62
- binding = _binding;
63
- selector = sel;
64
- bCloseScheduled = false;
65
- outboundQ = new LinkedList<Packet>();
66
-
67
- dc.register(selector, SelectionKey.OP_READ, this);
68
- }
69
-
70
- public void scheduleOutboundData (ByteBuffer bb) {
71
- try {
72
- if ((!bCloseScheduled) && (bb.remaining() > 0)) {
73
- outboundQ.addLast(new Packet(bb, returnAddress));
74
- channel.register(selector, SelectionKey.OP_WRITE | SelectionKey.OP_READ, this);
75
- }
76
- } catch (ClosedChannelException e) {
77
- throw new RuntimeException ("no outbound data");
78
- }
79
- }
80
-
81
- public void scheduleOutboundDatagram (ByteBuffer bb, String recipAddress, int recipPort) {
82
- try {
83
- if ((!bCloseScheduled) && (bb.remaining() > 0)) {
84
- outboundQ.addLast(new Packet (bb, new InetSocketAddress (recipAddress, recipPort)));
85
- channel.register(selector, SelectionKey.OP_WRITE | SelectionKey.OP_READ, this);
86
- }
87
- } catch (ClosedChannelException e) {
88
- throw new RuntimeException ("no outbound data");
89
- }
90
- }
91
-
92
- public void scheduleClose (boolean afterWriting) {
93
- System.out.println ("NOT SCHEDULING CLOSE ON DATAGRAM");
94
- }
95
-
96
- public void startTls() {
97
- throw new RuntimeException ("TLS is unimplemented on this Channel");
98
- }
99
-
100
- public String getBinding() {
101
- return binding;
102
- }
103
-
104
- /**
105
- * Terminate with extreme prejudice. Don't assume there will be another pass through
106
- * the reactor core.
107
- */
108
- public void close() {
109
- try {
110
- channel.close();
111
- } catch (IOException e) {
112
- }
113
- }
114
-
115
- public void readInboundData (ByteBuffer dst) {
116
- returnAddress = null;
117
- try {
118
- // If there is no datagram available (we're nonblocking after all),
119
- // then channel.receive returns null.
120
- returnAddress = channel.receive(dst);
121
- } catch (IOException e) {
122
- // probably a no-op. The caller will see the empty (or even partial) buffer
123
- // and presumably do the right thing.
124
- }
125
- }
126
-
127
- public boolean writeOutboundData() {
128
- while (!outboundQ.isEmpty()) {
129
- Packet p = outboundQ.getFirst();
130
- int written = 0;
131
- try {
132
- // With a datagram socket, it's ok to send an empty buffer.
133
- written = channel.send(p.bb, p.recipient);
134
- }
135
- catch (IOException e) {
136
- return false;
137
- }
138
-
139
- /* Did we consume the whole outbound buffer? If yes, pop it off and
140
- * keep looping. If no, the outbound network buffers are full, so break
141
- * out of here. There's a flaw that affects outbound buffers that are intentionally
142
- * empty. We can tell whether they got sent or not. So we assume they were.
143
- * TODO: As implemented, this ALWAYS discards packets if they were at least
144
- * partially written. This matches the behavior of the C++ EM. My judgment
145
- * is that this is less surprising than fragmenting the data and sending multiple
146
- * packets would be. I could be wrong, so this is subject to change.
147
- */
148
-
149
- if ((written > 0) || (p.bb.remaining() == 0))
150
- outboundQ.removeFirst();
151
- else
152
- break;
153
- }
154
-
155
- if (outboundQ.isEmpty()) {
156
- try {
157
- channel.register(selector, SelectionKey.OP_READ, this);
158
- } catch (ClosedChannelException e) {}
159
- }
160
-
161
- // ALWAYS drain the outbound queue before triggering a connection close.
162
- // If anyone wants to close immediately, they're responsible for clearing
163
- // the outbound queue.
164
- return (bCloseScheduled && outboundQ.isEmpty()) ? false : true;
165
- }
166
-
167
- public void setCommInactivityTimeout (long seconds) {
168
- // TODO
169
- System.out.println ("DATAGRAM: SET COMM INACTIVITY UNIMPLEMENTED " + seconds);
170
- }
171
- }
1
+ /**
2
+ * $Id$
3
+ *
4
+ * Author:: Francis Cianfrocca (gmail: blackhedd)
5
+ * Homepage:: http://rubyeventmachine.com
6
+ * Date:: 15 Jul 2007
7
+ *
8
+ * See EventMachine and EventMachine::Connection for documentation and
9
+ * usage examples.
10
+ *
11
+ *
12
+ *----------------------------------------------------------------------------
13
+ *
14
+ * Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
15
+ * Gmail: blackhedd
16
+ *
17
+ * This program is free software; you can redistribute it and/or modify
18
+ * it under the terms of either: 1) the GNU General Public License
19
+ * as published by the Free Software Foundation; either version 2 of the
20
+ * License, or (at your option) any later version; or 2) Ruby's License.
21
+ *
22
+ * See the file COPYING for complete licensing information.
23
+ *
24
+ *---------------------------------------------------------------------------
25
+ *
26
+ *
27
+ */
28
+
29
+
30
+ package com.rubyeventmachine;
31
+
32
+ import java.nio.ByteBuffer;
33
+ import java.nio.channels.ClosedChannelException;
34
+ import java.nio.channels.SelectionKey;
35
+ import java.nio.channels.Selector;
36
+ import java.nio.channels.DatagramChannel;
37
+ import java.util.LinkedList;
38
+ import java.io.*;
39
+ import java.net.*;
40
+
41
+ public class EventableDatagramChannel implements EventableChannel {
42
+
43
+ class Packet {
44
+ public ByteBuffer bb;
45
+ public SocketAddress recipient;
46
+ public Packet (ByteBuffer _bb, SocketAddress _recipient) {
47
+ bb = _bb;
48
+ recipient = _recipient;
49
+ }
50
+ }
51
+
52
+ DatagramChannel channel;
53
+ long binding;
54
+ Selector selector;
55
+ boolean bCloseScheduled;
56
+ LinkedList<Packet> outboundQ;
57
+ SocketAddress returnAddress;
58
+
59
+
60
+ public EventableDatagramChannel (DatagramChannel dc, long _binding, Selector sel) throws ClosedChannelException {
61
+ channel = dc;
62
+ binding = _binding;
63
+ selector = sel;
64
+ bCloseScheduled = false;
65
+ outboundQ = new LinkedList<Packet>();
66
+
67
+ dc.register(selector, SelectionKey.OP_READ, this);
68
+ }
69
+
70
+ public void scheduleOutboundData (ByteBuffer bb) {
71
+ try {
72
+ if ((!bCloseScheduled) && (bb.remaining() > 0)) {
73
+ outboundQ.addLast(new Packet(bb, returnAddress));
74
+ channel.register(selector, SelectionKey.OP_WRITE | SelectionKey.OP_READ, this);
75
+ }
76
+ } catch (ClosedChannelException e) {
77
+ throw new RuntimeException ("no outbound data");
78
+ }
79
+ }
80
+
81
+ public void scheduleOutboundDatagram (ByteBuffer bb, String recipAddress, int recipPort) {
82
+ try {
83
+ if ((!bCloseScheduled) && (bb.remaining() > 0)) {
84
+ outboundQ.addLast(new Packet (bb, new InetSocketAddress (recipAddress, recipPort)));
85
+ channel.register(selector, SelectionKey.OP_WRITE | SelectionKey.OP_READ, this);
86
+ }
87
+ } catch (ClosedChannelException e) {
88
+ throw new RuntimeException ("no outbound data");
89
+ }
90
+ }
91
+
92
+ public boolean scheduleClose (boolean afterWriting) {
93
+ System.out.println ("NOT SCHEDULING CLOSE ON DATAGRAM");
94
+ return false;
95
+ }
96
+
97
+ public void startTls() {
98
+ throw new RuntimeException ("TLS is unimplemented on this Channel");
99
+ }
100
+
101
+ public long getBinding() {
102
+ return binding;
103
+ }
104
+
105
+ public void register() throws ClosedChannelException {
106
+ // TODO
107
+ }
108
+
109
+ /**
110
+ * Terminate with extreme prejudice. Don't assume there will be another pass through
111
+ * the reactor core.
112
+ */
113
+ public void close() {
114
+ try {
115
+ channel.close();
116
+ } catch (IOException e) {
117
+ }
118
+ }
119
+
120
+ public void readInboundData (ByteBuffer dst) {
121
+ returnAddress = null;
122
+ try {
123
+ // If there is no datagram available (we're nonblocking after all),
124
+ // then channel.receive returns null.
125
+ returnAddress = channel.receive(dst);
126
+ } catch (IOException e) {
127
+ // probably a no-op. The caller will see the empty (or even partial) buffer
128
+ // and presumably do the right thing.
129
+ }
130
+ }
131
+
132
+ public boolean writeOutboundData() {
133
+ while (!outboundQ.isEmpty()) {
134
+ Packet p = outboundQ.getFirst();
135
+ int written = 0;
136
+ try {
137
+ // With a datagram socket, it's ok to send an empty buffer.
138
+ written = channel.send(p.bb, p.recipient);
139
+ }
140
+ catch (IOException e) {
141
+ return false;
142
+ }
143
+
144
+ /* Did we consume the whole outbound buffer? If yes, pop it off and
145
+ * keep looping. If no, the outbound network buffers are full, so break
146
+ * out of here. There's a flaw that affects outbound buffers that are intentionally
147
+ * empty. We can tell whether they got sent or not. So we assume they were.
148
+ * TODO: As implemented, this ALWAYS discards packets if they were at least
149
+ * partially written. This matches the behavior of the C++ EM. My judgment
150
+ * is that this is less surprising than fragmenting the data and sending multiple
151
+ * packets would be. I could be wrong, so this is subject to change.
152
+ */
153
+
154
+ if ((written > 0) || (p.bb.remaining() == 0))
155
+ outboundQ.removeFirst();
156
+ else
157
+ break;
158
+ }
159
+
160
+ if (outboundQ.isEmpty()) {
161
+ try {
162
+ channel.register(selector, SelectionKey.OP_READ, this);
163
+ } catch (ClosedChannelException e) {}
164
+ }
165
+
166
+ // ALWAYS drain the outbound queue before triggering a connection close.
167
+ // If anyone wants to close immediately, they're responsible for clearing
168
+ // the outbound queue.
169
+ return (bCloseScheduled && outboundQ.isEmpty()) ? false : true;
170
+ }
171
+
172
+ public void setCommInactivityTimeout (long seconds) {
173
+ // TODO
174
+ System.out.println ("DATAGRAM: SET COMM INACTIVITY UNIMPLEMENTED " + seconds);
175
+ }
176
+
177
+ public Object[] getPeerName () {
178
+ if (returnAddress != null) {
179
+ InetSocketAddress inetAddr = (InetSocketAddress) returnAddress;
180
+ return new Object[]{ inetAddr.getPort(), inetAddr.getHostName() };
181
+ } else {
182
+ return null;
183
+ }
184
+ }
185
+
186
+ public boolean isWatchOnly() { return false; }
187
+ public boolean isNotifyReadable() { return false; }
188
+ public boolean isNotifyWritable() { return false; }
189
+ }