sidekick-client 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. data/VERSION +1 -1
  2. data/lib/sidekick/client/sidekick_client.rb +0 -3
  3. data/lib/sidekick/shared/sidekick_queue_publisher.rb +1 -1
  4. data/sidekick-client.gemspec +1 -158
  5. metadata +1 -158
  6. data/lib/ext/eventmachine-0.12.10/.gitignore +0 -14
  7. data/lib/ext/eventmachine-0.12.10/README +0 -82
  8. data/lib/ext/eventmachine-0.12.10/Rakefile +0 -374
  9. data/lib/ext/eventmachine-0.12.10/docs/COPYING +0 -60
  10. data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +0 -211
  11. data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +0 -133
  12. data/lib/ext/eventmachine-0.12.10/docs/EPOLL +0 -141
  13. data/lib/ext/eventmachine-0.12.10/docs/GNU +0 -281
  14. data/lib/ext/eventmachine-0.12.10/docs/INSTALL +0 -13
  15. data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +0 -38
  16. data/lib/ext/eventmachine-0.12.10/docs/LEGAL +0 -25
  17. data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  18. data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +0 -75
  19. data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +0 -94
  20. data/lib/ext/eventmachine-0.12.10/docs/SMTP +0 -2
  21. data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +0 -89
  22. data/lib/ext/eventmachine-0.12.10/docs/TODO +0 -8
  23. data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +0 -40
  24. data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +0 -43
  25. data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +0 -2
  26. data/lib/ext/eventmachine-0.12.10/examples/helper.rb +0 -2
  27. data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +0 -125
  28. data/lib/ext/eventmachine-0.12.10/ext/binder.h +0 -46
  29. data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +0 -827
  30. data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +0 -202
  31. data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +0 -1893
  32. data/lib/ext/eventmachine-0.12.10/ext/ed.h +0 -424
  33. data/lib/ext/eventmachine-0.12.10/ext/em.cpp +0 -2282
  34. data/lib/ext/eventmachine-0.12.10/ext/em.h +0 -232
  35. data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +0 -300
  36. data/lib/ext/eventmachine-0.12.10/ext/emwin.h +0 -94
  37. data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +0 -26
  38. data/lib/ext/eventmachine-0.12.10/ext/epoll.h +0 -25
  39. data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +0 -122
  40. data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +0 -96
  41. data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +0 -148
  42. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +0 -83
  43. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +0 -214
  44. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +0 -59
  45. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +0 -127
  46. data/lib/ext/eventmachine-0.12.10/ext/files.cpp +0 -94
  47. data/lib/ext/eventmachine-0.12.10/ext/files.h +0 -65
  48. data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +0 -81
  49. data/lib/ext/eventmachine-0.12.10/ext/page.cpp +0 -107
  50. data/lib/ext/eventmachine-0.12.10/ext/page.h +0 -51
  51. data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +0 -349
  52. data/lib/ext/eventmachine-0.12.10/ext/project.h +0 -151
  53. data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +0 -1166
  54. data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +0 -89
  55. data/lib/ext/eventmachine-0.12.10/ext/sigs.h +0 -32
  56. data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +0 -460
  57. data/lib/ext/eventmachine-0.12.10/ext/ssl.h +0 -94
  58. data/lib/ext/eventmachine-0.12.10/java/.classpath +0 -8
  59. data/lib/ext/eventmachine-0.12.10/java/.project +0 -17
  60. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +0 -570
  61. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +0 -40
  62. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +0 -69
  63. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +0 -189
  64. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +0 -364
  65. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +0 -194
  66. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  67. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  68. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  69. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  70. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  71. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  72. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  73. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  74. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  75. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  76. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  77. data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +0 -138
  78. data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +0 -26
  79. data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +0 -57
  80. data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +0 -564
  81. data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +0 -192
  82. data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +0 -54
  83. data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +0 -61
  84. data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +0 -66
  85. data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +0 -44
  86. data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +0 -119
  87. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +0 -138
  88. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +0 -263
  89. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +0 -590
  90. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +0 -125
  91. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +0 -161
  92. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +0 -323
  93. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +0 -45
  94. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +0 -247
  95. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +0 -175
  96. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +0 -357
  97. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +0 -547
  98. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +0 -66
  99. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +0 -200
  100. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +0 -53
  101. data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +0 -36
  102. data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +0 -61
  103. data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +0 -85
  104. data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +0 -130
  105. data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +0 -56
  106. data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +0 -3
  107. data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +0 -1592
  108. data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +0 -32
  109. data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +0 -75
  110. data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +0 -77
  111. data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +0 -87
  112. data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +0 -48
  113. data/lib/ext/eventmachine-0.12.10/lib/evma.rb +0 -32
  114. data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +0 -257
  115. data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +0 -1022
  116. data/lib/ext/eventmachine-0.12.10/setup.rb +0 -1585
  117. data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +0 -77
  118. data/lib/ext/eventmachine-0.12.10/tests/client.crt +0 -31
  119. data/lib/ext/eventmachine-0.12.10/tests/client.key +0 -51
  120. data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +0 -126
  121. data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +0 -284
  122. data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +0 -63
  123. data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +0 -35
  124. data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +0 -47
  125. data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +0 -160
  126. data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +0 -35
  127. data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +0 -82
  128. data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +0 -55
  129. data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +0 -49
  130. data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +0 -198
  131. data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +0 -30
  132. data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +0 -37
  133. data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +0 -218
  134. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +0 -218
  135. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +0 -153
  136. data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +0 -50
  137. data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +0 -60
  138. data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +0 -182
  139. data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +0 -317
  140. data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +0 -133
  141. data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +0 -37
  142. data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +0 -70
  143. data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +0 -48
  144. data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +0 -48
  145. data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +0 -128
  146. data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +0 -92
  147. data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +0 -125
  148. data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +0 -44
  149. data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +0 -42
  150. data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +0 -72
  151. data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +0 -242
  152. data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +0 -76
  153. data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +0 -83
  154. data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +0 -85
  155. data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +0 -322
  156. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +0 -79
  157. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +0 -50
  158. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +0 -82
  159. data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +0 -162
  160. data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +0 -36
  161. data/lib/ext/eventmachine-0.12.10/tests/testem.rb +0 -31
  162. data/lib/ext/eventmachine-0.12.10/web/whatis +0 -7
@@ -1,189 +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;
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
- }
@@ -1,364 +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
- */
32
- package com.rubyeventmachine;
33
-
34
- /**
35
- * @author francis
36
- *
37
- */
38
-
39
- import java.nio.channels.*;
40
- import java.nio.*;
41
- import java.util.*;
42
- import java.io.*;
43
- import java.net.Socket;
44
- import javax.net.ssl.*;
45
- import javax.net.ssl.SSLEngineResult.*;
46
- import java.lang.reflect.Field;
47
-
48
- import java.security.*;
49
-
50
- public class EventableSocketChannel implements EventableChannel {
51
- Selector selector;
52
- SelectionKey channelKey;
53
- SocketChannel channel;
54
-
55
- long binding;
56
- LinkedList<ByteBuffer> outboundQ;
57
-
58
- boolean bCloseScheduled;
59
- boolean bConnectPending;
60
- boolean bWatchOnly;
61
- boolean bAttached;
62
- boolean bNotifyReadable;
63
- boolean bNotifyWritable;
64
-
65
- SSLEngine sslEngine;
66
- SSLContext sslContext;
67
-
68
- public EventableSocketChannel (SocketChannel sc, long _binding, Selector sel) {
69
- channel = sc;
70
- binding = _binding;
71
- selector = sel;
72
- bCloseScheduled = false;
73
- bConnectPending = false;
74
- bWatchOnly = false;
75
- bAttached = false;
76
- bNotifyReadable = false;
77
- bNotifyWritable = false;
78
- outboundQ = new LinkedList<ByteBuffer>();
79
- }
80
-
81
- public long getBinding() {
82
- return binding;
83
- }
84
-
85
- public SocketChannel getChannel() {
86
- return channel;
87
- }
88
-
89
- public void register() throws ClosedChannelException {
90
- if (channelKey == null) {
91
- int events = currentEvents();
92
- channelKey = channel.register(selector, events, this);
93
- }
94
- }
95
-
96
- /**
97
- * Terminate with extreme prejudice. Don't assume there will be another pass through
98
- * the reactor core.
99
- */
100
- public void close() {
101
- if (channelKey != null) {
102
- channelKey.cancel();
103
- channelKey = null;
104
- }
105
-
106
- if (bAttached) {
107
- // attached channels are copies, so reset the file descriptor to prevent java from close()ing it
108
- Field f;
109
- FileDescriptor fd;
110
-
111
- try {
112
- /* do _NOT_ clobber fdVal here, it will break epoll/kqueue on jdk6!
113
- * channelKey.cancel() above does not occur until the next call to select
114
- * and if fdVal is gone, we will continue to get events for this fd.
115
- *
116
- * instead, remove fdVal in cleanup(), which is processed via DetachedConnections,
117
- * after UnboundConnections but before NewConnections.
118
- */
119
-
120
- f = channel.getClass().getDeclaredField("fd");
121
- f.setAccessible(true);
122
- fd = (FileDescriptor) f.get(channel);
123
-
124
- f = fd.getClass().getDeclaredField("fd");
125
- f.setAccessible(true);
126
- f.set(fd, -1);
127
- } catch (java.lang.NoSuchFieldException e) {
128
- e.printStackTrace();
129
- } catch (java.lang.IllegalAccessException e) {
130
- e.printStackTrace();
131
- }
132
-
133
- return;
134
- }
135
-
136
- try {
137
- channel.close();
138
- } catch (IOException e) {
139
- }
140
- }
141
-
142
- public void cleanup() {
143
- if (bAttached) {
144
- Field f;
145
- try {
146
- f = channel.getClass().getDeclaredField("fdVal");
147
- f.setAccessible(true);
148
- f.set(channel, -1);
149
- } catch (java.lang.NoSuchFieldException e) {
150
- e.printStackTrace();
151
- } catch (java.lang.IllegalAccessException e) {
152
- e.printStackTrace();
153
- }
154
- }
155
-
156
- channel = null;
157
- }
158
-
159
- public void scheduleOutboundData (ByteBuffer bb) {
160
- if (!bCloseScheduled && bb.remaining() > 0) {
161
- if (sslEngine != null) {
162
- try {
163
- ByteBuffer b = ByteBuffer.allocate(32*1024); // TODO, preallocate this buffer.
164
- sslEngine.wrap(bb, b);
165
- b.flip();
166
- outboundQ.addLast(b);
167
- } catch (SSLException e) {
168
- throw new RuntimeException ("ssl error");
169
- }
170
- }
171
- else {
172
- outboundQ.addLast(bb);
173
- }
174
-
175
- updateEvents();
176
- }
177
- }
178
-
179
- public void scheduleOutboundDatagram (ByteBuffer bb, String recipAddress, int recipPort) {
180
- throw new RuntimeException ("datagram sends not supported on this channel");
181
- }
182
-
183
- /**
184
- * Called by the reactor when we have selected readable.
185
- */
186
- public void readInboundData (ByteBuffer bb) throws IOException {
187
- if (channel.read(bb) == -1)
188
- throw new IOException ("eof");
189
- }
190
-
191
- /**
192
- * Called by the reactor when we have selected writable.
193
- * Return false to indicate an error that should cause the connection to close.
194
- * TODO, VERY IMPORTANT: we're here because we selected writable, but it's always
195
- * possible to become unwritable between the poll and when we get here. The way
196
- * this code is written, we're depending on a nonblocking write NOT TO CONSUME
197
- * the whole outbound buffer in this case, rather than firing an exception.
198
- * We should somehow verify that this is indeed Java's defined behavior.
199
- * Also TODO, see if we can use gather I/O rather than one write at a time.
200
- * Ought to be a big performance enhancer.
201
- * @return
202
- */
203
- public boolean writeOutboundData() throws IOException {
204
- while (!outboundQ.isEmpty()) {
205
- ByteBuffer b = outboundQ.getFirst();
206
- if (b.remaining() > 0)
207
- channel.write(b);
208
-
209
- // Did we consume the whole outbound buffer? If yes,
210
- // pop it off and keep looping. If no, the outbound network
211
- // buffers are full, so break out of here.
212
- if (b.remaining() == 0)
213
- outboundQ.removeFirst();
214
- else
215
- break;
216
- }
217
-
218
- if (outboundQ.isEmpty() && !bCloseScheduled) {
219
- updateEvents();
220
- }
221
-
222
- // ALWAYS drain the outbound queue before triggering a connection close.
223
- // If anyone wants to close immediately, they're responsible for clearing
224
- // the outbound queue.
225
- return (bCloseScheduled && outboundQ.isEmpty()) ? false : true;
226
- }
227
-
228
- public void setConnectPending() {
229
- bConnectPending = true;
230
- updateEvents();
231
- }
232
-
233
- /**
234
- * Called by the reactor when we have selected connectable.
235
- * Return false to indicate an error that should cause the connection to close.
236
- */
237
- public boolean finishConnecting() throws IOException {
238
- channel.finishConnect();
239
-
240
- bConnectPending = false;
241
- updateEvents();
242
- return true;
243
- }
244
-
245
- public boolean scheduleClose (boolean afterWriting) {
246
- // TODO: What the hell happens here if bConnectPending is set?
247
- if (!afterWriting)
248
- outboundQ.clear();
249
-
250
- if (outboundQ.isEmpty())
251
- return true;
252
- else {
253
- updateEvents();
254
- bCloseScheduled = true;
255
- return false;
256
- }
257
- }
258
-
259
- public void startTls() {
260
- if (sslEngine == null) {
261
- try {
262
- sslContext = SSLContext.getInstance("TLS");
263
- sslContext.init(null, null, null); // TODO, fill in the parameters.
264
- sslEngine = sslContext.createSSLEngine(); // TODO, should use the parameterized version, to get Kerb stuff and session re-use.
265
- sslEngine.setUseClientMode(false);
266
- } catch (NoSuchAlgorithmException e) {
267
- throw new RuntimeException ("unable to start TLS"); // TODO, get rid of this.
268
- } catch (KeyManagementException e) {
269
- throw new RuntimeException ("unable to start TLS"); // TODO, get rid of this.
270
- }
271
- }
272
- System.out.println ("Starting TLS");
273
- }
274
-
275
- public ByteBuffer dispatchInboundData (ByteBuffer bb) throws SSLException {
276
- if (sslEngine != null) {
277
- if (true) throw new RuntimeException ("TLS currently unimplemented");
278
- System.setProperty("javax.net.debug", "all");
279
- ByteBuffer w = ByteBuffer.allocate(32*1024); // TODO, WRONG, preallocate this buffer.
280
- SSLEngineResult res = sslEngine.unwrap(bb, w);
281
- if (res.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
282
- Runnable r;
283
- while ((r = sslEngine.getDelegatedTask()) != null) {
284
- r.run();
285
- }
286
- }
287
- System.out.println (bb);
288
- w.flip();
289
- return w;
290
- }
291
- else
292
- return bb;
293
- }
294
-
295
- public void setCommInactivityTimeout (long seconds) {
296
- // TODO
297
- System.out.println ("SOCKET: SET COMM INACTIVITY UNIMPLEMENTED " + seconds);
298
- }
299
-
300
- public Object[] getPeerName () {
301
- Socket sock = channel.socket();
302
- return new Object[]{ sock.getPort(), sock.getInetAddress().getHostAddress() };
303
- }
304
-
305
- public void setWatchOnly() {
306
- bWatchOnly = true;
307
- updateEvents();
308
- }
309
- public boolean isWatchOnly() { return bWatchOnly; }
310
-
311
- public void setAttached() {
312
- bAttached = true;
313
- }
314
- public boolean isAttached() { return bAttached; }
315
-
316
- public void setNotifyReadable (boolean mode) {
317
- bNotifyReadable = mode;
318
- updateEvents();
319
- }
320
- public boolean isNotifyReadable() { return bNotifyReadable; }
321
-
322
- public void setNotifyWritable (boolean mode) {
323
- bNotifyWritable = mode;
324
- updateEvents();
325
- }
326
- public boolean isNotifyWritable() { return bNotifyWritable; }
327
-
328
- private void updateEvents() {
329
- if (channelKey == null)
330
- return;
331
-
332
- int events = currentEvents();
333
-
334
- if (channelKey.interestOps() != events) {
335
- channelKey.interestOps(events);
336
- }
337
- }
338
-
339
- private int currentEvents() {
340
- int events = 0;
341
-
342
- if (bWatchOnly)
343
- {
344
- if (bNotifyReadable)
345
- events |= SelectionKey.OP_READ;
346
-
347
- if (bNotifyWritable)
348
- events |= SelectionKey.OP_WRITE;
349
- }
350
- else
351
- {
352
- if (bConnectPending)
353
- events |= SelectionKey.OP_CONNECT;
354
- else {
355
- events |= SelectionKey.OP_READ;
356
-
357
- if (!outboundQ.isEmpty())
358
- events |= SelectionKey.OP_WRITE;
359
- }
360
- }
361
-
362
- return events;
363
- }
364
- }