diff options
Diffstat (limited to 'java/src')
7 files changed, 61 insertions, 59 deletions
diff --git a/java/src/Ice/src/main/java/Ice/ConnectionI.java b/java/src/Ice/src/main/java/Ice/ConnectionI.java index 57ec2b58b49..5a12142973e 100644 --- a/java/src/Ice/src/main/java/Ice/ConnectionI.java +++ b/java/src/Ice/src/main/java/Ice/ConnectionI.java @@ -2607,9 +2607,9 @@ public final class ConnectionI extends IceInternal.EventHandler case IceInternal.Protocol.replyMsg: { - IceInternal.TraceUtil.traceRecv(info.stream, _logger, _traceLevels); info.requestId = info.stream.readInt(); + IceInternal.OutgoingAsync outAsync = _asyncRequests.remove(info.requestId); if(outAsync != null && outAsync.completed(info.stream)) { @@ -2993,6 +2993,7 @@ public final class ConnectionI extends IceInternal.EventHandler s.append(_endpoint.protocol()); s.append("\n"); s.append(toString()); + _instance.initializationData().logger.trace(_instance.traceLevels().networkCat, s.toString()); } return op; diff --git a/java/src/Ice/src/main/java/IceInternal/EndpointHostResolver.java b/java/src/Ice/src/main/java/IceInternal/EndpointHostResolver.java index 896eb21b8a1..e0ea6773d1b 100644 --- a/java/src/Ice/src/main/java/IceInternal/EndpointHostResolver.java +++ b/java/src/Ice/src/main/java/IceInternal/EndpointHostResolver.java @@ -211,7 +211,12 @@ class EndpointHostResolver // Wait for the executor to terminate. try { - _executor.awaitTermination(Long.MAX_VALUE, java.util.concurrent.TimeUnit.NANOSECONDS); + while(!_executor.isTerminated()) + { + // A very long time. + _executor.awaitTermination(100000, java.util.concurrent.TimeUnit.SECONDS); + } + } finally { diff --git a/java/src/Ice/src/main/java/IceInternal/Instance.java b/java/src/Ice/src/main/java/IceInternal/Instance.java index ebe7dd118df..0fa1a9d77bc 100644 --- a/java/src/Ice/src/main/java/IceInternal/Instance.java +++ b/java/src/Ice/src/main/java/IceInternal/Instance.java @@ -129,7 +129,11 @@ public final class Instance throws InterruptedException { shutdown(); - awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + while(!isTerminated()) + { + // A very long time. + awaitTermination(100000, java.util.concurrent.TimeUnit.SECONDS); + } } private final ThreadObserverHelper _observerHelper; @@ -727,6 +731,12 @@ public final class Instance return Util.findClass(className, _initData.classLoader); } + public ClassLoader + getClassLoader() + { + return _initData.classLoader; + } + public synchronized String getClassForType(String type) { @@ -991,7 +1001,9 @@ public final class Instance // // If Ice.ThreadInterruptSafe is set or we're running on Android all - // IO is done on the background thread. + // IO is done on the background thread. For Android we use the queue + // executor as Android doesn't allow any network invocations on the main + // thread even if the call is non-blocking. // if(_initData.properties.getPropertyAsInt("Ice.ThreadInterruptSafe") > 0 || Util.isAndroid()) { @@ -1342,7 +1354,11 @@ public final class Instance } if(_timer != null) { - _timer.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + while(!_timer.isTerminated()) + { + // A very long time. + _timer.awaitTermination(100000, java.util.concurrent.TimeUnit.SECONDS); + } } } catch(InterruptedException ex) diff --git a/java/src/Ice/src/main/java/IceInternal/StreamSocket.java b/java/src/Ice/src/main/java/IceInternal/StreamSocket.java index 9ab185a42d5..c0be3b3ba61 100644 --- a/java/src/Ice/src/main/java/IceInternal/StreamSocket.java +++ b/java/src/Ice/src/main/java/IceInternal/StreamSocket.java @@ -11,11 +11,12 @@ package IceInternal; public class StreamSocket { - public StreamSocket(ProtocolInstance instance, + public StreamSocket(ProtocolInstance instance, NetworkProxy proxy, java.net.InetSocketAddress addr, java.net.InetSocketAddress sourceAddr) { + _instance = instance; _proxy = proxy; _addr = addr; _fd = Network.createTcpSocket(); @@ -23,7 +24,7 @@ public class StreamSocket try { - init(instance); + init(); if(Network.doConnect(_fd, _proxy != null ? _proxy.getAddress() : _addr, sourceAddr)) { _state = StateConnected; @@ -41,6 +42,7 @@ public class StreamSocket public StreamSocket(ProtocolInstance instance, java.nio.channels.SocketChannel fd) { + _instance = instance; _proxy = null; _addr = null; _fd = fd; @@ -48,7 +50,7 @@ public class StreamSocket try { - init(instance); + init(); } catch(Exception ex) { @@ -174,11 +176,7 @@ public class StreamSocket assert(_fd != null); int read = 0; - if(_buffer != null && _buffer.hasRemaining()) - { - read = readBuffered(buf); - } - + while(buf.hasRemaining()) { try @@ -192,7 +190,7 @@ public class StreamSocket { return read; } - + read += ret; } catch(java.io.InterruptedIOException ex) @@ -274,10 +272,10 @@ public class StreamSocket return _desc; } - private void init(ProtocolInstance instance) + private void init() { Network.setBlock(_fd, false); - Network.setTcpBufSize(_fd, instance.properties(), instance.logger()); + Network.setTcpBufSize(_fd, _instance.properties(), _instance.logger()); if(System.getProperty("os.name").startsWith("Windows")) { @@ -294,28 +292,6 @@ public class StreamSocket } } - private int readBuffered(java.nio.ByteBuffer buf) - { - assert(_buffer != null); - int length = buf.remaining(); - if(length < _buffer.remaining()) - { - int limit = _buffer.limit(); - _buffer.limit(_buffer.position() + length); - buf.put(_buffer); - _buffer.position(_buffer.limit()); - _buffer.limit(limit); - return length; - } - else - { - int read = _buffer.remaining(); - buf.put(_buffer); - _buffer.clear(); - return read; - } - } - private int toState(int operation) { switch(operation) @@ -329,6 +305,8 @@ public class StreamSocket } } + private final ProtocolInstance _instance; + final private NetworkProxy _proxy; final private java.net.InetSocketAddress _addr; @@ -336,7 +314,6 @@ public class StreamSocket private int _maxSendPacketSize; private int _state; private String _desc; - private java.nio.ByteBuffer _buffer; private static final int StateNeedConnect = 0; private static final int StateConnectPending = 1; diff --git a/java/src/Ice/src/main/java/IceInternal/TraceUtil.java b/java/src/Ice/src/main/java/IceInternal/TraceUtil.java index f3c269aa9d5..6af4c41de3b 100644 --- a/java/src/Ice/src/main/java/IceInternal/TraceUtil.java +++ b/java/src/Ice/src/main/java/IceInternal/TraceUtil.java @@ -303,7 +303,7 @@ public final class TraceUtil try { byte mode = stream.readByte(); - out.write("\nmode = " + (int)mode + ' '); + out.write("\nmode = " + (int) mode + ' '); switch(Ice.OperationMode.values()[mode]) { case Normal: @@ -337,7 +337,7 @@ public final class TraceUtil { String key = stream.readString(); String value = stream.readString(); - out.write(key + '/'+ value); + out.write(key + '/' + value); if(sz > 0) { out.write(", "); diff --git a/java/src/Ice/src/main/java/IceSSL/SSLEngine.java b/java/src/Ice/src/main/java/IceSSL/SSLEngine.java index 5601d3f2312..9e121635fc8 100644 --- a/java/src/Ice/src/main/java/IceSSL/SSLEngine.java +++ b/java/src/Ice/src/main/java/IceSSL/SSLEngine.java @@ -48,7 +48,7 @@ class SSLEngine // Protocols selects which protocols to enable, by default we only enable TLS1.0 // TLS1.1 and TLS1.2 to avoid security issues with SSLv3 // - String[] protocols = + String[] protocols = properties.getPropertyAsListWithDefault(prefix + "Protocols", new String[]{"tls1_0", "tls1_1", "tls1_2"}); if(protocols.length != 0) { diff --git a/java/src/Ice/src/main/java/IceSSL/TransceiverI.java b/java/src/Ice/src/main/java/IceSSL/TransceiverI.java index 937d6cea068..7799dcf2caa 100644 --- a/java/src/Ice/src/main/java/IceSSL/TransceiverI.java +++ b/java/src/Ice/src/main/java/IceSSL/TransceiverI.java @@ -184,14 +184,17 @@ final class TransceiverI implements IceInternal.Transceiver _netInput.flip(); SSLEngineResult result = _engine.unwrap(_netInput, _appInput); _netInput.compact(); - switch(result.getStatus()) - { - case BUFFER_OVERFLOW: + + Status status = result.getStatus(); + assert status != Status.BUFFER_OVERFLOW; + + if(status == Status.CLOSED) { - assert(false); - break; + throw new Ice.ConnectionLostException(); } - case BUFFER_UNDERFLOW: + // Android API 21 SSLEngine doesn't report underflow, so look at the absence of + // network data and application data to signal a network read. + else if(status == Status.BUFFER_UNDERFLOW || (_appInput.position() == 0 && _netInput.position() == 0)) { if(_stream.read(_netInput) == 0) { @@ -199,15 +202,6 @@ final class TransceiverI implements IceInternal.Transceiver } continue; } - case CLOSED: - { - throw new Ice.ConnectionLostException(); - } - case OK: - { - break; - } - } fill(buf.b); } @@ -220,7 +214,8 @@ final class TransceiverI implements IceInternal.Transceiver // // Return a boolean to indicate whether more data is available. // - moreData.value = _netInput.position() > 0; + moreData.value = _netInput.position() > 0 || _appInput.position() > 0; + return IceInternal.SocketOperation.None; } @@ -325,7 +320,7 @@ final class TransceiverI implements IceInternal.Transceiver try { HandshakeStatus status = _engine.getHandshakeStatus(); - while(true) + while(!_engine.isOutboundDone() && !_engine.isInboundDone()) { SSLEngineResult result = null; switch(status) @@ -347,6 +342,11 @@ final class TransceiverI implements IceInternal.Transceiver } case NEED_UNWRAP: { + if(_netInput.position() == 0 && _stream.read(_netInput) == 0) + { + return IceInternal.SocketOperation.Read; + } + // // The engine needs more data. We might already have enough data in // the _netInput buffer to satisfy the engine. If not, the engine @@ -396,6 +396,7 @@ final class TransceiverI implements IceInternal.Transceiver { return IceInternal.SocketOperation.Write; } + // // FINISHED is only returned from wrap or unwrap, not from engine.getHandshakeResult(). // @@ -427,6 +428,7 @@ final class TransceiverI implements IceInternal.Transceiver { throw new Ice.SecurityException("IceSSL: handshake error", ex); } + return IceInternal.SocketOperation.None; } private int writeNonBlocking(ByteBuffer buf) @@ -445,6 +447,7 @@ final class TransceiverI implements IceInternal.Transceiver // // Encrypt the buffer. // + int position = _netOutput.position(); SSLEngineResult result = _engine.wrap(buf, _netOutput); switch(result.getStatus()) { |