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.
- data/.gitignore +14 -13
- data/Rakefile +374 -264
- data/eventmachine.gemspec +4 -5
- data/ext/binder.cpp +125 -126
- data/ext/binder.h +46 -48
- data/ext/cmain.cpp +184 -42
- data/ext/cplusplus.cpp +202 -202
- data/ext/ed.cpp +242 -81
- data/ext/ed.h +39 -22
- data/ext/em.cpp +127 -108
- data/ext/em.h +27 -18
- data/ext/emwin.cpp +3 -3
- data/ext/eventmachine.h +49 -38
- data/ext/eventmachine_cpp.h +96 -96
- data/ext/extconf.rb +147 -132
- data/ext/fastfilereader/extconf.rb +82 -76
- data/ext/project.h +151 -140
- data/ext/rubymain.cpp +222 -103
- data/ext/ssl.cpp +460 -460
- data/ext/ssl.h +94 -94
- data/java/src/com/rubyeventmachine/EmReactor.java +570 -423
- data/java/src/com/rubyeventmachine/EventableChannel.java +69 -57
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -171
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -244
- data/java/src/com/rubyeventmachine/{Application.java → application/Application.java} +194 -200
- data/java/src/com/rubyeventmachine/{Connection.java → application/Connection.java} +74 -74
- data/java/src/com/rubyeventmachine/{ConnectionFactory.java → application/ConnectionFactory.java} +36 -36
- data/java/src/com/rubyeventmachine/{DefaultConnectionFactory.java → application/DefaultConnectionFactory.java} +46 -46
- data/java/src/com/rubyeventmachine/{PeriodicTimer.java → application/PeriodicTimer.java} +38 -38
- data/java/src/com/rubyeventmachine/{Timer.java → application/Timer.java} +54 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -108
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -146
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -74
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -89
- data/lib/em/connection.rb +71 -12
- data/lib/em/deferrable.rb +191 -186
- data/lib/em/protocols.rb +36 -35
- data/lib/em/protocols/httpclient2.rb +590 -582
- data/lib/em/protocols/line_and_text.rb +125 -126
- data/lib/em/protocols/linetext2.rb +161 -160
- data/lib/em/protocols/object_protocol.rb +45 -39
- data/lib/em/protocols/smtpclient.rb +357 -331
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/queue.rb +60 -60
- data/lib/em/timers.rb +56 -55
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +125 -169
- data/lib/jeventmachine.rb +257 -142
- data/tasks/{cpp.rake → cpp.rake_example} +76 -76
- data/tests/test_attach.rb +125 -100
- data/tests/test_basic.rb +1 -2
- data/tests/test_connection_count.rb +34 -44
- data/tests/test_epoll.rb +0 -2
- data/tests/test_get_sock_opt.rb +30 -0
- data/tests/test_httpclient2.rb +3 -3
- data/tests/test_inactivity_timeout.rb +21 -1
- data/tests/test_ltp.rb +182 -188
- data/tests/test_next_tick.rb +0 -2
- data/tests/test_pause.rb +70 -0
- data/tests/test_pending_connect_timeout.rb +48 -0
- data/tests/test_ssl_args.rb +78 -67
- data/tests/test_timers.rb +162 -141
- metadata +13 -11
- data/tasks/project.rake +0 -79
- 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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
public void
|
39
|
-
|
40
|
-
public void
|
41
|
-
|
42
|
-
public
|
43
|
-
|
44
|
-
public
|
45
|
-
|
46
|
-
public
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
public void
|
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
|
-
|
54
|
-
Selector selector;
|
55
|
-
boolean bCloseScheduled;
|
56
|
-
LinkedList<Packet> outboundQ;
|
57
|
-
SocketAddress returnAddress;
|
58
|
-
|
59
|
-
|
60
|
-
public EventableDatagramChannel (DatagramChannel dc,
|
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
|
93
|
-
System.out.println ("NOT SCHEDULING CLOSE ON DATAGRAM");
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
//
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
*
|
146
|
-
*
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
//
|
169
|
-
|
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
|
+
}
|