eventmachine 0.12.2 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +191 -0
- data/{COPYING → docs/COPYING} +0 -0
- data/docs/ChangeLog +183 -0
- data/{DEFERRABLES → docs/DEFERRABLES} +1 -1
- data/{EPOLL → docs/EPOLL} +0 -0
- data/{GNU → docs/GNU} +0 -0
- data/docs/INSTALL +15 -0
- data/{KEYBOARD → docs/KEYBOARD} +0 -0
- data/{LEGAL → docs/LEGAL} +0 -0
- data/{LIGHTWEIGHT_CONCURRENCY → docs/LIGHTWEIGHT_CONCURRENCY} +1 -1
- data/{PURE_RUBY → docs/PURE_RUBY} +1 -1
- data/{README → docs/README} +1 -1
- data/{RELEASE_NOTES → docs/RELEASE_NOTES} +1 -1
- data/{SMTP → docs/SMTP} +1 -1
- data/{SPAWNED_PROCESSES → docs/SPAWNED_PROCESSES} +1 -1
- data/{TODO → docs/TODO} +1 -1
- data/ext/binder.cpp +1 -1
- data/ext/binder.h +1 -1
- data/ext/cmain.cpp +65 -74
- data/ext/cplusplus.cpp +1 -1
- data/ext/ed.cpp +41 -25
- data/ext/ed.h +10 -3
- data/ext/em.cpp +39 -12
- data/ext/em.h +13 -1
- data/ext/emwin.cpp +1 -1
- data/ext/emwin.h +1 -1
- data/ext/epoll.cpp +1 -1
- data/ext/epoll.h +1 -1
- data/ext/eventmachine.h +1 -1
- data/ext/eventmachine_cpp.h +1 -1
- data/ext/extconf.rb +86 -139
- data/ext/fastfilereader/extconf.rb +161 -0
- data/ext/fastfilereader/mapper.cpp +202 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/files.cpp +1 -1
- data/ext/files.h +1 -1
- data/ext/kb.cpp +1 -1
- data/ext/page.cpp +1 -1
- data/ext/page.h +1 -1
- data/ext/pipe.cpp +14 -7
- data/ext/project.h +1 -1
- data/ext/rubymain.cpp +56 -2
- data/ext/sigs.cpp +1 -1
- data/ext/sigs.h +1 -1
- data/ext/ssl.cpp +1 -1
- data/ext/ssl.h +1 -1
- 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 +1 -1
- data/lib/em/eventable.rb +1 -1
- data/lib/em/future.rb +1 -1
- data/lib/em/messages.rb +1 -1
- data/lib/em/processes.rb +1 -1
- data/lib/em/spawnable.rb +1 -1
- data/lib/em/streamer.rb +1 -1
- data/lib/eventmachine.rb +138 -116
- data/lib/eventmachine_version.rb +2 -2
- data/lib/evma.rb +1 -1
- data/lib/evma/callback.rb +1 -1
- data/lib/evma/container.rb +1 -1
- data/lib/evma/factory.rb +1 -1
- data/lib/evma/protocol.rb +1 -1
- data/lib/evma/reactor.rb +1 -1
- data/lib/jeventmachine.rb +7 -2
- data/lib/pr_eventmachine.rb +2 -2
- data/lib/protocols/buftok.rb +1 -1
- data/lib/protocols/header_and_content.rb +1 -1
- data/lib/protocols/httpcli2.rb +16 -6
- data/lib/protocols/httpclient.rb +7 -1
- data/lib/protocols/line_and_text.rb +6 -2
- data/lib/protocols/linetext2.rb +12 -14
- data/lib/protocols/postgres.rb +1 -1
- data/lib/protocols/saslauth.rb +1 -1
- data/lib/protocols/smtpclient.rb +1 -1
- data/lib/protocols/smtpserver.rb +36 -23
- data/lib/protocols/stomp.rb +24 -1
- data/lib/protocols/tcptest.rb +1 -1
- data/tasks/cpp.rake +77 -0
- data/tasks/project.rake +78 -0
- data/tasks/tests.rake +192 -0
- data/tests/test_attach.rb +1 -1
- data/tests/test_basic.rb +65 -12
- data/tests/test_defer.rb +13 -29
- data/tests/test_epoll.rb +16 -21
- data/tests/test_errors.rb +1 -1
- data/tests/test_eventables.rb +4 -5
- data/tests/test_exc.rb +1 -1
- data/tests/test_futures.rb +1 -1
- data/tests/test_hc.rb +185 -236
- data/tests/test_httpclient.rb +1 -1
- data/tests/test_httpclient2.rb +28 -6
- data/tests/test_kb.rb +2 -2
- data/tests/test_ltp.rb +139 -141
- data/tests/test_ltp2.rb +1 -1
- data/tests/test_next_tick.rb +1 -1
- data/tests/test_processes.rb +1 -1
- data/tests/test_pure.rb +3 -2
- data/tests/test_running.rb +1 -1
- data/tests/test_sasl.rb +1 -1
- data/tests/test_send_file.rb +56 -51
- data/tests/test_servers.rb +26 -36
- data/tests/test_smtpclient.rb +46 -44
- data/tests/test_smtpserver.rb +1 -1
- data/tests/test_spawn.rb +1 -1
- data/tests/test_ssl_args.rb +68 -0
- data/tests/test_timers.rb +15 -9
- data/tests/test_ud.rb +1 -1
- data/tests/testem.rb +30 -4
- metadata +69 -34
data/ext/files.cpp
CHANGED
data/ext/files.h
CHANGED
data/ext/kb.cpp
CHANGED
data/ext/page.cpp
CHANGED
data/ext/page.h
CHANGED
data/ext/pipe.cpp
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id
|
3
|
+
$Id$
|
4
4
|
|
5
5
|
File: pipe.cpp
|
6
6
|
Date: 30May07
|
@@ -92,15 +92,22 @@ PipeDescriptor::~PipeDescriptor()
|
|
92
92
|
* within other unbind calls. (Not sure if that's even possible.)
|
93
93
|
*/
|
94
94
|
|
95
|
-
struct timespec req = {0, 10000000};
|
96
|
-
kill (SubprocessPid, SIGTERM);
|
97
|
-
nanosleep (&req, NULL);
|
98
95
|
assert (MyEventMachine);
|
96
|
+
|
97
|
+
// check if the process is already dead
|
99
98
|
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0) {
|
100
|
-
kill (SubprocessPid,
|
99
|
+
kill (SubprocessPid, SIGTERM);
|
100
|
+
// wait 0.25s for process to die
|
101
|
+
struct timespec req = {0, 250000000};
|
101
102
|
nanosleep (&req, NULL);
|
102
|
-
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0)
|
103
|
-
|
103
|
+
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0) {
|
104
|
+
kill (SubprocessPid, SIGKILL);
|
105
|
+
// wait 0.5s for process to die
|
106
|
+
struct timespec req = {0, 500000000};
|
107
|
+
nanosleep (&req, NULL);
|
108
|
+
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0)
|
109
|
+
throw std::runtime_error ("unable to reap subprocess");
|
110
|
+
}
|
104
111
|
}
|
105
112
|
}
|
106
113
|
|
data/ext/project.h
CHANGED
data/ext/rubymain.cpp
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id
|
3
|
+
$Id$
|
4
4
|
|
5
5
|
File: rubymain.cpp
|
6
6
|
Date: 06Apr06
|
@@ -463,7 +463,12 @@ t_invoke_popen
|
|
463
463
|
|
464
464
|
static VALUE t_invoke_popen (VALUE self, VALUE cmd)
|
465
465
|
{
|
466
|
-
|
466
|
+
// 1.8.7+
|
467
|
+
#ifdef RARRAY_LEN
|
468
|
+
int len = RARRAY_LEN(cmd);
|
469
|
+
#else
|
470
|
+
int len = RARRAY (cmd)->len;
|
471
|
+
#endif
|
467
472
|
if (len > 98)
|
468
473
|
rb_raise (rb_eRuntimeError, "too many arguments to popen");
|
469
474
|
char *strings [100];
|
@@ -510,6 +515,20 @@ static VALUE t__epoll (VALUE self)
|
|
510
515
|
return Qnil;
|
511
516
|
}
|
512
517
|
|
518
|
+
/**********
|
519
|
+
t__epoll_p
|
520
|
+
**********/
|
521
|
+
|
522
|
+
static VALUE t__epoll_p (VALUE self)
|
523
|
+
{
|
524
|
+
#ifdef HAVE_EPOLL
|
525
|
+
return Qtrue;
|
526
|
+
#else
|
527
|
+
return Qfalse;
|
528
|
+
#endif
|
529
|
+
}
|
530
|
+
|
531
|
+
|
513
532
|
/*********
|
514
533
|
t__kqueue
|
515
534
|
*********/
|
@@ -521,6 +540,19 @@ static VALUE t__kqueue (VALUE self)
|
|
521
540
|
return Qnil;
|
522
541
|
}
|
523
542
|
|
543
|
+
/***********
|
544
|
+
t__kqueue_p
|
545
|
+
***********/
|
546
|
+
|
547
|
+
static VALUE t__kqueue_p (VALUE self)
|
548
|
+
{
|
549
|
+
#ifdef HAVE_KQUEUE
|
550
|
+
return Qtrue;
|
551
|
+
#else
|
552
|
+
return Qfalse;
|
553
|
+
#endif
|
554
|
+
}
|
555
|
+
|
524
556
|
|
525
557
|
/****************
|
526
558
|
t_send_file_data
|
@@ -585,6 +617,23 @@ static VALUE conn_associate_callback_target (VALUE self, VALUE sig)
|
|
585
617
|
}
|
586
618
|
|
587
619
|
|
620
|
+
/***************
|
621
|
+
t_get_loop_time
|
622
|
+
****************/
|
623
|
+
|
624
|
+
static VALUE t_get_loop_time (VALUE self)
|
625
|
+
{
|
626
|
+
VALUE cTime = rb_path2class("Time");
|
627
|
+
if (gCurrentLoopTime != 0) {
|
628
|
+
return rb_funcall(cTime,
|
629
|
+
rb_intern("at"),
|
630
|
+
1,
|
631
|
+
INT2NUM(gCurrentLoopTime));
|
632
|
+
}
|
633
|
+
return Qnil;
|
634
|
+
}
|
635
|
+
|
636
|
+
|
588
637
|
/*********************
|
589
638
|
Init_rubyeventmachine
|
590
639
|
*********************/
|
@@ -634,6 +683,8 @@ extern "C" void Init_rubyeventmachine()
|
|
634
683
|
rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 3);
|
635
684
|
rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
|
636
685
|
|
686
|
+
rb_define_module_function (EmModule, "current_time", (VALUE(*)(...))t_get_loop_time, 0);
|
687
|
+
|
637
688
|
rb_define_module_function (EmModule, "open_udp_socket", (VALUE(*)(...))t_open_udp_socket, 2);
|
638
689
|
rb_define_module_function (EmModule, "read_keyboard", (VALUE(*)(...))t_read_keyboard, 0);
|
639
690
|
rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
|
@@ -661,6 +712,9 @@ extern "C" void Init_rubyeventmachine()
|
|
661
712
|
rb_define_module_function (EmModule, "epoll", (VALUE(*)(...))t__epoll, 0);
|
662
713
|
rb_define_module_function (EmModule, "kqueue", (VALUE(*)(...))t__kqueue, 0);
|
663
714
|
|
715
|
+
rb_define_module_function (EmModule, "epoll?", (VALUE(*)(...))t__epoll_p, 0);
|
716
|
+
rb_define_module_function (EmModule, "kqueue?", (VALUE(*)(...))t__kqueue_p, 0);
|
717
|
+
|
664
718
|
rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
|
665
719
|
rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);
|
666
720
|
|
data/ext/sigs.cpp
CHANGED
data/ext/sigs.h
CHANGED
data/ext/ssl.cpp
CHANGED
data/ext/ssl.h
CHANGED
@@ -0,0 +1,196 @@
|
|
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
|
+
*/
|
32
|
+
package com.rubyeventmachine;
|
33
|
+
|
34
|
+
import java.nio.ByteBuffer;
|
35
|
+
import java.nio.channels.*;
|
36
|
+
import java.util.*;
|
37
|
+
import java.io.*;
|
38
|
+
import java.net.*;
|
39
|
+
import java.net.SocketAddress;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @author francis
|
43
|
+
*
|
44
|
+
*/
|
45
|
+
public class Application {
|
46
|
+
|
47
|
+
|
48
|
+
public class Reactor extends EmReactor {
|
49
|
+
|
50
|
+
private Application application;
|
51
|
+
private TreeMap<String, Timer> timers;
|
52
|
+
private TreeMap<String, Connection> connections;
|
53
|
+
private TreeMap<String, ConnectionFactory> acceptors;
|
54
|
+
/**
|
55
|
+
*
|
56
|
+
*/
|
57
|
+
public Reactor (Application app) {
|
58
|
+
application = app;
|
59
|
+
timers = new TreeMap<String, Timer>();
|
60
|
+
connections = new TreeMap<String, Connection>();
|
61
|
+
acceptors = new TreeMap<String, ConnectionFactory>();
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
public void eventCallback (String sig, int eventType, ByteBuffer data) {
|
66
|
+
if (eventType == EM_TIMER_FIRED) {
|
67
|
+
String timersig = new String (data.array());
|
68
|
+
//System.out.println ("EVSIG "+sig + "..."+new String(data.array()));
|
69
|
+
Timer r = timers.remove(timersig);
|
70
|
+
if (r != null)
|
71
|
+
r._fire();
|
72
|
+
else
|
73
|
+
throw new RuntimeException ("unable to run unknown timer");
|
74
|
+
}
|
75
|
+
else if (eventType == EM_CONNECTION_COMPLETED) {
|
76
|
+
Connection c = connections.get(sig);
|
77
|
+
if (c != null) {
|
78
|
+
c.connectionCompleted();
|
79
|
+
}
|
80
|
+
else
|
81
|
+
throw new RuntimeException ("connection completed to unknown object");
|
82
|
+
|
83
|
+
}
|
84
|
+
else if (eventType == EM_CONNECTION_UNBOUND) {
|
85
|
+
Connection c = connections.get(sig);
|
86
|
+
if (c != null) {
|
87
|
+
c.unbind();
|
88
|
+
}
|
89
|
+
else
|
90
|
+
throw new RuntimeException ("unbind received on unknown object");
|
91
|
+
}
|
92
|
+
else if (eventType == EM_CONNECTION_ACCEPTED) {
|
93
|
+
ConnectionFactory f = acceptors.get(sig);
|
94
|
+
if (f != null) {
|
95
|
+
Connection c = f.connection();
|
96
|
+
c.signature = new String (data.array());
|
97
|
+
c.application = application;
|
98
|
+
connections.put(c.signature, c);
|
99
|
+
c.postInit();
|
100
|
+
//System.out.println (sig+"..."+new String(data.array()));
|
101
|
+
}
|
102
|
+
else
|
103
|
+
throw new RuntimeException ("received connection on unknown acceptor");
|
104
|
+
}
|
105
|
+
else if (eventType == EM_CONNECTION_READ) {
|
106
|
+
Connection c = connections.get(sig);
|
107
|
+
if (c != null) {
|
108
|
+
c.receiveData(data);
|
109
|
+
}
|
110
|
+
else throw new RuntimeException ("received data on unknown object");
|
111
|
+
}
|
112
|
+
else {
|
113
|
+
System.out.println ("unknown event type: " + eventType);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
Reactor reactor;
|
120
|
+
|
121
|
+
public Application() {
|
122
|
+
reactor = new Reactor (this);
|
123
|
+
}
|
124
|
+
public void addTimer (double seconds, Timer t) {
|
125
|
+
t.application = this;
|
126
|
+
t.interval = seconds;
|
127
|
+
String s = reactor.installOneshotTimer ((int)(seconds * 1000));
|
128
|
+
reactor.timers.put(s, t);
|
129
|
+
|
130
|
+
}
|
131
|
+
|
132
|
+
public void connect (String host, int port, Connection c) {
|
133
|
+
try {
|
134
|
+
String s = reactor.connectTcpServer(host, port);
|
135
|
+
c.application = this;
|
136
|
+
c.signature = s;
|
137
|
+
reactor.connections.put(s, c);
|
138
|
+
c.postInit();
|
139
|
+
} catch (ClosedChannelException e) {}
|
140
|
+
}
|
141
|
+
|
142
|
+
public void startServer (SocketAddress sa, ConnectionFactory f) throws EmReactorException {
|
143
|
+
String s = reactor.startTcpServer(sa);
|
144
|
+
reactor.acceptors.put(s, f);
|
145
|
+
}
|
146
|
+
|
147
|
+
public void stop() {
|
148
|
+
reactor.stop();
|
149
|
+
}
|
150
|
+
public void run() {
|
151
|
+
try {
|
152
|
+
reactor.run();
|
153
|
+
} catch (IOException e) {}
|
154
|
+
}
|
155
|
+
public void run (final Runnable r) {
|
156
|
+
addTimer(0, new Timer() {
|
157
|
+
public void fire() {
|
158
|
+
r.run();
|
159
|
+
}
|
160
|
+
});
|
161
|
+
run();
|
162
|
+
}
|
163
|
+
|
164
|
+
public void sendData (String sig, ByteBuffer bb) {
|
165
|
+
try {
|
166
|
+
reactor.sendData(sig, bb);
|
167
|
+
} catch (IOException e) {}
|
168
|
+
}
|
169
|
+
|
170
|
+
public void sendDatagram (String sig, ByteBuffer bb, InetSocketAddress target) {
|
171
|
+
reactor.sendDatagram(sig, bb, target.getHostName(), target.getPort());
|
172
|
+
}
|
173
|
+
|
174
|
+
public void closeConnection (String sig, boolean afterWriting) {
|
175
|
+
try {
|
176
|
+
reactor.closeConnection(sig, afterWriting);
|
177
|
+
} catch (ClosedChannelException e) {}
|
178
|
+
}
|
179
|
+
|
180
|
+
public void openDatagramSocket (Connection c) {
|
181
|
+
openDatagramSocket (new InetSocketAddress ("0.0.0.0", 0), c);
|
182
|
+
}
|
183
|
+
public void openDatagramSocket (InetSocketAddress addr, Connection c) {
|
184
|
+
try {
|
185
|
+
String s = reactor.openUdpSocket(addr);
|
186
|
+
c.application = this;
|
187
|
+
c.signature = s;
|
188
|
+
reactor.connections.put(s, c);
|
189
|
+
c.postInit();
|
190
|
+
} catch (ClosedChannelException e) {
|
191
|
+
} catch (IOException e) {
|
192
|
+
System.out.println ("Bad Datagram socket "+e+" "+addr);
|
193
|
+
/* TODO, can't catch this here, because it can happen on a bad address */
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
@@ -0,0 +1,74 @@
|
|
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;
|
32
|
+
|
33
|
+
//import java.io.*;
|
34
|
+
import java.nio.*;
|
35
|
+
import java.net.*;
|
36
|
+
//import java.nio.channels.*;
|
37
|
+
|
38
|
+
public class Connection {
|
39
|
+
|
40
|
+
public Application application;
|
41
|
+
public String signature;
|
42
|
+
|
43
|
+
public void postInit() {}
|
44
|
+
public void connectionCompleted() {}
|
45
|
+
public void unbind() {}
|
46
|
+
public void receiveData (ByteBuffer bytebuffer) {}
|
47
|
+
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Called by user code.
|
51
|
+
* @param bytebuffer
|
52
|
+
*/
|
53
|
+
public void sendData (ByteBuffer b) {
|
54
|
+
application.sendData(signature, b);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* This is called by user code.
|
59
|
+
* TODO: don't expose the exception here.
|
60
|
+
*/
|
61
|
+
public void close() {
|
62
|
+
application.closeConnection(signature, false);
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* This is called by user code/
|
66
|
+
*/
|
67
|
+
public void closeAfterWriting() {
|
68
|
+
application.closeConnection(signature, true);
|
69
|
+
}
|
70
|
+
|
71
|
+
public void sendDatagram (ByteBuffer bb, InetSocketAddress addr) {
|
72
|
+
application.sendDatagram (signature, bb, addr);
|
73
|
+
}
|
74
|
+
}
|