diff options
author | Mark Spruiell <mes@zeroc.com> | 2014-06-13 10:06:29 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2014-06-13 10:06:29 -0700 |
commit | 69c46db2fb9f03a4b730f8da1bd6e03d4ba68895 (patch) | |
tree | a755e1e123ac50a31729e51ebb375a92e86f1303 /java | |
parent | SSL Cipher test fix for OpenSSL (diff) | |
download | ice-69c46db2fb9f03a4b730f8da1bd6e03d4ba68895.tar.bz2 ice-69c46db2fb9f03a4b730f8da1bd6e03d4ba68895.tar.xz ice-69c46db2fb9f03a4b730f8da1bd6e03d4ba68895.zip |
initial commit of C# transport changes
Diffstat (limited to 'java')
-rw-r--r-- | java/src/Ice/ConnectionI.java | 2 | ||||
-rw-r--r-- | java/src/IceInternal/IPEndpointI.java | 1 | ||||
-rw-r--r-- | java/src/IceInternal/OutgoingConnectionFactory.java | 16 | ||||
-rw-r--r-- | java/src/IceInternal/TcpAcceptor.java | 54 | ||||
-rw-r--r-- | java/src/IceInternal/UdpConnector.java | 2 | ||||
-rw-r--r-- | java/src/IceInternal/UdpTransceiver.java | 10 | ||||
-rw-r--r-- | java/test/Ice/background/AllTests.java | 54 | ||||
-rw-r--r-- | java/test/Ice/background/BackgroundControllerI.java | 6 | ||||
-rw-r--r-- | java/test/Ice/background/Test.ice | 8 | ||||
-rw-r--r-- | java/test/Ice/background/Transceiver.java | 9 |
10 files changed, 108 insertions, 54 deletions
diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index fb2c0ce8a33..a39905470ac 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -2348,7 +2348,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne { return IceInternal.SocketOperation.None; } - else if(_state == StateClosingPending && _writeStream.pos() == _writeStream.size()) + else if(_state == StateClosingPending && _writeStream.pos() == 0) { // Message wasn't sent, empty the _writeStream, we're not going to send more data. OutgoingMessage message = _sendStreams.getFirst(); diff --git a/java/src/IceInternal/IPEndpointI.java b/java/src/IceInternal/IPEndpointI.java index 7c860106754..e887fb95770 100644 --- a/java/src/IceInternal/IPEndpointI.java +++ b/java/src/IceInternal/IPEndpointI.java @@ -151,6 +151,7 @@ public abstract class IPEndpointI extends EndpointI _hashValue = 5381; _hashValue = HashUtil.hashAdd(_hashValue, type()); _hashValue = hashInit(_hashValue); + _hashInitialized = true; } return _hashValue; } diff --git a/java/src/IceInternal/OutgoingConnectionFactory.java b/java/src/IceInternal/OutgoingConnectionFactory.java index 53a1abbfc90..f9e5a50b57a 100644 --- a/java/src/IceInternal/OutgoingConnectionFactory.java +++ b/java/src/IceInternal/OutgoingConnectionFactory.java @@ -28,20 +28,6 @@ public final class OutgoingConnectionFactory list.add(value); } - /* - public void - removeElementWithValue(K key, V value) - { - java.util.List<V> list = this.get(key); - assert(list != null); - list.remove(value); - if(list.isEmpty()) - { - this.remove(key); - } - } - */ - public boolean removeElementWithValue(K key, V value) { @@ -54,7 +40,7 @@ public final class OutgoingConnectionFactory } return v; } - }; + } interface CreateConnectionCallback { diff --git a/java/src/IceInternal/TcpAcceptor.java b/java/src/IceInternal/TcpAcceptor.java index d8f35bb625a..ef20c146dac 100644 --- a/java/src/IceInternal/TcpAcceptor.java +++ b/java/src/IceInternal/TcpAcceptor.java @@ -11,18 +11,16 @@ package IceInternal; class TcpAcceptor implements Acceptor { - public java.nio.channels.ServerSocketChannel - fd() + public java.nio.channels.ServerSocketChannel fd() { return _fd; } - public void - close() + public void close() { if(_instance.traceLevel() >= 1) { - String s = "stopping to accept tcp connections at " + toString(); + String s = "stopping to accept " + protocol() + " connections at " + toString(); _instance.logger().trace(_instance.traceCategory(), s); } @@ -31,17 +29,16 @@ class TcpAcceptor implements Acceptor _fd = null; } - public void - listen() + public void listen() { // Nothing to do. if(_instance.traceLevel() >= 1) { - StringBuffer s = new StringBuffer("listening for tcp connections at "); + StringBuffer s = new StringBuffer("listening for " + protocol() + " connections at "); s.append(toString()); - java.util.List<String> interfaces = + java.util.List<String> interfaces = Network.getHostsForEndpointExpand(_addr.getAddress().getHostAddress(), _instance.protocolSupport(), true); if(!interfaces.isEmpty()) @@ -53,8 +50,7 @@ class TcpAcceptor implements Acceptor } } - public Transceiver - accept() + public Transceiver accept() { java.nio.channels.SocketChannel fd = Network.doAccept(_fd); Network.setBlock(fd, false); @@ -62,27 +58,24 @@ class TcpAcceptor implements Acceptor if(_instance.traceLevel() >= 1) { - String s = "accepted tcp connection\n" + Network.fdToString(fd); + String s = "accepted " + protocol() + " connection\n" + Network.fdToString(fd); _instance.logger().trace(_instance.traceCategory(), s); } return new TcpTransceiver(_instance, fd); } - public String - protocol() + public String protocol() { return _instance.protocol(); } - public String - toString() + public String toString() { return Network.addrToString(_addr); } - int - effectivePort() + int effectivePort() { return _addr.getPort(); } @@ -100,24 +93,24 @@ class TcpAcceptor implements Acceptor if(!System.getProperty("os.name").startsWith("Windows")) { // - // Enable SO_REUSEADDR on Unix platforms to allow - // re-using the socket even if it's in the TIME_WAIT - // state. On Windows, this doesn't appear to be - // necessary and enabling SO_REUSEADDR would actually - // not be a good thing since it allows a second - // process to bind to an address even it's already - // bound by another process. + // Enable SO_REUSEADDR on Unix platforms to allow re-using the + // socket even if it's in the TIME_WAIT state. On Windows, + // this doesn't appear to be necessary and enabling + // SO_REUSEADDR would actually not be a good thing since it + // allows a second process to bind to an address even it's + // already bound by another process. // - // TODO: using SO_EXCLUSIVEADDRUSE on Windows would - // probably be better but it's only supported by recent - // Windows versions (XP SP2, Windows Server 2003). + // TODO: using SO_EXCLUSIVEADDRUSE on Windows would probably + // be better but it's only supported by recent Windows + // versions (XP SP2, Windows Server 2003). // Network.setReuseAddress(_fd, true); } + _addr = Network.getAddressForServer(host, port, instance.protocolSupport(), instance.preferIPv6()); if(instance.traceLevel() >= 2) { - String s = "attempting to bind to tcp socket " + toString(); + String s = "attempting to bind to " + protocol() + " socket " + toString(); instance.logger().trace(instance.traceCategory(), s); } _addr = Network.doBind(_fd, _addr, _backlog); @@ -129,8 +122,7 @@ class TcpAcceptor implements Acceptor } } - protected synchronized void - finalize() + protected synchronized void finalize() throws Throwable { try diff --git a/java/src/IceInternal/UdpConnector.java b/java/src/IceInternal/UdpConnector.java index 054014efc2c..94ddf2d14cd 100644 --- a/java/src/IceInternal/UdpConnector.java +++ b/java/src/IceInternal/UdpConnector.java @@ -38,7 +38,7 @@ final class UdpConnector implements Connector } // - // Only for use by TcpEndpoint + // Only for use by UdpEndpointI // UdpConnector(ProtocolInstance instance, java.net.InetSocketAddress addr, String mcastInterface, int mcastTtl, String connectionId) diff --git a/java/src/IceInternal/UdpTransceiver.java b/java/src/IceInternal/UdpTransceiver.java index 15f1683cf4e..d8344adb130 100644 --- a/java/src/IceInternal/UdpTransceiver.java +++ b/java/src/IceInternal/UdpTransceiver.java @@ -66,6 +66,11 @@ final class UdpTransceiver implements Transceiver return SocketOperation.Write; } + if(!buf.b.hasRemaining()) + { + return SocketOperation.None; + } + assert(buf.b.position() == 0); assert(_fd != null && _state >= StateConnected); @@ -127,6 +132,11 @@ final class UdpTransceiver implements Transceiver @SuppressWarnings("deprecation") public int read(Buffer buf, Ice.BooleanHolder moreData) { + if(!buf.b.hasRemaining()) + { + return SocketOperation.None; + } + assert(buf.b.position() == 0); final int packetSize = java.lang.Math.min(_maxPacketSize, _rcvSize - _udpOverhead); diff --git a/java/test/Ice/background/AllTests.java b/java/test/Ice/background/AllTests.java index 45bb92f6a05..e029f2a8056 100644 --- a/java/test/Ice/background/AllTests.java +++ b/java/test/Ice/background/AllTests.java @@ -152,6 +152,26 @@ public class AllTests private Callback _sent = new Callback(); } + private static class OpAMICallbackNoOp extends Callback_Background_op + { + @Override + public void response() + { + } + + @Override + public void exception(Ice.LocalException ex) + { + ex.printStackTrace(); + test(false); + } + + @Override + public void sent(boolean ss) + { + } + } + private static class NoResponse extends Callback_Background_opWithPayload { @Override @@ -371,6 +391,40 @@ public class AllTests } out.println("ok"); + final boolean ws = communicator.getProperties().getProperty("Ice.Default.Protocol").equals("test-ws"); + final boolean wss = communicator.getProperties().getProperty("Ice.Default.Protocol").equals("test-wss"); + if(!ws && !wss) + { + out.print("testing buffered transport... "); + out.flush(); + + configuration.buffered(true); + backgroundController.buffered(true); + background.begin_op(); + background.ice_getCachedConnection().close(true); + background.begin_op(); + + Ice.AsyncResult r = null; + OpAMICallbackNoOp cb = new OpAMICallbackNoOp(); + + for(int i = 0; i < 10000; ++i) + { + r = background.begin_op(cb); + if(i % 50 == 0) + { + backgroundController.holdAdapter(); + backgroundController.resumeAdapter(); + } + if(i % 100 == 0) + { + r.waitForCompleted(); + } + } + r.waitForCompleted(); + + out.println("ok"); + } + return background; } diff --git a/java/test/Ice/background/BackgroundControllerI.java b/java/test/Ice/background/BackgroundControllerI.java index 594a623d131..64cefee73ca 100644 --- a/java/test/Ice/background/BackgroundControllerI.java +++ b/java/test/Ice/background/BackgroundControllerI.java @@ -88,6 +88,12 @@ class BackgroundControllerI extends _BackgroundControllerDisp { _configuration.writeException(enable ? new Ice.SocketException() : null); } + + public void + buffered(boolean enable, Ice.Current current) + { + _configuration.buffered(enable); + } public BackgroundControllerI(Configuration configuration, Ice.ObjectAdapter adapter) diff --git a/java/test/Ice/background/Test.ice b/java/test/Ice/background/Test.ice index 95d72cb42b6..b612eb4d280 100644 --- a/java/test/Ice/background/Test.ice +++ b/java/test/Ice/background/Test.ice @@ -18,8 +18,8 @@ module Test interface Background { - ["ami"] void op(); - ["ami"] void opWithPayload(Ice::ByteSeq seq); + void op(); + void opWithPayload(Ice::ByteSeq seq); void shutdown(); }; @@ -28,7 +28,7 @@ interface BackgroundController { void pauseCall(string call); void resumeCall(string call); - + void holdAdapter(); void resumeAdapter(); @@ -40,6 +40,8 @@ interface BackgroundController void writeReady(bool enable); void writeException(bool enable); + + void buffered(bool enable); }; }; diff --git a/java/test/Ice/background/Transceiver.java b/java/test/Ice/background/Transceiver.java index 36a0b85a6d2..a16eb335cfe 100644 --- a/java/test/Ice/background/Transceiver.java +++ b/java/test/Ice/background/Transceiver.java @@ -105,9 +105,10 @@ final class Transceiver implements IceInternal.Transceiver return IceInternal.SocketOperation.Read; } } - assert(_readBuffer.b.position() > _readBufferPos); - int requested = buf.b.remaining(); - int available = _readBuffer.b.position() - _readBufferPos; + final int pos = _readBuffer.b.position(); + assert(pos > _readBufferPos); + final int requested = buf.b.remaining(); + int available = pos - _readBufferPos; assert(available > 0); if(available >= requested) { @@ -115,9 +116,11 @@ final class Transceiver implements IceInternal.Transceiver } byte[] arr = new byte[available]; + _readBuffer.b.position(_readBufferPos); _readBuffer.b.get(arr); buf.b.put(arr); _readBufferPos += available; + _readBuffer.b.position(pos); } moreData.value = _readBufferPos < _readBuffer.b.position(); return IceInternal.SocketOperation.None; |