From bf124728b994b7937aa3eb7697000db49f0c2faf Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 3 Feb 2025 22:05:57 -0800 Subject: [PATCH] Eagerly disable reference mode when writing stubs and skeletons. --- src/main/java/org/cojen/dirmi/core/BufferedPipe.java | 11 +++++++++++ src/main/java/org/cojen/dirmi/core/CorePipe.java | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/org/cojen/dirmi/core/BufferedPipe.java b/src/main/java/org/cojen/dirmi/core/BufferedPipe.java index a70093a5..6eb8b913 100644 --- a/src/main/java/org/cojen/dirmi/core/BufferedPipe.java +++ b/src/main/java/org/cojen/dirmi/core/BufferedPipe.java @@ -2383,6 +2383,17 @@ private boolean tryWriteReference(ReferenceMap refMap, Object v) throws IOExcept } } + /** + * If necessary, writes T_REF_MODE_OFF before writing an object. + */ + protected void refModeOffIfDisabled() throws IOException { + ReferenceMap refMap = mOutRefMap; + if (refMap != null && refMap.isDisabled()) { + write(T_REF_MODE_OFF); + mOutRefMap = null; + } + } + @Override public final SocketAddress localAddress() { return mLocalAddress; diff --git a/src/main/java/org/cojen/dirmi/core/CorePipe.java b/src/main/java/org/cojen/dirmi/core/CorePipe.java index 4b9cd1ca..39528f92 100644 --- a/src/main/java/org/cojen/dirmi/core/CorePipe.java +++ b/src/main/java/org/cojen/dirmi/core/CorePipe.java @@ -89,6 +89,7 @@ Class loadClass(String name) throws ClassNotFoundException { @Override void writeStub(Stub stub) throws IOException { + refModeOffIfDisabled(); requireOutput(9); int end = mOutEnd; byte[] buf = mOutBuffer; @@ -106,6 +107,7 @@ void writeSkeleton(Object server) throws IOException { * @param typeCode T_REMOTE_T or T_REMOTE_TI */ void writeSkeletonHeader(byte typeCode, Skeleton skeleton) throws IOException { + refModeOffIfDisabled(); requireOutput(17); int end = mOutEnd; byte[] buf = mOutBuffer;