annotate src/org/eclipse/jetty/io/nio/SslConnection.java @ 972:5ee36654b383

simplify AbstractHttpConnection
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 15 Oct 2016 22:42:05 -0600
parents 866f2e801618
children 4d9fe9cc554d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.io.nio;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.nio.ByteBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.util.concurrent.atomic.AtomicBoolean;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import javax.net.ssl.SSLEngine;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import javax.net.ssl.SSLEngineResult;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import javax.net.ssl.SSLEngineResult.HandshakeStatus;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import javax.net.ssl.SSLException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import javax.net.ssl.SSLSession;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.io.AbstractConnection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.io.AsyncEndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import org.eclipse.jetty.io.Buffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import org.eclipse.jetty.io.EndPoint;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
34 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
35 import org.slf4j.LoggerFactory;
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
36
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 /** SSL Connection.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 * An AysyncConnection that acts as an interceptor between and EndPoint and another
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 * Connection, that implements TLS encryption using an {@link SSLEngine}.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 * The connector uses an {@link AsyncEndPoint} (like {@link SelectChannelEndPoint}) as
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 * it's source/sink of encrypted data. It then provides {@link #getSslEndPoint()} to
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 * expose a source/sink of unencrypted data to another connection (eg HttpConnection).
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 */
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
47 public final class SslConnection extends AbstractConnection implements AsyncConnection
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 {
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
49 private final Logger _logger = LoggerFactory.getLogger("org.eclipse.jetty.io.nio.ssl");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
51 private static final NIOBuffer __ZERO_BUFFER=new IndirectNIOBuffer(0);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
53 private static final ThreadLocal<SslBuffers> __buffers = new ThreadLocal<SslBuffers>();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54 private final SSLEngine _engine;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
55 private final SSLSession _session;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 private AsyncConnection _connection;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 private final SslEndPoint _sslEndPoint;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 private int _allocations;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
59 private SslBuffers _buffers;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 private NIOBuffer _inbound;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 private NIOBuffer _unwrapBuf;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 private NIOBuffer _outbound;
952
669769bcdf5c simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 945
diff changeset
63 private final AsyncEndPoint _aEndp;
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 private boolean _allowRenegotiate=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 private boolean _handshook;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 private boolean _ishut;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 private boolean _oshut;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 private final AtomicBoolean _progressed = new AtomicBoolean();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 /* ------------------------------------------------------------ */
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 /* this is a half baked buffer pool
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 */
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 private static class SslBuffers
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 final NIOBuffer _in;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 final NIOBuffer _out;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 final NIOBuffer _unwrap;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 SslBuffers(int packetSize, int appSize)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 _in=new IndirectNIOBuffer(packetSize);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 _out=new IndirectNIOBuffer(packetSize);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 _unwrap=new IndirectNIOBuffer(appSize);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86
952
669769bcdf5c simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 945
diff changeset
87 public SslConnection(SSLEngine engine,AsyncEndPoint endp)
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 this(engine,endp,System.currentTimeMillis());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91
952
669769bcdf5c simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 945
diff changeset
92 private SslConnection(SSLEngine engine,AsyncEndPoint endp, long timeStamp)
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 super(endp,timeStamp);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 _engine=engine;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 _session=_engine.getSession();
952
669769bcdf5c simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 945
diff changeset
97 _aEndp=endp;
669769bcdf5c simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 945
diff changeset
98 _sslEndPoint = new SslEndPoint();
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 /* ------------------------------------------------------------ */
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 /**
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 * @return True if SSL re-negotiation is allowed (default false)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 */
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 public boolean isAllowRenegotiate()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 return _allowRenegotiate;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 /* ------------------------------------------------------------ */
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 /**
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 * Set if SSL re-negotiation is allowed. CVE-2009-3555 discovered
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 * a vulnerability in SSL/TLS with re-negotiation. If your JVM
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 * does not have CVE-2009-3555 fixed, then re-negotiation should
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 * not be allowed. CVE-2009-3555 was fixed in Sun java 1.6 with a ban
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 * of renegotiates in u19 and with RFC5746 in u22.
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 *
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 * @param allowRenegotiate
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 * true if re-negotiation is allowed (default false)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 */
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 public void setAllowRenegotiate(boolean allowRenegotiate)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 _allowRenegotiate = allowRenegotiate;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 /* ------------------------------------------------------------ */
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 private void allocateBuffers()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 synchronized (this)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 if (_allocations++==0)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133 if (_buffers==null)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 _buffers=__buffers.get();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 if (_buffers==null)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 _buffers=new SslBuffers(_session.getPacketBufferSize()*2,_session.getApplicationBufferSize()*2);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 _inbound=_buffers._in;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 _outbound=_buffers._out;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 _unwrapBuf=_buffers._unwrap;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 __buffers.set(null);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 /* ------------------------------------------------------------ */
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 private void releaseBuffers()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 synchronized (this)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 if (--_allocations==0)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 if (_buffers!=null &&
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 _inbound.length()==0 &&
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 _outbound.length()==0 &&
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 _unwrapBuf.length()==0)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 _inbound=null;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 _outbound=null;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 _unwrapBuf=null;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 __buffers.set(_buffers);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 _buffers=null;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
169 @Override
965
866f2e801618 handle() returns void
Franklin Schmidt <fschmidt@gmail.com>
parents: 960
diff changeset
170 public void handle() throws IOException
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 try
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 allocateBuffers();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 boolean progress=true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 while (progress)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 progress=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 // If we are handshook let the delegate connection
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 if (_engine.getHandshakeStatus()!=HandshakeStatus.NOT_HANDSHAKING)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 progress=process(null,null);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 // handle the delegate connection
965
866f2e801618 handle() returns void
Franklin Schmidt <fschmidt@gmail.com>
parents: 960
diff changeset
187 _connection.handle();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 _logger.debug("{} handle {} progress={}", _session, this, progress);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 finally
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 releaseBuffers();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 if (!_ishut && _sslEndPoint.isInputShutdown() && _sslEndPoint.isOpen())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 _ishut=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 try
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 _connection.onInputShutdown();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 catch(Throwable x)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 _logger.warn("onInputShutdown failed", x);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 try{_sslEndPoint.close();}
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 catch(IOException e2){
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 _logger.trace("",e2);}
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 public boolean isIdle()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 return false;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
218
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 public boolean isSuspended()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 return false;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 @Override
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 public void onIdleExpired(long idleForMs)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 try
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 _logger.debug("onIdleExpired {}ms on {}",idleForMs,this);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 if (_endp.isOutputShutdown())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 _sslEndPoint.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 else
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 _sslEndPoint.shutdownOutput();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 catch (IOException e)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 _logger.warn("",e);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 super.onIdleExpired(idleForMs);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
241
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 public void onInputShutdown() throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 {
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
244
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 private synchronized boolean process(Buffer toFill, Buffer toFlush) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 boolean some_progress=false;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 try
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 // We need buffers to progress
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 allocateBuffers();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
254
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 // if we don't have a buffer to put received data into
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 if (toFill==null)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 // use the unwrapbuffer to hold received data.
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 _unwrapBuf.compact();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 toFill=_unwrapBuf;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 // Else if the fill buffer is too small for the SSL session
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 else if (toFill.capacity()<_session.getApplicationBufferSize())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 // fill to the temporary unwrapBuffer
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 boolean progress=process(null,toFlush);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 // if we received any data,
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 if (_unwrapBuf!=null && _unwrapBuf.hasContent())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 // transfer from temp buffer to fill buffer
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 _unwrapBuf.skip(toFill.put(_unwrapBuf));
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 return true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 else
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 // return progress from recursive call
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 return progress;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 // Else if there is some temporary data
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 else if (_unwrapBuf!=null && _unwrapBuf.hasContent())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 // transfer from temp buffer to fill buffer
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 _unwrapBuf.skip(toFill.put(_unwrapBuf));
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 return true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
286
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 // If we are here, we have a buffer ready into which we can put some read data.
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 // If we have no data to flush, flush the empty buffer
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 if (toFlush==null)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 toFlush=__ZERO_BUFFER;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
292
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 // While we are making progress processing SSL engine
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 boolean progress=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 while (progress)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 progress=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
298
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 // Do any real IO
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 int filled=0,flushed=0;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 try
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 // Read any available data
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 if (_inbound.space()>0 && (filled=_endp.fill(_inbound))>0)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 progress = true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
306
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 // flush any output data
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 if (_outbound.hasContent() && (flushed=_endp.flush(_outbound))>0)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 progress = true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 catch (IOException e)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 _endp.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 throw e;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 finally
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 _logger.debug("{} {} {} filled={}/{} flushed={}/{}",_session,this,_engine.getHandshakeStatus(),filled,_inbound.length(),flushed,_outbound.length());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
320
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 // handle the current hand share status
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 switch(_engine.getHandshakeStatus())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 case FINISHED:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 throw new IllegalStateException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
326
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 case NOT_HANDSHAKING:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 // Try unwrapping some application data
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 if (toFill.space()>0 && _inbound.hasContent() && unwrap(toFill))
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 progress=true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
332
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 // Try wrapping some application data
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 if (toFlush.hasContent() && _outbound.space()>0 && wrap(toFlush))
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 progress=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
338
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 case NEED_TASK:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 // A task needs to be run, so run it!
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 Runnable task;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 while ((task=_engine.getDelegatedTask())!=null)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 progress=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 task.run();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
348
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
351
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 case NEED_WRAP:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 // The SSL needs to send some handshake data to the other side
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 if (_handshook && !_allowRenegotiate)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 _endp.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 else if (wrap(toFlush))
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 progress=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
361
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 case NEED_UNWRAP:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 // The SSL needs to receive some handshake data from the other side
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 if (_handshook && !_allowRenegotiate)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 _endp.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 else if (!_inbound.hasContent()&&filled==-1)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 // No more input coming
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 _endp.shutdownInput();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 else if (unwrap(toFill))
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 progress=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 break;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
377
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 // pass on ishut/oshut state
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 if (_endp.isOpen() && _endp.isInputShutdown() && !_inbound.hasContent())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 closeInbound();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
381
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 if (_endp.isOpen() && _engine.isOutboundDone() && !_outbound.hasContent())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 _endp.shutdownOutput();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
384
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 // remember if any progress has been made
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 some_progress|=progress;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
388
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 // If we are reading into the temp buffer and it has some content, then we should be dispatched.
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 if (toFill==_unwrapBuf && _unwrapBuf.hasContent() && !_connection.isSuspended())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 _aEndp.dispatch();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 finally
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 releaseBuffers();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 if (some_progress)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 _progressed.set(true);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 return some_progress;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
401
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 private void closeInbound()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 try
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 _engine.closeInbound();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 catch (SSLException x)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 _logger.debug("",x);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
413
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 private synchronized boolean wrap(final Buffer buffer) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
415 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 ByteBuffer bbuf=extractByteBuffer(buffer);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 final SSLEngineResult result;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
418
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 synchronized(bbuf)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 _outbound.compact();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 ByteBuffer out_buffer=_outbound.getByteBuffer();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 synchronized(out_buffer)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 try
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 bbuf.position(buffer.getIndex());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 bbuf.limit(buffer.putIndex());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 out_buffer.position(_outbound.putIndex());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 out_buffer.limit(out_buffer.capacity());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 result=_engine.wrap(bbuf,out_buffer);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 if (_logger.isDebugEnabled())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 _logger.debug("{} wrap {} {} consumed={} produced={}",
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 _session,
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 result.getStatus(),
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 result.getHandshakeStatus(),
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 result.bytesConsumed(),
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 result.bytesProduced());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
439
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
440
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 buffer.skip(result.bytesConsumed());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 _outbound.setPutIndex(_outbound.putIndex()+result.bytesProduced());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 catch(SSLException e)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 _logger.debug(String.valueOf(_endp), e);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 _endp.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 throw e;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 finally
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 out_buffer.position(0);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 out_buffer.limit(out_buffer.capacity());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 bbuf.position(0);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 bbuf.limit(bbuf.capacity());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
459
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 switch(result.getStatus())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 case BUFFER_UNDERFLOW:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 throw new IllegalStateException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
464
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 case BUFFER_OVERFLOW:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
467
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 case OK:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 if (result.getHandshakeStatus()==HandshakeStatus.FINISHED)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 _handshook=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
472
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 case CLOSED:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 _logger.debug("wrap CLOSE {} {}",this,result);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 if (result.getHandshakeStatus()==HandshakeStatus.FINISHED)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 _endp.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
478
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 default:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 _logger.debug("{} wrap default {}",_session,result);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 throw new IOException(result.toString());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
483
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 return result.bytesConsumed()>0 || result.bytesProduced()>0;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
486
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 private synchronized boolean unwrap(final Buffer buffer) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 if (!_inbound.hasContent())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
491
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 ByteBuffer bbuf=extractByteBuffer(buffer);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 final SSLEngineResult result;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
494
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 synchronized(bbuf)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 ByteBuffer in_buffer=_inbound.getByteBuffer();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 synchronized(in_buffer)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 try
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 bbuf.position(buffer.putIndex());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 bbuf.limit(buffer.capacity());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 in_buffer.position(_inbound.getIndex());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 in_buffer.limit(_inbound.putIndex());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
506
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 result=_engine.unwrap(in_buffer,bbuf);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 if (_logger.isDebugEnabled())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 _logger.debug("{} unwrap {} {} consumed={} produced={}",
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 _session,
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 result.getStatus(),
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 result.getHandshakeStatus(),
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 result.bytesConsumed(),
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 result.bytesProduced());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
515
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 _inbound.skip(result.bytesConsumed());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 _inbound.compact();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 buffer.setPutIndex(buffer.putIndex()+result.bytesProduced());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 catch(SSLException e)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 _logger.debug(String.valueOf(_endp), e);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 _endp.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 throw e;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 finally
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 in_buffer.position(0);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 in_buffer.limit(in_buffer.capacity());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 bbuf.position(0);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 bbuf.limit(bbuf.capacity());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
535
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 switch(result.getStatus())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 case BUFFER_UNDERFLOW:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 if (_endp.isInputShutdown())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 _inbound.clear();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
542
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 case BUFFER_OVERFLOW:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 if (_logger.isDebugEnabled()) _logger.debug("{} unwrap {} {}->{}",_session,result.getStatus(),_inbound.toDetailString(),buffer.toDetailString());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
546
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 case OK:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 if (result.getHandshakeStatus()==HandshakeStatus.FINISHED)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 _handshook=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
551
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 case CLOSED:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 _logger.debug("unwrap CLOSE {} {}",this,result);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 if (result.getHandshakeStatus()==HandshakeStatus.FINISHED)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 _endp.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
557
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 default:
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 _logger.debug("{} wrap default {}",_session,result);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 throw new IOException(result.toString());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
562
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 //if (LOG.isDebugEnabled() && result.bytesProduced()>0)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 // LOG.debug("{} unwrapped '{}'",_session,buffer);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
565
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 return result.bytesConsumed()>0 || result.bytesProduced()>0;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
568
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
569
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 private ByteBuffer extractByteBuffer(Buffer buffer)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 if (buffer.buffer() instanceof NIOBuffer)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 return ((NIOBuffer)buffer.buffer()).getByteBuffer();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 return ByteBuffer.wrap(buffer.array());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
576
952
669769bcdf5c simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 945
diff changeset
577 public SslEndPoint getSslEndPoint()
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 return _sslEndPoint;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
581
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 public String toString()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 return String.format("%s %s", super.toString(), _sslEndPoint);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
586
952
669769bcdf5c simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 945
diff changeset
587
669769bcdf5c simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 945
diff changeset
588 public final class SslEndPoint implements AsyncEndPoint
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 public SSLEngine getSslEngine()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 return _engine;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
594
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 public AsyncEndPoint getEndpoint()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 return _aEndp;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
599
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 public void shutdownOutput() throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 synchronized (SslConnection.this)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 _logger.debug("{} ssl endp.oshut {}",_session,this);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 _engine.closeOutbound();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 _oshut=true;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608 flush();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
610
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 public boolean isOutputShutdown()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 synchronized (SslConnection.this)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 return _oshut||!isOpen()||_engine.isOutboundDone();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
618
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 public void shutdownInput() throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 _logger.debug("{} ssl endp.ishut!",_session);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 // We do not do a closeInput here, as SSL does not support half close.
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 // isInputShutdown works it out itself from buffer state and underlying endpoint state.
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
625
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 public boolean isInputShutdown()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 synchronized (SslConnection.this)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 return _endp.isInputShutdown() &&
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 !(_unwrapBuf!=null&&_unwrapBuf.hasContent()) &&
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632 !(_inbound!=null&&_inbound.hasContent());
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 }
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
635
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 public void close() throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 _logger.debug("{} ssl endp.close",_session);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 _endp.close();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
641
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 public int fill(Buffer buffer) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 int size=buffer.length();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 process(buffer, null);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
646
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 int filled=buffer.length()-size;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 if (filled==0 && isInputShutdown())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 return -1;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 return filled;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
653
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 public int flush(Buffer buffer) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656 int size = buffer.length();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 process(null, buffer);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 return size-buffer.length();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
660
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 if (header!=null && header.hasContent())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 return flush(header);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 if (buffer!=null && buffer.hasContent())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 return flush(buffer);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 if (trailer!=null && trailer.hasContent())
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 return flush(trailer);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 return 0;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
671
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 public boolean blockReadable(long millisecs) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 long now = System.currentTimeMillis();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 long end=millisecs>0?(now+millisecs):Long.MAX_VALUE;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
676
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
677 while (now<end)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 if (process(null,null))
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 break;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 _endp.blockReadable(end-now);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
682 now = System.currentTimeMillis();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
684
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 return now<end;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
686 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
687
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 public boolean blockWritable(long millisecs) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 return _endp.blockWritable(millisecs);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
692
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 public boolean isOpen()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 return _endp.isOpen();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
696 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
697
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 public Object getTransport()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 return _endp;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
702
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 public void flush() throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 process(null, null);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
707
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 public void dispatch()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 _aEndp.dispatch();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
712
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 public boolean hasProgressed()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 return _progressed.getAndSet(false);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
717
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 public String getLocalAddr()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720 return _aEndp.getLocalAddr();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
722
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 public String getLocalHost()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
724 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 return _aEndp.getLocalHost();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
727
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 public int getLocalPort()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
730 return _aEndp.getLocalPort();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
732
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733 public String getRemoteAddr()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 return _aEndp.getRemoteAddr();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
737
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 public String getRemoteHost()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 return _aEndp.getRemoteHost();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
741 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
742
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 public int getRemotePort()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 return _aEndp.getRemotePort();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
747
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
748 public boolean isBlocking()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
750 return false;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
751 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
752
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
753 public int getMaxIdleTime()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
754 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 return _aEndp.getMaxIdleTime();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
756 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
757
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
758 public void setMaxIdleTime(int timeMs) throws IOException
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
760 _aEndp.setMaxIdleTime(timeMs);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
762
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
763 public void setConnection(AsyncConnection connection)
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
765 _connection = connection;
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
766 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
767
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
768 public String toString()
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 {
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 // Do NOT use synchronized (SslConnection.this)
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 // because it's very easy to deadlock when debugging is enabled.
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
772 // We do a best effort to print the right toString() and that's it.
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 Buffer inbound = _inbound;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 Buffer outbound = _outbound;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 Buffer unwrap = _unwrapBuf;
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
776 int i = inbound == null? -1 : inbound.length();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 int o = outbound == null ? -1 : outbound.length();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 int u = unwrap == null ? -1 : unwrap.length();
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779 return String.format("SSL %s i/o/u=%d/%d/%d ishut=%b oshut=%b {%s}",
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
780 _engine.getHandshakeStatus(),
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
781 i, o, u,
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
782 _ishut, _oshut,
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 _connection);
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
785
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
786 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
787 }