eventmachine-maglev- 0.12.10 → 1.0.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.yardopts +7 -0
- data/Gemfile +3 -0
- data/README.md +109 -0
- data/Rakefile +14 -368
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +521 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/{KEYBOARD → old/KEYBOARD} +15 -11
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/eventmachine.gemspec +20 -26
- data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
- data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
- data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
- data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
- data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
- data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
- data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
- data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
- data/examples/{ex_channel.rb → old/ex_channel.rb} +3 -3
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +40 -29
- data/ext/ed.cpp +189 -134
- data/ext/ed.h +34 -40
- data/ext/em.cpp +388 -340
- data/ext/em.h +29 -32
- data/ext/eventmachine.h +7 -6
- data/ext/extconf.rb +57 -48
- data/ext/fastfilereader/extconf.rb +5 -3
- data/ext/fastfilereader/mapper.cpp +1 -1
- data/ext/fastfilereader/rubymain.cpp +0 -1
- data/ext/kb.cpp +1 -3
- data/ext/pipe.cpp +9 -11
- data/ext/project.h +12 -8
- data/ext/rubymain.cpp +158 -112
- data/java/src/com/rubyeventmachine/EmReactor.java +3 -2
- data/lib/em/buftok.rb +35 -63
- data/lib/em/callback.rb +43 -11
- data/lib/em/channel.rb +22 -15
- data/lib/em/completion.rb +303 -0
- data/lib/em/connection.rb +341 -208
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/deferrable.rb +20 -2
- data/lib/em/file_watch.rb +37 -18
- data/lib/em/iterator.rb +270 -0
- data/lib/em/pool.rb +146 -0
- data/lib/em/process_watch.rb +5 -4
- data/lib/em/processes.rb +8 -4
- data/lib/em/protocols/httpclient.rb +27 -11
- data/lib/em/protocols/httpclient2.rb +15 -5
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/memcache.rb +17 -9
- data/lib/em/protocols/object_protocol.rb +2 -1
- data/lib/em/protocols/postgres3.rb +2 -1
- data/lib/em/protocols/smtpclient.rb +19 -11
- data/lib/em/protocols/smtpserver.rb +101 -8
- data/lib/em/protocols/stomp.rb +9 -7
- data/lib/em/protocols/tcptest.rb +3 -2
- data/lib/em/protocols.rb +1 -1
- data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +188 -205
- data/lib/em/queue.rb +23 -13
- data/lib/em/resolver.rb +192 -0
- data/lib/em/spawnable.rb +9 -10
- data/lib/em/streamer.rb +34 -46
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +8 -3
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +582 -686
- data/lib/jeventmachine.rb +25 -3
- data/tasks/package.rake +98 -0
- data/tasks/test.rake +8 -0
- data/tests/em_test_helper.rb +64 -0
- data/tests/test_attach.rb +56 -56
- data/tests/test_basic.rb +111 -168
- data/tests/test_channel.rb +5 -6
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +1 -3
- data/tests/test_defer.rb +3 -32
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +27 -57
- data/tests/test_error_handler.rb +10 -7
- data/tests/test_exc.rb +6 -33
- data/tests/test_file_watch.rb +51 -35
- data/tests/test_futures.rb +10 -38
- data/tests/test_get_sock_opt.rb +27 -20
- data/tests/test_handler_check.rb +1 -3
- data/tests/test_hc.rb +49 -112
- data/tests/test_httpclient.rb +34 -62
- data/tests/test_httpclient2.rb +14 -39
- data/tests/test_inactivity_timeout.rb +44 -40
- data/tests/test_kb.rb +26 -52
- data/tests/test_ltp.rb +27 -71
- data/tests/test_ltp2.rb +1 -30
- data/tests/test_next_tick.rb +2 -31
- data/tests/test_object_protocol.rb +8 -9
- data/tests/test_pause.rb +45 -37
- data/tests/test_pending_connect_timeout.rb +42 -38
- data/tests/test_pool.rb +128 -0
- data/tests/test_process_watch.rb +37 -37
- data/tests/test_processes.rb +92 -110
- data/tests/test_proxy_connection.rb +137 -61
- data/tests/test_pure.rb +30 -67
- data/tests/test_queue.rb +10 -4
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +1 -29
- data/tests/test_sasl.rb +8 -33
- data/tests/test_send_file.rb +163 -188
- data/tests/test_servers.rb +12 -55
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +1 -29
- data/tests/test_smtpserver.rb +1 -29
- data/tests/test_spawn.rb +2 -31
- data/tests/test_ssl_args.rb +9 -10
- data/tests/test_ssl_methods.rb +1 -3
- data/tests/test_ssl_verify.rb +63 -63
- data/tests/test_threaded_resource.rb +53 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +52 -91
- data/tests/test_ud.rb +1 -29
- data/tests/test_unbind_reason.rb +31 -0
- metadata +113 -70
- data/README +0 -82
- data/docs/DEFERRABLES +0 -133
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
- data/docs/SMTP +0 -2
- data/docs/SPAWNED_PROCESSES +0 -89
- data/ext/cplusplus.cpp +0 -202
- data/ext/emwin.cpp +0 -300
- data/ext/emwin.h +0 -94
- data/ext/epoll.cpp +0 -26
- data/ext/epoll.h +0 -25
- data/ext/eventmachine_cpp.h +0 -96
- data/ext/files.cpp +0 -94
- data/ext/files.h +0 -65
- data/ext/sigs.cpp +0 -89
- data/ext/sigs.h +0 -32
- data/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/evma/callback.rb +0 -32
- data/lib/evma/container.rb +0 -75
- data/lib/evma/factory.rb +0 -77
- data/lib/evma/protocol.rb +0 -87
- data/lib/evma/reactor.rb +0 -48
- data/lib/evma.rb +0 -32
- data/setup.rb +0 -1585
- data/tests/test_errors.rb +0 -82
- data/tests/testem.rb +0 -31
- data/web/whatis +0 -7
- /data/{docs/GNU → GNU} +0 -0
- /data/{docs/COPYING → LICENSE} +0 -0
- /data/docs/{ChangeLog → old/ChangeLog} +0 -0
- /data/docs/{EPOLL → old/EPOLL} +0 -0
- /data/docs/{INSTALL → old/INSTALL} +0 -0
- /data/docs/{LEGAL → old/LEGAL} +0 -0
- /data/docs/{PURE_RUBY → old/PURE_RUBY} +0 -0
- /data/docs/{RELEASE_NOTES → old/RELEASE_NOTES} +0 -0
- /data/docs/{TODO → old/TODO} +0 -0
- /data/examples/{ex_queue.rb → old/ex_queue.rb} +0 -0
- /data/examples/{helper.rb → old/helper.rb} +0 -0
@@ -1,46 +0,0 @@
|
|
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.application;
|
32
|
-
|
33
|
-
import com.rubyeventmachine.application.ConnectionFactory;
|
34
|
-
|
35
|
-
public class DefaultConnectionFactory implements ConnectionFactory {
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Convenience class. Its connection() method returns an instance of class
|
39
|
-
* Connection, which is usually overridden. This class is probably most
|
40
|
-
* useful for unit testing.
|
41
|
-
*/
|
42
|
-
public Connection connection() {
|
43
|
-
return new Connection();
|
44
|
-
}
|
45
|
-
|
46
|
-
}
|
@@ -1,38 +0,0 @@
|
|
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.application;
|
31
|
-
|
32
|
-
public class PeriodicTimer extends Timer {
|
33
|
-
|
34
|
-
public void _fire() {
|
35
|
-
fire();
|
36
|
-
application.addTimer(interval, this);
|
37
|
-
}
|
38
|
-
}
|
@@ -1,54 +0,0 @@
|
|
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.application;
|
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
|
-
}
|
@@ -1,109 +0,0 @@
|
|
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
|
-
import com.rubyeventmachine.application.*;
|
46
|
-
|
47
|
-
public class ApplicationTest {
|
48
|
-
|
49
|
-
@BeforeClass
|
50
|
-
public static void setUpBeforeClass() throws Exception {
|
51
|
-
}
|
52
|
-
|
53
|
-
@AfterClass
|
54
|
-
public static void tearDownAfterClass() throws Exception {
|
55
|
-
}
|
56
|
-
|
57
|
-
@Before
|
58
|
-
public void setUp() throws Exception {
|
59
|
-
}
|
60
|
-
|
61
|
-
@After
|
62
|
-
public void tearDown() throws Exception {
|
63
|
-
}
|
64
|
-
|
65
|
-
@Test
|
66
|
-
public void testRunnableArgument() {
|
67
|
-
final Application a = new Application();
|
68
|
-
a.run (new Runnable() {
|
69
|
-
public void run() {
|
70
|
-
a.stop();
|
71
|
-
}
|
72
|
-
});
|
73
|
-
}
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
class F implements ConnectionFactory {
|
78
|
-
public Connection connection() {
|
79
|
-
return new Connection() {
|
80
|
-
public void receiveData (ByteBuffer bb) {
|
81
|
-
application.stop();
|
82
|
-
}
|
83
|
-
};
|
84
|
-
}
|
85
|
-
|
86
|
-
};
|
87
|
-
|
88
|
-
@Test
|
89
|
-
public void testTcpServer() throws EmReactorException {
|
90
|
-
final Application a = new Application();
|
91
|
-
final SocketAddress saddr = new InetSocketAddress ("127.0.0.1", 9008);
|
92
|
-
a.run (new Runnable() {
|
93
|
-
public void run() {
|
94
|
-
try {
|
95
|
-
a.startServer (saddr, new F());
|
96
|
-
} catch (EmReactorException e) { Assert.fail(); }
|
97
|
-
new Thread() {
|
98
|
-
public void run() {
|
99
|
-
try {
|
100
|
-
Socket s = new Socket ("127.0.0.1", 9008);
|
101
|
-
s.getOutputStream().write(new String ("boo").getBytes());
|
102
|
-
} catch (UnknownHostException e) {
|
103
|
-
} catch (IOException e) {}
|
104
|
-
}
|
105
|
-
}.start();
|
106
|
-
}
|
107
|
-
});
|
108
|
-
}
|
109
|
-
}
|
@@ -1,148 +0,0 @@
|
|
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.net.*;
|
39
|
-
import java.io.*;
|
40
|
-
import java.nio.*;
|
41
|
-
import java.nio.channels.*;
|
42
|
-
|
43
|
-
import com.rubyeventmachine.*;
|
44
|
-
import com.rubyeventmachine.application.*;
|
45
|
-
|
46
|
-
public class ConnectTest {
|
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 final void test1() throws IOException, ClosedChannelException {
|
66
|
-
Application a = new Application();
|
67
|
-
a.addTimer(0, new Timer() {
|
68
|
-
public void fire() {
|
69
|
-
application.connect("www.bayshorenetworks.com", 80, new Connection() {
|
70
|
-
public void connectionCompleted() {
|
71
|
-
close();
|
72
|
-
}
|
73
|
-
public void unbind() {
|
74
|
-
application.stop();
|
75
|
-
}
|
76
|
-
});
|
77
|
-
}
|
78
|
-
});
|
79
|
-
a.run();
|
80
|
-
}
|
81
|
-
|
82
|
-
@Test
|
83
|
-
public final void test2() throws IOException {
|
84
|
-
class Bays extends Connection {
|
85
|
-
public void connectionCompleted() {
|
86
|
-
sendData (ByteBuffer.wrap( new String ("GET / HTTP/1.1\r\nHost: _\r\n\r\n").getBytes()));
|
87
|
-
}
|
88
|
-
public void receiveData (ByteBuffer b) {
|
89
|
-
System.out.println (new String(b.array()));
|
90
|
-
application.stop();
|
91
|
-
}
|
92
|
-
};
|
93
|
-
|
94
|
-
Application a = new Application();
|
95
|
-
a.addTimer(0, new Timer() {
|
96
|
-
public void fire() {
|
97
|
-
application.connect("www.bayshorenetworks.com", 80, new Bays());
|
98
|
-
}
|
99
|
-
});
|
100
|
-
a.run();
|
101
|
-
}
|
102
|
-
|
103
|
-
public final void testBindConnect() throws IOException {
|
104
|
-
class Server extends Connection {
|
105
|
-
public void postInit() {
|
106
|
-
// TODO: get peername here and check if the port is 33333
|
107
|
-
// doesnt seem like peername is impl yet?
|
108
|
-
System.out.println("post init!");
|
109
|
-
}
|
110
|
-
};
|
111
|
-
|
112
|
-
Application a = new Application();
|
113
|
-
a.addTimer(0, new Timer() {
|
114
|
-
public void fire() {
|
115
|
-
application.startServer(new InetSocketAddress("localhost", 20000), new DefaultConnectionFactory());
|
116
|
-
}
|
117
|
-
});
|
118
|
-
a.addTimer(500, new Timer() {
|
119
|
-
public void fire() {
|
120
|
-
application.bindConnect("localhost", 33333, "localhost", 20000, new Connection());
|
121
|
-
}
|
122
|
-
});
|
123
|
-
|
124
|
-
a.run();
|
125
|
-
}
|
126
|
-
|
127
|
-
class C1 extends Connection {
|
128
|
-
Application application;
|
129
|
-
public C1 (Application a) {
|
130
|
-
application = a;
|
131
|
-
}
|
132
|
-
public void postInit() {
|
133
|
-
application.stop();
|
134
|
-
}
|
135
|
-
}
|
136
|
-
@Test
|
137
|
-
public final void test3() {
|
138
|
-
final Application a = new Application();
|
139
|
-
a.run (new Runnable() {
|
140
|
-
public void run() {
|
141
|
-
a.connect("www.bayshorenetworks.com", 80, new C1(a));
|
142
|
-
}
|
143
|
-
});
|
144
|
-
}
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
}
|
@@ -1,80 +0,0 @@
|
|
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
|
-
}
|
@@ -1,53 +0,0 @@
|
|
1
|
-
package com.rubyeventmachine.tests;
|
2
|
-
|
3
|
-
import com.rubyeventmachine.application.*;
|
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
|
-
}
|
@@ -1,75 +0,0 @@
|
|
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 com.rubyeventmachine.*;
|
34
|
-
import com.rubyeventmachine.application.*;
|
35
|
-
import java.net.*;
|
36
|
-
import org.junit.After;
|
37
|
-
import org.junit.AfterClass;
|
38
|
-
import org.junit.Before;
|
39
|
-
import org.junit.BeforeClass;
|
40
|
-
import org.junit.Test;
|
41
|
-
import org.junit.Assert;
|
42
|
-
|
43
|
-
public class TestServers {
|
44
|
-
|
45
|
-
@BeforeClass
|
46
|
-
public static void setUpBeforeClass() throws Exception {
|
47
|
-
}
|
48
|
-
|
49
|
-
@AfterClass
|
50
|
-
public static void tearDownAfterClass() throws Exception {
|
51
|
-
}
|
52
|
-
|
53
|
-
@Before
|
54
|
-
public void setUp() throws Exception {
|
55
|
-
}
|
56
|
-
|
57
|
-
@After
|
58
|
-
public void tearDown() throws Exception {
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
@Test
|
63
|
-
public void testBadServerAddress() {
|
64
|
-
final Application a = new Application();
|
65
|
-
a.run (new Runnable() {
|
66
|
-
public void run() {
|
67
|
-
try {
|
68
|
-
a.startServer(new InetSocketAddress ("100.100.100.100", 100), new DefaultConnectionFactory());
|
69
|
-
Assert.fail ("was supposed to throw a reactor exception");
|
70
|
-
} catch (EmReactorException e) {}
|
71
|
-
a.stop();
|
72
|
-
}
|
73
|
-
});
|
74
|
-
}
|
75
|
-
}
|
@@ -1,90 +0,0 @@
|
|
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 com.rubyeventmachine.*;
|
33
|
-
import com.rubyeventmachine.application.*;
|
34
|
-
import java.io.*;
|
35
|
-
|
36
|
-
import org.junit.Assert;
|
37
|
-
import org.junit.After;
|
38
|
-
import org.junit.AfterClass;
|
39
|
-
import org.junit.Before;
|
40
|
-
import org.junit.BeforeClass;
|
41
|
-
import org.junit.Test;
|
42
|
-
|
43
|
-
|
44
|
-
public class TestTimers {
|
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
|
-
|
63
|
-
|
64
|
-
@Test
|
65
|
-
public final void test2() throws IOException {
|
66
|
-
Application a = new Application();
|
67
|
-
a.addTimer(0, new Timer() {
|
68
|
-
public void fire() {
|
69
|
-
application.stop();
|
70
|
-
}
|
71
|
-
});
|
72
|
-
a.run();
|
73
|
-
Assert.assertEquals (1, 1); // just to make sure the reactor halts.
|
74
|
-
}
|
75
|
-
|
76
|
-
@Test
|
77
|
-
public final void test3() throws IOException {
|
78
|
-
Application a = new Application();
|
79
|
-
a.addTimer (0.1, new PeriodicTimer() {
|
80
|
-
int n = 0;
|
81
|
-
public void fire() {
|
82
|
-
n++;
|
83
|
-
if (n == 5)
|
84
|
-
application.stop();
|
85
|
-
}
|
86
|
-
});
|
87
|
-
a.run();
|
88
|
-
Assert.assertEquals(1, 1);
|
89
|
-
}
|
90
|
-
}
|