summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/Connection.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/IceInternal/Connection.java')
-rw-r--r--java/src/IceInternal/Connection.java148
1 files changed, 23 insertions, 125 deletions
diff --git a/java/src/IceInternal/Connection.java b/java/src/IceInternal/Connection.java
index e761caaf906..35ae3e5ce69 100644
--- a/java/src/IceInternal/Connection.java
+++ b/java/src/IceInternal/Connection.java
@@ -158,14 +158,8 @@ public final class Connection extends EventHandler
// respect to connection validation.
//
BasicStream os = new BasicStream(_instance);
- os.writeByte((byte)0x49); // 'I'
- os.writeByte((byte)0x63); // 'c'
- os.writeByte((byte)0x65); // 'e'
- os.writeByte((byte)0x50); // 'P'
- os.writeByte(Protocol.protocolMajor);
- os.writeByte(Protocol.protocolMinor);
- os.writeByte(Protocol.encodingMajor);
- os.writeByte(Protocol.encodingMinor);
+ os.writeByte(Protocol.protocolVersion);
+ os.writeByte(Protocol.encodingVersion);
os.writeByte(Protocol.validateConnectionMsg);
os.writeInt(Protocol.headerSize); // Message size.
TraceUtil.traceHeader("sending validate connection", os, _logger, _traceLevels);
@@ -184,60 +178,16 @@ public final class Connection extends EventHandler
int pos = is.pos();
assert(pos >= Protocol.headerSize);
is.pos(0);
- byte[] magic = new byte[4];
- magic[0] = is.readByte();
- magic[1] = is.readByte();
- magic[2] = is.readByte();
- magic[3] = is.readByte();
- if(magic[0] != 0x49 || magic[1] != 0x63 || magic[2] != 0x65 || magic[3] != 0x50)
+ byte protVer = is.readByte();
+ if(protVer != Protocol.protocolVersion)
{
- Ice.BadMagicException ex = new Ice.BadMagicException();
- ex.badMagic = magic;
- throw ex;
+ throw new Ice.UnsupportedProtocolException();
}
- byte pMajor = is.readByte();
- byte pMinor = is.readByte();
-
- //
- // We only check the major version number here. The minor version
- // number is irrelevant -- no matter what minor version number is offered
- // by the server, we can be certain that the server supports at least minor version 0.
- // As the client, we are obliged to never produce a message with a minor
- // version number that is larger than what the server can understand, but we don't
- // care if the server understands more than we do.
- //
- // Note: Once we add minor versions, we need to modify the client side to never produce
- // a message with a minor number that is greater than what the server can handle. Similarly,
- // the server side will have to be modified so it never replies with a minor version that is
- // greater than what the client can handle.
- //
- if(pMajor != Protocol.protocolMajor)
- {
- Ice.UnsupportedProtocolException e = new Ice.UnsupportedProtocolException();
- e.badMajor = pMajor < 0 ? pMajor + 255 : pMajor;
- e.badMinor = pMinor < 0 ? pMinor + 255 : pMinor;
- e.major = Protocol.protocolMajor;
- e.minor = Protocol.protocolMinor;
- throw e;
- }
-
- byte eMajor = is.readByte();
- byte eMinor = is.readByte();
-
- //
- // The same applies here as above -- only the major version number
- // of the encoding is relevant.
- //
- if(eMajor != Protocol.encodingMajor)
+ byte encVer = is.readByte();
+ if(encVer != Protocol.encodingVersion)
{
- Ice.UnsupportedEncodingException e = new Ice.UnsupportedEncodingException();
- e.badMajor = eMajor < 0 ? eMajor + 255 : eMajor;
- e.badMinor = eMinor < 0 ? eMinor + 255 : eMinor;
- e.major = Protocol.encodingMajor;
- e.minor = Protocol.encodingMinor;
- throw e;
+ throw new Ice.UnsupportedEncodingException();
}
-
byte messageType = is.readByte();
if(messageType != Protocol.validateConnectionMsg)
{
@@ -313,11 +263,8 @@ public final class Connection extends EventHandler
private final static byte[] _requestHdr =
{
- (byte)0x49, (byte)0x63, (byte)0x65, (byte)0x50, // 'I', 'c', 'e', 'P'
- Protocol.protocolMajor,
- Protocol.protocolMinor,
- Protocol.encodingMajor,
- Protocol.encodingMinor,
+ Protocol.protocolVersion,
+ Protocol.encodingVersion,
Protocol.requestMsg,
(byte)0, (byte)0, (byte)0, (byte)0, // Message size (placeholder).
(byte)0, (byte)0, (byte)0, (byte)0 // Request ID (placeholder).
@@ -343,7 +290,7 @@ public final class Connection extends EventHandler
try
{
BasicStream os = out.os();
- os.pos(9);
+ os.pos(3);
//
// Fill in the message size and request ID.
@@ -402,7 +349,7 @@ public final class Connection extends EventHandler
try
{
BasicStream os = out.__os();
- os.pos(9);
+ os.pos(3);
//
// Fill in the message size and request ID.
@@ -442,11 +389,8 @@ public final class Connection extends EventHandler
private final static byte[] _requestBatchHdr =
{
- (byte)0x49, (byte)0x63, (byte)0x65, (byte)0x50, // 'I', 'c', 'e', 'P'
- Protocol.protocolMajor,
- Protocol.protocolMinor,
- Protocol.encodingMajor,
- Protocol.encodingMinor,
+ Protocol.protocolVersion,
+ Protocol.encodingVersion,
Protocol.requestBatchMsg,
(byte)0, (byte)0, (byte)0, (byte)0, // Message size (placeholder).
(byte)0, (byte)0, (byte)0, (byte)0 // Number of requests in batch (placeholder).
@@ -554,7 +498,7 @@ public final class Connection extends EventHandler
try
{
- _batchStream.pos(9);
+ _batchStream.pos(3);
//
// Fill in the message size.
@@ -610,7 +554,7 @@ public final class Connection extends EventHandler
//
// Fill in the message size.
//
- os.pos(9);
+ os.pos(3);
final int sz = os.size();
os.writeInt(sz);
@@ -742,11 +686,8 @@ public final class Connection extends EventHandler
private final static byte[] _replyHdr =
{
- (byte)0x49, (byte)0x63, (byte)0x65, (byte)0x50, // 'I', 'c', 'e', 'P'
- Protocol.protocolMajor,
- Protocol.protocolMinor,
- Protocol.encodingMajor,
- Protocol.encodingMinor,
+ Protocol.protocolVersion,
+ Protocol.encodingVersion,
Protocol.replyMsg,
(byte)0, (byte)0, (byte)0, (byte)0 // Message size (placeholder).
};
@@ -777,44 +718,7 @@ public final class Connection extends EventHandler
try
{
assert(stream.pos() == stream.size());
- stream.pos(0);
-
- byte[] magic = new byte[4];
- magic[0] = stream.readByte();
- magic[1] = stream.readByte();
- magic[2] = stream.readByte();
- magic[3] = stream.readByte();
- if(magic[0] != 0x49 || magic[1] != 0x63 || magic[2] != 0x65 || magic[3] != 0x50)
- {
- Ice.BadMagicException ex = new Ice.BadMagicException();
- ex.badMagic = magic;
- throw ex;
- }
-
- byte pMajor = stream.readByte();
- byte pMinor = stream.readByte();
- if(pMajor != Protocol.protocolMajor || pMinor > Protocol.protocolMinor)
- {
- Ice.UnsupportedProtocolException e = new Ice.UnsupportedProtocolException();
- e.badMajor = pMajor < 0 ? pMajor + 255 : pMajor;
- e.badMinor = pMinor < 0 ? pMinor + 255 : pMinor;
- e.major = Protocol.protocolMajor;
- e.minor = Protocol.protocolMinor;
- throw e;
- }
-
- byte eMajor = stream.readByte();
- byte eMinor = stream.readByte();
- if(eMajor != Protocol.encodingMajor || eMinor > Protocol.encodingMinor)
- {
- Ice.UnsupportedEncodingException e = new Ice.UnsupportedEncodingException();
- e.badMajor = eMajor < 0 ? eMajor + 255 : eMajor;
- e.badMinor = eMinor < 0 ? eMinor + 255 : eMinor;
- e.major = Protocol.encodingMajor;
- e.minor = Protocol.encodingMinor;
- throw e;
- }
-
+ stream.pos(2);
byte messageType = stream.readByte();
stream.pos(Protocol.headerSize);
@@ -1052,8 +956,8 @@ public final class Connection extends EventHandler
_transceiver = transceiver;
_endpoint = endpoint;
_adapter = adapter;
- _logger = instance.logger(); // Cached for better performance.
- _traceLevels = instance.traceLevels(); // Cached for better performance.
+ _logger = instance.logger(); // Chached for better performance.
+ _traceLevels = instance.traceLevels(); // Chached for better performance.
_registeredWithPool = false;
_warn = false;
_acmTimeout = 0;
@@ -1268,14 +1172,8 @@ public final class Connection extends EventHandler
// message.
//
BasicStream os = new BasicStream(_instance);
- os.writeByte((byte)0x49); // 'I'
- os.writeByte((byte)0x63); // 'c'
- os.writeByte((byte)0x65); // 'e'
- os.writeByte((byte)0x50); // 'P'
- os.writeByte(Protocol.protocolMajor);
- os.writeByte(Protocol.protocolMinor);
- os.writeByte(Protocol.encodingMajor);
- os.writeByte(Protocol.encodingMinor);
+ os.writeByte(Protocol.protocolVersion);
+ os.writeByte(Protocol.encodingVersion);
os.writeByte(Protocol.closeConnectionMsg);
os.writeInt(Protocol.headerSize); // Message size.
_transceiver.write(os, _endpoint.timeout());