Skip to content

Commit 1b6be67

Browse files
committed
[refactor] share empty read-only byte-buffer
1 parent 65bd8d5 commit 1b6be67

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
private SSLContext sslContext;
145147
private SSLEngine engine;
146148
private RubyIO io;
147149

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

153154
private boolean initialHandshake = false;
154155
private transient long initializeTime;
@@ -623,7 +624,7 @@ private IRubyObject doHandshake(final boolean blocking, final boolean exception)
623624

624625
private void doWrap(final boolean blocking) throws IOException {
625626
netWriteData.clear();
626-
SSLEngineResult result = engine.wrap(dummy, netWriteData);
627+
SSLEngineResult result = engine.wrap(EMPTY_DATA.duplicate(), netWriteData);
627628
netWriteData.flip();
628629
handshakeStatus = result.getHandshakeStatus();
629630
status = result.getStatus();
@@ -820,7 +821,7 @@ private void doShutdown() throws IOException {
820821
}
821822
netWriteData.clear();
822823
try {
823-
engine.wrap(dummy, netWriteData); // send close (after sslEngine.closeOutbound)
824+
engine.wrap(EMPTY_DATA.duplicate(), netWriteData); // send close (after sslEngine.closeOutbound)
824825
}
825826
catch (SSLException e) {
826827
debug(getRuntime(), "SSLSocket.doShutdown", e);

0 commit comments

Comments
 (0)