Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/nio/SslConnection.java @ 1048:2b769da7f67d
remove Buffer
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Mon, 07 Nov 2016 23:15:42 -0700 |
| parents | a8c92b0a08ed |
| children | 4afdf0f0c5bc |
comparison
equal
deleted
inserted
replaced
| 1047:1accf965d51a | 1048:2b769da7f67d |
|---|---|
| 28 import javax.net.ssl.SSLException; | 28 import javax.net.ssl.SSLException; |
| 29 import javax.net.ssl.SSLSession; | 29 import javax.net.ssl.SSLSession; |
| 30 | 30 |
| 31 import org.eclipse.jetty.io.AbstractConnection; | 31 import org.eclipse.jetty.io.AbstractConnection; |
| 32 import org.eclipse.jetty.io.AsyncEndPoint; | 32 import org.eclipse.jetty.io.AsyncEndPoint; |
| 33 import org.eclipse.jetty.io.Buffer; | 33 import org.eclipse.jetty.io.JBuffer; |
| 34 import org.eclipse.jetty.io.BufferUtil; | 34 import org.eclipse.jetty.io.BufferUtil; |
| 35 import org.eclipse.jetty.io.EndPoint; | 35 import org.eclipse.jetty.io.EndPoint; |
| 36 import org.eclipse.jetty.server.AsyncHttpConnection; | 36 import org.eclipse.jetty.server.AsyncHttpConnection; |
| 37 import org.slf4j.Logger; | 37 import org.slf4j.Logger; |
| 38 import org.slf4j.LoggerFactory; | 38 import org.slf4j.LoggerFactory; |
| 49 */ | 49 */ |
| 50 public final class SslConnection extends AbstractConnection implements AsyncConnection | 50 public final class SslConnection extends AbstractConnection implements AsyncConnection |
| 51 { | 51 { |
| 52 private final Logger _logger = LoggerFactory.getLogger("org.eclipse.jetty.io.nio.ssl"); | 52 private final Logger _logger = LoggerFactory.getLogger("org.eclipse.jetty.io.nio.ssl"); |
| 53 | 53 |
| 54 private static final NIOBuffer __ZERO_BUFFER = BufferUtil.EMPTY_BUFFER; | 54 private static final JBuffer __ZERO_BUFFER = BufferUtil.EMPTY_BUFFER; |
| 55 | 55 |
| 56 private static final ThreadLocal<SslBuffers> __buffers = new ThreadLocal<SslBuffers>(); | 56 private static final ThreadLocal<SslBuffers> __buffers = new ThreadLocal<SslBuffers>(); |
| 57 private final SSLEngine _engine; | 57 private final SSLEngine _engine; |
| 58 private final SSLSession _session; | 58 private final SSLSession _session; |
| 59 private AsyncHttpConnection _connection; | 59 private AsyncHttpConnection _connection; |
| 60 private final SslEndPoint _sslEndPoint; | 60 private final SslEndPoint _sslEndPoint; |
| 61 private int _allocations; | 61 private int _allocations; |
| 62 private SslBuffers _buffers; | 62 private SslBuffers _buffers; |
| 63 private NIOBuffer _inbound; | 63 private JBuffer _inbound; |
| 64 private NIOBuffer _unwrapBuf; | 64 private JBuffer _unwrapBuf; |
| 65 private NIOBuffer _outbound; | 65 private JBuffer _outbound; |
| 66 private final AsyncEndPoint _aEndp; | 66 private final AsyncEndPoint _aEndp; |
| 67 private boolean _allowRenegotiate = true; | 67 private boolean _allowRenegotiate = true; |
| 68 private boolean _handshook; | 68 private boolean _handshook; |
| 69 private boolean _ishut; | 69 private boolean _ishut; |
| 70 private boolean _oshut; | 70 private boolean _oshut; |
| 73 /* ------------------------------------------------------------ */ | 73 /* ------------------------------------------------------------ */ |
| 74 /* this is a half baked buffer pool | 74 /* this is a half baked buffer pool |
| 75 */ | 75 */ |
| 76 private static class SslBuffers | 76 private static class SslBuffers |
| 77 { | 77 { |
| 78 final NIOBuffer _in; | 78 final JBuffer _in; |
| 79 final NIOBuffer _out; | 79 final JBuffer _out; |
| 80 final NIOBuffer _unwrap; | 80 final JBuffer _unwrap; |
| 81 | 81 |
| 82 SslBuffers(int packetSize, int appSize) | 82 SslBuffers(int packetSize, int appSize) |
| 83 { | 83 { |
| 84 _in = BufferUtil.newBuffer(packetSize); | 84 _in = BufferUtil.newBuffer(packetSize); |
| 85 _out = BufferUtil.newBuffer(packetSize); | 85 _out = BufferUtil.newBuffer(packetSize); |
| 207 @Override | 207 @Override |
| 208 public void onInputShutdown() throws IOException | 208 public void onInputShutdown() throws IOException |
| 209 { | 209 { |
| 210 } | 210 } |
| 211 | 211 |
| 212 private synchronized boolean process(Buffer toFill, Buffer toFlush) throws IOException | 212 private synchronized boolean process(JBuffer toFill, JBuffer toFlush) throws IOException |
| 213 { | 213 { |
| 214 boolean some_progress=false; | 214 boolean some_progress=false; |
| 215 try | 215 try |
| 216 { | 216 { |
| 217 // We need buffers to progress | 217 // We need buffers to progress |
| 374 { | 374 { |
| 375 _logger.debug("",x); | 375 _logger.debug("",x); |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 private synchronized boolean wrap(final Buffer buffer) throws IOException | 379 private synchronized boolean wrap(final JBuffer buffer) throws IOException |
| 380 { | 380 { |
| 381 ByteBuffer bbuf=extractByteBuffer(buffer); | 381 ByteBuffer bbuf=extractByteBuffer(buffer); |
| 382 final SSLEngineResult result; | 382 final SSLEngineResult result; |
| 383 | 383 |
| 384 synchronized(bbuf) | 384 synchronized(bbuf) |
| 447 } | 447 } |
| 448 | 448 |
| 449 return result.bytesConsumed()>0 || result.bytesProduced()>0; | 449 return result.bytesConsumed()>0 || result.bytesProduced()>0; |
| 450 } | 450 } |
| 451 | 451 |
| 452 private synchronized boolean unwrap(final Buffer buffer) throws IOException | 452 private synchronized boolean unwrap(final JBuffer buffer) throws IOException |
| 453 { | 453 { |
| 454 if (!_inbound.hasRemaining()) | 454 if (!_inbound.hasRemaining()) |
| 455 return false; | 455 return false; |
| 456 | 456 |
| 457 ByteBuffer bbuf=extractByteBuffer(buffer); | 457 ByteBuffer bbuf=extractByteBuffer(buffer); |
| 530 | 530 |
| 531 return result.bytesConsumed()>0 || result.bytesProduced()>0; | 531 return result.bytesConsumed()>0 || result.bytesProduced()>0; |
| 532 } | 532 } |
| 533 | 533 |
| 534 | 534 |
| 535 private ByteBuffer extractByteBuffer(Buffer buffer) | 535 private ByteBuffer extractByteBuffer(JBuffer buffer) |
| 536 { | 536 { |
| 537 if (buffer.buffer() instanceof NIOBuffer) | 537 return buffer.getByteBuffer(); |
| 538 return ((NIOBuffer)buffer.buffer()).getByteBuffer(); | |
| 539 return ByteBuffer.wrap(buffer.array()); | |
| 540 } | 538 } |
| 541 | 539 |
| 542 public SslEndPoint getSslEndPoint() | 540 public SslEndPoint getSslEndPoint() |
| 543 { | 541 { |
| 544 return _sslEndPoint; | 542 return _sslEndPoint; |
| 602 { | 600 { |
| 603 _logger.debug("{} ssl endp.close",_session); | 601 _logger.debug("{} ssl endp.close",_session); |
| 604 _endp.close(); | 602 _endp.close(); |
| 605 } | 603 } |
| 606 | 604 |
| 607 public int fill(Buffer buffer) throws IOException | 605 public int fill(JBuffer buffer) throws IOException |
| 608 { | 606 { |
| 609 int size=buffer.remaining(); | 607 int size=buffer.remaining(); |
| 610 process(buffer, null); | 608 process(buffer, null); |
| 611 | 609 |
| 612 int filled=buffer.remaining()-size; | 610 int filled=buffer.remaining()-size; |
| 614 if (filled==0 && isInputShutdown()) | 612 if (filled==0 && isInputShutdown()) |
| 615 return -1; | 613 return -1; |
| 616 return filled; | 614 return filled; |
| 617 } | 615 } |
| 618 | 616 |
| 619 public int flush(Buffer buffer) throws IOException | 617 public int flush(JBuffer buffer) throws IOException |
| 620 { | 618 { |
| 621 int size = buffer.remaining(); | 619 int size = buffer.remaining(); |
| 622 process(null, buffer); | 620 process(null, buffer); |
| 623 return size-buffer.remaining(); | 621 return size-buffer.remaining(); |
| 624 } | 622 } |
| 625 | 623 |
| 626 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException | 624 public int flush(JBuffer header, JBuffer buffer, JBuffer trailer) throws IOException |
| 627 { | 625 { |
| 628 if (header!=null && header.hasRemaining()) | 626 if (header!=null && header.hasRemaining()) |
| 629 return flush(header); | 627 return flush(header); |
| 630 if (buffer!=null && buffer.hasRemaining()) | 628 if (buffer!=null && buffer.hasRemaining()) |
| 631 return flush(buffer); | 629 return flush(buffer); |
| 733 public String toString() | 731 public String toString() |
| 734 { | 732 { |
| 735 // Do NOT use synchronized (SslConnection.this) | 733 // Do NOT use synchronized (SslConnection.this) |
| 736 // because it's very easy to deadlock when debugging is enabled. | 734 // because it's very easy to deadlock when debugging is enabled. |
| 737 // We do a best effort to print the right toString() and that's it. | 735 // We do a best effort to print the right toString() and that's it. |
| 738 Buffer inbound = _inbound; | 736 JBuffer inbound = _inbound; |
| 739 Buffer outbound = _outbound; | 737 JBuffer outbound = _outbound; |
| 740 Buffer unwrap = _unwrapBuf; | 738 JBuffer unwrap = _unwrapBuf; |
| 741 int i = inbound == null? -1 : inbound.remaining(); | 739 int i = inbound == null? -1 : inbound.remaining(); |
| 742 int o = outbound == null ? -1 : outbound.remaining(); | 740 int o = outbound == null ? -1 : outbound.remaining(); |
| 743 int u = unwrap == null ? -1 : unwrap.remaining(); | 741 int u = unwrap == null ? -1 : unwrap.remaining(); |
| 744 return String.format("SSL %s i/o/u=%d/%d/%d ishut=%b oshut=%b {%s}", | 742 return String.format("SSL %s i/o/u=%d/%d/%d ishut=%b oshut=%b {%s}", |
| 745 _engine.getHandshakeStatus(), | 743 _engine.getHandshakeStatus(), |
