From ed0718674ed11ebefd29a326f89b151257cb7f22 Mon Sep 17 00:00:00 2001 From: Jamie Doornbos Date: Thu, 30 Oct 2008 17:15:42 +0000 Subject: [PATCH] Fixed bug with long running clients. The results for invocation requests with ids exceeding Short.MAX_VALUE could not be processed due to the id being deserialized as a short but stored in the map with an integer key. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5483 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/client/InvocationDirector.as | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/as/com/threerings/presents/client/InvocationDirector.as b/src/as/com/threerings/presents/client/InvocationDirector.as index 26445cd43..40db296f0 100644 --- a/src/as/com/threerings/presents/client/InvocationDirector.as +++ b/src/as/com/threerings/presents/client/InvocationDirector.as @@ -27,6 +27,7 @@ import flash.utils.getTimer; // function import import com.threerings.util.Boxed; import com.threerings.util.HashMap; import com.threerings.util.Log; +import com.threerings.util.Short; import com.threerings.presents.data.InvocationMarshaller_ListenerMarshaller; @@ -340,11 +341,22 @@ public class InvocationDirector } /** - * Used to generate monotonically increasing invocation request ids. + * Used to generate (almost) monotonically increasing invocation request ids. The ids wrap + * around to Short.MIN_VALUE after Short.MAX_VALUE is reached. */ protected function nextRequestId () :int { - return _requestId++; + // post increment with wraparound - this is necessary because the request id is + // serialized as a java short in all instances. since action script does not appear + // to support sign extension, wraparound in the integer domain explicitly. This will + // make the values in our _listeners map reliable. Cleverer ways to wrapround may exist. + var current :int = _requestId; + if (_requestId == Short.MAX_VALUE) { // x7fff + _requestId = -Short.MIN_VALUE; // x8000 + } else { + _requestId++; + } + return current; } /**