Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/nio/SslConnection.java @ 1062:4a50422596b6
fix JBuffer.getByteBuffer()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 02:04:02 -0700 |
parents | 4afdf0f0c5bc |
children | 158d1e6ac17f |
comparison
equal
deleted
inserted
replaced
1061:c880589715c7 | 1062:4a50422596b6 |
---|---|
122 { | 122 { |
123 _buffers=__buffers.get(); | 123 _buffers=__buffers.get(); |
124 if (_buffers==null) | 124 if (_buffers==null) |
125 _buffers=new SslBuffers(_session.getPacketBufferSize()*2,_session.getApplicationBufferSize()*2); | 125 _buffers=new SslBuffers(_session.getPacketBufferSize()*2,_session.getApplicationBufferSize()*2); |
126 _inbound=_buffers._in; | 126 _inbound=_buffers._in; |
127 _outbound=_buffers._out; | 127 _outbound = _buffers._out; |
128 _unwrapBuf=_buffers._unwrap; | 128 _unwrapBuf=_buffers._unwrap; |
129 __buffers.set(null); | 129 __buffers.set(null); |
130 } | 130 } |
131 } | 131 } |
132 } | 132 } |
142 _inbound.remaining()==0 && | 142 _inbound.remaining()==0 && |
143 _outbound.remaining()==0 && | 143 _outbound.remaining()==0 && |
144 _unwrapBuf.remaining()==0) | 144 _unwrapBuf.remaining()==0) |
145 { | 145 { |
146 _inbound=null; | 146 _inbound=null; |
147 _outbound=null; | 147 _outbound = null; |
148 _unwrapBuf=null; | 148 _unwrapBuf=null; |
149 __buffers.set(_buffers); | 149 __buffers.set(_buffers); |
150 _buffers=null; | 150 _buffers=null; |
151 } | 151 } |
152 } | 152 } |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 private synchronized boolean wrap(final JBuffer buffer) throws IOException | 379 private synchronized boolean wrap(final JBuffer buffer) throws IOException |
380 { | 380 { |
381 ByteBuffer bbuf=extractByteBuffer(buffer); | 381 ByteBuffer bbuf = buffer.getByteBuffer(); |
382 final SSLEngineResult result; | 382 final SSLEngineResult result; |
383 | 383 |
384 synchronized(bbuf) | 384 synchronized(bbuf) |
385 { | 385 { |
386 _outbound.compact(); | 386 _outbound.compact(); |
387 ByteBuffer out_buffer=_outbound.getByteBuffer(); | 387 ByteBuffer out_buffer = _outbound.getByteBuffer().duplicate(); |
388 synchronized(out_buffer) | 388 synchronized(out_buffer) |
389 { | 389 { |
390 try | 390 try |
391 { | 391 { |
392 bbuf.position(buffer.getIndex()); | 392 out_buffer.position(_outbound.limit()); |
393 bbuf.limit(buffer.putIndex()); | |
394 out_buffer.position(_outbound.putIndex()); | |
395 out_buffer.limit(out_buffer.capacity()); | 393 out_buffer.limit(out_buffer.capacity()); |
396 result=_engine.wrap(bbuf,out_buffer); | 394 result = _engine.wrap(bbuf,out_buffer); |
397 if (_logger.isDebugEnabled()) | 395 if (_logger.isDebugEnabled()) |
398 _logger.debug("{} wrap {} {} consumed={} produced={}", | 396 _logger.debug("{} wrap {} {} consumed={} produced={}", |
399 _session, | 397 _session, |
400 result.getStatus(), | 398 result.getStatus(), |
401 result.getHandshakeStatus(), | 399 result.getHandshakeStatus(), |
402 result.bytesConsumed(), | 400 result.bytesConsumed(), |
403 result.bytesProduced()); | 401 result.bytesProduced()); |
404 | 402 |
405 | 403 _outbound.limit(_outbound.limit()+result.bytesProduced()); |
406 buffer.skip(result.bytesConsumed()); | |
407 _outbound.setPutIndex(_outbound.putIndex()+result.bytesProduced()); | |
408 } | 404 } |
409 catch(SSLException e) | 405 catch(SSLException e) |
410 { | 406 { |
411 _logger.debug(String.valueOf(_endp), e); | 407 _logger.debug(String.valueOf(_endp), e); |
412 _endp.close(); | 408 _endp.close(); |
413 throw e; | 409 throw e; |
414 } | |
415 finally | |
416 { | |
417 out_buffer.position(0); | |
418 out_buffer.limit(out_buffer.capacity()); | |
419 bbuf.position(0); | |
420 bbuf.limit(bbuf.capacity()); | |
421 } | 410 } |
422 } | 411 } |
423 } | 412 } |
424 | 413 |
425 switch(result.getStatus()) | 414 switch(result.getStatus()) |
452 private synchronized boolean unwrap(final JBuffer buffer) throws IOException | 441 private synchronized boolean unwrap(final JBuffer buffer) throws IOException |
453 { | 442 { |
454 if (!_inbound.hasRemaining()) | 443 if (!_inbound.hasRemaining()) |
455 return false; | 444 return false; |
456 | 445 |
457 ByteBuffer bbuf=extractByteBuffer(buffer); | 446 ByteBuffer bbuf = buffer.getByteBuffer().duplicate(); |
458 final SSLEngineResult result; | 447 final SSLEngineResult result; |
459 | 448 |
460 synchronized(bbuf) | 449 synchronized(bbuf) |
461 { | 450 { |
462 ByteBuffer in_buffer=_inbound.getByteBuffer(); | 451 ByteBuffer in_buffer = _inbound.getByteBuffer(); |
463 synchronized(in_buffer) | 452 synchronized(in_buffer) |
464 { | 453 { |
465 try | 454 try |
466 { | 455 { |
467 bbuf.position(buffer.putIndex()); | 456 bbuf.position(buffer.limit()); |
468 bbuf.limit(buffer.capacity()); | 457 bbuf.limit(buffer.capacity()); |
469 in_buffer.position(_inbound.getIndex()); | |
470 in_buffer.limit(_inbound.putIndex()); | |
471 | 458 |
472 result=_engine.unwrap(in_buffer,bbuf); | 459 result=_engine.unwrap(in_buffer,bbuf); |
473 if (_logger.isDebugEnabled()) | 460 if (_logger.isDebugEnabled()) |
474 _logger.debug("{} unwrap {} {} consumed={} produced={}", | 461 _logger.debug("{} unwrap {} {} consumed={} produced={}", |
475 _session, | 462 _session, |
476 result.getStatus(), | 463 result.getStatus(), |
477 result.getHandshakeStatus(), | 464 result.getHandshakeStatus(), |
478 result.bytesConsumed(), | 465 result.bytesConsumed(), |
479 result.bytesProduced()); | 466 result.bytesProduced()); |
480 | 467 |
481 _inbound.skip(result.bytesConsumed()); | |
482 _inbound.compact(); | 468 _inbound.compact(); |
483 buffer.setPutIndex(buffer.putIndex()+result.bytesProduced()); | 469 buffer.limit(buffer.limit()+result.bytesProduced()); |
484 } | 470 } |
485 catch(SSLException e) | 471 catch(SSLException e) |
486 { | 472 { |
487 _logger.debug(String.valueOf(_endp), e); | 473 _logger.debug(String.valueOf(_endp), e); |
488 _endp.close(); | 474 _endp.close(); |
489 throw e; | 475 throw e; |
490 } | |
491 finally | |
492 { | |
493 in_buffer.position(0); | |
494 in_buffer.limit(in_buffer.capacity()); | |
495 bbuf.position(0); | |
496 bbuf.limit(bbuf.capacity()); | |
497 } | 476 } |
498 } | 477 } |
499 } | 478 } |
500 | 479 |
501 switch(result.getStatus()) | 480 switch(result.getStatus()) |
526 | 505 |
527 //if (LOG.isDebugEnabled() && result.bytesProduced()>0) | 506 //if (LOG.isDebugEnabled() && result.bytesProduced()>0) |
528 // LOG.debug("{} unwrapped '{}'",_session,buffer); | 507 // LOG.debug("{} unwrapped '{}'",_session,buffer); |
529 | 508 |
530 return result.bytesConsumed()>0 || result.bytesProduced()>0; | 509 return result.bytesConsumed()>0 || result.bytesProduced()>0; |
531 } | |
532 | |
533 | |
534 private ByteBuffer extractByteBuffer(JBuffer buffer) | |
535 { | |
536 return buffer.getByteBuffer(); | |
537 } | 510 } |
538 | 511 |
539 public SslEndPoint getSslEndPoint() | 512 public SslEndPoint getSslEndPoint() |
540 { | 513 { |
541 return _sslEndPoint; | 514 return _sslEndPoint; |