eventmachine-eventmachine 0.12.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +169 -0
- data/docs/COPYING +60 -0
- data/docs/ChangeLog +183 -0
- data/docs/DEFERRABLES +138 -0
- data/docs/EPOLL +141 -0
- data/docs/GNU +281 -0
- data/docs/INSTALL +15 -0
- data/docs/KEYBOARD +38 -0
- data/docs/LEGAL +25 -0
- data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
- data/docs/PURE_RUBY +77 -0
- data/docs/README +74 -0
- data/docs/RELEASE_NOTES +96 -0
- data/docs/SMTP +9 -0
- data/docs/SPAWNED_PROCESSES +93 -0
- data/docs/TODO +10 -0
- data/ext/binder.cpp +126 -0
- data/ext/binder.h +48 -0
- data/ext/cmain.cpp +530 -0
- data/ext/cplusplus.cpp +172 -0
- data/ext/ed.cpp +1473 -0
- data/ext/ed.h +361 -0
- data/ext/em.cpp +1895 -0
- data/ext/em.h +170 -0
- data/ext/emwin.cpp +300 -0
- data/ext/emwin.h +94 -0
- data/ext/epoll.cpp +26 -0
- data/ext/epoll.h +25 -0
- data/ext/eventmachine.h +90 -0
- data/ext/eventmachine_cpp.h +94 -0
- data/ext/extconf.rb +150 -0
- data/ext/files.cpp +94 -0
- data/ext/files.h +65 -0
- data/ext/kb.cpp +368 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +327 -0
- data/ext/project.h +119 -0
- data/ext/rubymain.cpp +683 -0
- data/ext/sigs.cpp +89 -0
- data/ext/sigs.h +32 -0
- data/ext/ssl.cpp +408 -0
- data/ext/ssl.h +86 -0
- data/java/src/com/rubyeventmachine/Application.java +196 -0
- data/java/src/com/rubyeventmachine/Connection.java +74 -0
- data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
- data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
- data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
- data/java/src/com/rubyeventmachine/Timer.java +54 -0
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
- data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
- data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
- data/lib/em/deferrable.rb +208 -0
- data/lib/em/eventable.rb +39 -0
- data/lib/em/future.rb +62 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/processes.rb +68 -0
- data/lib/em/spawnable.rb +88 -0
- data/lib/em/streamer.rb +112 -0
- data/lib/eventmachine.rb +1763 -0
- data/lib/eventmachine_version.rb +31 -0
- data/lib/evma.rb +32 -0
- data/lib/evma/callback.rb +32 -0
- data/lib/evma/container.rb +75 -0
- data/lib/evma/factory.rb +77 -0
- data/lib/evma/protocol.rb +87 -0
- data/lib/evma/reactor.rb +48 -0
- data/lib/jeventmachine.rb +137 -0
- data/lib/pr_eventmachine.rb +1011 -0
- data/lib/protocols/buftok.rb +127 -0
- data/lib/protocols/header_and_content.rb +129 -0
- data/lib/protocols/httpcli2.rb +794 -0
- data/lib/protocols/httpclient.rb +270 -0
- data/lib/protocols/line_and_text.rb +122 -0
- data/lib/protocols/linetext2.rb +163 -0
- data/lib/protocols/postgres.rb +261 -0
- data/lib/protocols/saslauth.rb +179 -0
- data/lib/protocols/smtpclient.rb +308 -0
- data/lib/protocols/smtpserver.rb +556 -0
- data/lib/protocols/stomp.rb +130 -0
- data/lib/protocols/tcptest.rb +57 -0
- data/tasks/cpp.rake +77 -0
- data/tasks/project.rake +78 -0
- data/tasks/tests.rake +192 -0
- data/tests/test_attach.rb +66 -0
- data/tests/test_basic.rb +231 -0
- data/tests/test_defer.rb +47 -0
- data/tests/test_epoll.rb +161 -0
- data/tests/test_errors.rb +82 -0
- data/tests/test_eventables.rb +78 -0
- data/tests/test_exc.rb +58 -0
- data/tests/test_futures.rb +214 -0
- data/tests/test_hc.rb +218 -0
- data/tests/test_httpclient.rb +215 -0
- data/tests/test_httpclient2.rb +133 -0
- data/tests/test_kb.rb +61 -0
- data/tests/test_ltp.rb +192 -0
- data/tests/test_ltp2.rb +320 -0
- data/tests/test_next_tick.rb +102 -0
- data/tests/test_processes.rb +56 -0
- data/tests/test_pure.rb +129 -0
- data/tests/test_running.rb +47 -0
- data/tests/test_sasl.rb +74 -0
- data/tests/test_send_file.rb +245 -0
- data/tests/test_servers.rb +80 -0
- data/tests/test_smtpclient.rb +81 -0
- data/tests/test_smtpserver.rb +93 -0
- data/tests/test_spawn.rb +329 -0
- data/tests/test_ssl_args.rb +68 -0
- data/tests/test_timers.rb +146 -0
- data/tests/test_ud.rb +43 -0
- data/tests/testem.rb +31 -0
- metadata +197 -0
@@ -0,0 +1,38 @@
|
|
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
|
+
public class PeriodicTimer extends Timer {
|
33
|
+
|
34
|
+
public void _fire() {
|
35
|
+
fire();
|
36
|
+
application.addTimer(interval, this);
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,54 @@
|
|
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
|
+
public class Timer {
|
33
|
+
/**
|
34
|
+
* User code is expected to call a method on a controlling Application,
|
35
|
+
* which will fill in this field so subsequent user code can access it.
|
36
|
+
*/
|
37
|
+
public Application application;
|
38
|
+
public double interval;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* The reactor calls here, and it may be overridden in subclasses.
|
42
|
+
* User code should never call this method.
|
43
|
+
*/
|
44
|
+
public void _fire() {
|
45
|
+
fire();
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* User code is expected to override this method.
|
50
|
+
*/
|
51
|
+
public void fire() {
|
52
|
+
}
|
53
|
+
|
54
|
+
}
|
@@ -0,0 +1,108 @@
|
|
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
|
+
|
31
|
+
package com.rubyeventmachine.tests;
|
32
|
+
|
33
|
+
|
34
|
+
import org.junit.After;
|
35
|
+
import org.junit.AfterClass;
|
36
|
+
import org.junit.Before;
|
37
|
+
import org.junit.BeforeClass;
|
38
|
+
import org.junit.Test;
|
39
|
+
import org.junit.Assert;
|
40
|
+
import java.net.*;
|
41
|
+
import java.io.*;
|
42
|
+
import java.nio.*;
|
43
|
+
|
44
|
+
import com.rubyeventmachine.*;
|
45
|
+
|
46
|
+
public class ApplicationTest {
|
47
|
+
|
48
|
+
@BeforeClass
|
49
|
+
public static void setUpBeforeClass() throws Exception {
|
50
|
+
}
|
51
|
+
|
52
|
+
@AfterClass
|
53
|
+
public static void tearDownAfterClass() throws Exception {
|
54
|
+
}
|
55
|
+
|
56
|
+
@Before
|
57
|
+
public void setUp() throws Exception {
|
58
|
+
}
|
59
|
+
|
60
|
+
@After
|
61
|
+
public void tearDown() throws Exception {
|
62
|
+
}
|
63
|
+
|
64
|
+
@Test
|
65
|
+
public void testRunnableArgument() {
|
66
|
+
final Application a = new Application();
|
67
|
+
a.run (new Runnable() {
|
68
|
+
public void run() {
|
69
|
+
a.stop();
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
class F implements ConnectionFactory {
|
77
|
+
public Connection connection() {
|
78
|
+
return new Connection() {
|
79
|
+
public void receiveData (ByteBuffer bb) {
|
80
|
+
application.stop();
|
81
|
+
}
|
82
|
+
};
|
83
|
+
}
|
84
|
+
|
85
|
+
};
|
86
|
+
|
87
|
+
@Test
|
88
|
+
public void testTcpServer() throws EmReactorException {
|
89
|
+
final Application a = new Application();
|
90
|
+
final SocketAddress saddr = new InetSocketAddress ("127.0.0.1", 9008);
|
91
|
+
a.run (new Runnable() {
|
92
|
+
public void run() {
|
93
|
+
try {
|
94
|
+
a.startServer (saddr, new F());
|
95
|
+
} catch (EmReactorException e) { Assert.fail(); }
|
96
|
+
new Thread() {
|
97
|
+
public void run() {
|
98
|
+
try {
|
99
|
+
Socket s = new Socket ("127.0.0.1", 9008);
|
100
|
+
s.getOutputStream().write(new String ("boo").getBytes());
|
101
|
+
} catch (UnknownHostException e) {
|
102
|
+
} catch (IOException e) {}
|
103
|
+
}
|
104
|
+
}.start();
|
105
|
+
}
|
106
|
+
});
|
107
|
+
}
|
108
|
+
}
|
@@ -0,0 +1,124 @@
|
|
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.tests;
|
31
|
+
|
32
|
+
|
33
|
+
import org.junit.After;
|
34
|
+
import org.junit.AfterClass;
|
35
|
+
import org.junit.Before;
|
36
|
+
import org.junit.BeforeClass;
|
37
|
+
import org.junit.Test;
|
38
|
+
import java.io.*;
|
39
|
+
import java.nio.*;
|
40
|
+
import java.nio.channels.*;
|
41
|
+
|
42
|
+
import com.rubyeventmachine.*;
|
43
|
+
|
44
|
+
public class ConnectTest {
|
45
|
+
|
46
|
+
@BeforeClass
|
47
|
+
public static void setUpBeforeClass() throws Exception {
|
48
|
+
}
|
49
|
+
|
50
|
+
@AfterClass
|
51
|
+
public static void tearDownAfterClass() throws Exception {
|
52
|
+
}
|
53
|
+
|
54
|
+
@Before
|
55
|
+
public void setUp() throws Exception {
|
56
|
+
}
|
57
|
+
|
58
|
+
@After
|
59
|
+
public void tearDown() throws Exception {
|
60
|
+
}
|
61
|
+
|
62
|
+
@Test
|
63
|
+
public final void test1() throws IOException, ClosedChannelException {
|
64
|
+
Application a = new Application();
|
65
|
+
a.addTimer(0, new Timer() {
|
66
|
+
public void fire() {
|
67
|
+
application.connect("www.bayshorenetworks.com", 80, new Connection() {
|
68
|
+
public void connectionCompleted() {
|
69
|
+
close();
|
70
|
+
}
|
71
|
+
public void unbind() {
|
72
|
+
application.stop();
|
73
|
+
}
|
74
|
+
});
|
75
|
+
}
|
76
|
+
});
|
77
|
+
a.run();
|
78
|
+
}
|
79
|
+
|
80
|
+
@Test
|
81
|
+
public final void test2() throws IOException {
|
82
|
+
class Bays extends Connection {
|
83
|
+
public void connectionCompleted() {
|
84
|
+
sendData (ByteBuffer.wrap( new String ("GET / HTTP/1.1\r\nHost: _\r\n\r\n").getBytes()));
|
85
|
+
}
|
86
|
+
public void receiveData (ByteBuffer b) {
|
87
|
+
System.out.println (new String(b.array()));
|
88
|
+
application.stop();
|
89
|
+
}
|
90
|
+
};
|
91
|
+
|
92
|
+
Application a = new Application();
|
93
|
+
a.addTimer(0, new Timer() {
|
94
|
+
public void fire() {
|
95
|
+
application.connect("www.bayshorenetworks.com", 80, new Bays());
|
96
|
+
}
|
97
|
+
});
|
98
|
+
a.run();
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
class C1 extends Connection {
|
104
|
+
Application application;
|
105
|
+
public C1 (Application a) {
|
106
|
+
application = a;
|
107
|
+
}
|
108
|
+
public void postInit() {
|
109
|
+
application.stop();
|
110
|
+
}
|
111
|
+
}
|
112
|
+
@Test
|
113
|
+
public final void test3() {
|
114
|
+
final Application a = new Application();
|
115
|
+
a.run (new Runnable() {
|
116
|
+
public void run() {
|
117
|
+
a.connect("www.bayshorenetworks.com", 80, new C1(a));
|
118
|
+
}
|
119
|
+
});
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
}
|
@@ -0,0 +1,80 @@
|
|
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.tests;
|
31
|
+
|
32
|
+
//import static org.junit.Assert.*;
|
33
|
+
|
34
|
+
import org.junit.After;
|
35
|
+
import org.junit.AfterClass;
|
36
|
+
import org.junit.Before;
|
37
|
+
import org.junit.BeforeClass;
|
38
|
+
import org.junit.Test;
|
39
|
+
|
40
|
+
import com.rubyeventmachine.EmReactor;
|
41
|
+
|
42
|
+
import java.io.*;
|
43
|
+
import java.nio.*;
|
44
|
+
|
45
|
+
|
46
|
+
public class EMTest {
|
47
|
+
|
48
|
+
class ShortTimer extends EmReactor {
|
49
|
+
public void eventCallback (String sig, int eventCode, ByteBuffer data) {
|
50
|
+
System.out.println ("Short Callback "+sig+" "+eventCode+" "+data);
|
51
|
+
this.stop();
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
@BeforeClass
|
56
|
+
public static void setUpBeforeClass() throws Exception {
|
57
|
+
}
|
58
|
+
|
59
|
+
@AfterClass
|
60
|
+
public static void tearDownAfterClass() throws Exception {
|
61
|
+
}
|
62
|
+
|
63
|
+
@Before
|
64
|
+
public void setUp() throws Exception {
|
65
|
+
}
|
66
|
+
|
67
|
+
@After
|
68
|
+
public void tearDown() throws Exception {
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
@Test
|
73
|
+
public final void testOneShort() throws IOException {
|
74
|
+
EmReactor em = new ShortTimer();
|
75
|
+
em.installOneshotTimer(1050);
|
76
|
+
em.run();
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
package com.rubyeventmachine.tests;
|
2
|
+
|
3
|
+
import com.rubyeventmachine.*;
|
4
|
+
import java.net.*;
|
5
|
+
import java.nio.*;
|
6
|
+
|
7
|
+
import org.junit.After;
|
8
|
+
import org.junit.AfterClass;
|
9
|
+
import org.junit.Before;
|
10
|
+
import org.junit.BeforeClass;
|
11
|
+
import org.junit.Test;
|
12
|
+
|
13
|
+
|
14
|
+
public class TestDatagrams {
|
15
|
+
|
16
|
+
@BeforeClass
|
17
|
+
public static void setUpBeforeClass() throws Exception {
|
18
|
+
}
|
19
|
+
|
20
|
+
@AfterClass
|
21
|
+
public static void tearDownAfterClass() throws Exception {
|
22
|
+
}
|
23
|
+
|
24
|
+
@Before
|
25
|
+
public void setUp() throws Exception {
|
26
|
+
}
|
27
|
+
|
28
|
+
@After
|
29
|
+
public void tearDown() throws Exception {
|
30
|
+
}
|
31
|
+
|
32
|
+
class A extends Connection {
|
33
|
+
public void receiveData (ByteBuffer bb) {
|
34
|
+
application.stop();
|
35
|
+
}
|
36
|
+
}
|
37
|
+
class B extends Connection {
|
38
|
+
public void postInit() {
|
39
|
+
this.sendDatagram(ByteBuffer.wrap(new String("ABC").getBytes()), new InetSocketAddress ("127.0.0.1", 9550));
|
40
|
+
}
|
41
|
+
|
42
|
+
}
|
43
|
+
@Test
|
44
|
+
public final void testA() {
|
45
|
+
final Application a = new Application();
|
46
|
+
a.run (new Runnable() {
|
47
|
+
public void run() {
|
48
|
+
a.openDatagramSocket( new InetSocketAddress ("0.0.0.0", 9550), new A() );
|
49
|
+
a.openDatagramSocket( new B() );
|
50
|
+
}
|
51
|
+
});
|
52
|
+
}
|
53
|
+
}
|