Skip to content

Commit f31f323

Browse files
committed
[refactor] share empty read-only byte-buffer
1 parent 5f09ae8 commit f31f323

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/java/org/jruby/ext/openssl/SSLSocket.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,15 @@ private static CallSite callSite(final CallSite[] sites, final CallSiteIndex ind
141141
return sites[ index.ordinal() ];
142142
}
143143

144+
private static final ByteBuffer EMPTY_DATA = ByteBuffer.allocate(0).asReadOnlyBuffer();
145+
144146
SSLContext sslContext;
145147
private SSLEngine engine;
146148
private RubyIO io;
147149

148150
ByteBuffer appReadData;
149151
ByteBuffer netReadData;
150152
ByteBuffer netWriteData;
151-
private final ByteBuffer dummy = ByteBuffer.allocate(0); // could be static
152153

153154
private boolean initialHandshake = false;
154155
private transient long initializeTime;
@@ -610,7 +611,7 @@ private IRubyObject doHandshake(final boolean blocking, final boolean exception)
610611

611612
private void doWrap(final boolean blocking) throws IOException {
612613
netWriteData.clear();
613-
SSLEngineResult result = engine.wrap(dummy, netWriteData);
614+
SSLEngineResult result = engine.wrap(EMPTY_DATA.duplicate(), netWriteData);
614615
netWriteData.flip();
615616
handshakeStatus = result.getHandshakeStatus();
616617
status = result.getStatus();
@@ -794,7 +795,7 @@ private void doShutdown() throws IOException {
794795
}
795796
netWriteData.clear();
796797
try {
797-
engine.wrap(dummy, netWriteData); // send close (after sslEngine.closeOutbound)
798+
engine.wrap(EMPTY_DATA.duplicate(), netWriteData); // send close (after sslEngine.closeOutbound)
798799
}
799800
catch (SSLException e) {
800801
debug(getRuntime(), "SSLSocket.doShutdown", e);

0 commit comments

Comments
 (0)