Skip to content

Commit

Permalink
Remove message adopt in C# and JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Oct 2, 2024
1 parent 0f5a361 commit 6dd93db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 38 deletions.
24 changes: 4 additions & 20 deletions csharp/src/Ice/ConnectionI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ _inactivityTimer is null && // timer not already scheduled
os.writeInt(Protocol.headerSize); // Message size.
try
{
_ = sendMessage(new OutgoingMessage(os, false, false));
_ = sendMessage(new OutgoingMessage(os, compress: false));
}
catch (LocalException ex)
{
Expand Down Expand Up @@ -1821,7 +1821,7 @@ private void initiateShutdown()

scheduleCloseTimer();

if ((sendMessage(new OutgoingMessage(os, false, false)) & OutgoingAsyncBase.AsyncStatusSent) != 0)
if ((sendMessage(new OutgoingMessage(os, compress: false)) & OutgoingAsyncBase.AsyncStatusSent) != 0)
{
setState(StateClosingPending);

Expand Down Expand Up @@ -2135,7 +2135,6 @@ private int sendMessage(OutgoingMessage message)
// the message was queued.
if (_sendStreams.Count > 0)
{
message.adopt();
_sendStreams.AddLast(message);
return OutgoingAsyncBase.AsyncStatusQueued;
}
Expand Down Expand Up @@ -2181,8 +2180,6 @@ private int sendMessage(OutgoingMessage message)
// thread pool. At this point the message() method will take care of sending the whole message (held by
// _writeStream) when the transceiver is ready to write more of the message buffer.

message.adopt();

_writeStream.swap(message.stream);
_sendStreams.AddLast(message);
_threadPool.register(this, op);
Expand Down Expand Up @@ -2559,7 +2556,7 @@ private void sendResponse(OutgoingResponse response, bool isTwoWay, byte compres

if (isTwoWay)
{
sendMessage(new OutgoingMessage(response.outputStream, compress > 0, adopt: true));
sendMessage(new OutgoingMessage(response.outputStream, compress > 0));
}

if (_state == StateActive && _maxDispatches > 0 && _dispatchCount == _maxDispatches)
Expand Down Expand Up @@ -2845,11 +2842,10 @@ private void doApplicationClose()

private class OutgoingMessage
{
internal OutgoingMessage(OutputStream stream, bool compress, bool adopt)
internal OutgoingMessage(OutputStream stream, bool compress)
{
this.stream = stream;
this.compress = compress;
_adopt = adopt;
}

internal OutgoingMessage(OutgoingAsyncBase outAsync, OutputStream stream, bool compress, int requestId)
Expand All @@ -2866,17 +2862,6 @@ internal void canceled()
outAsync = null;
}

internal void adopt()
{
if (_adopt)
{
var stream = new OutputStream(Util.currentProtocolEncoding);
stream.swap(this.stream);
this.stream = stream;
_adopt = false;
}
}

internal bool sent()
{
stream = null;
Expand Down Expand Up @@ -2904,7 +2889,6 @@ internal void completed(LocalException ex)
internal OutgoingAsyncBase outAsync;
internal bool compress;
internal int requestId;
internal bool _adopt;
internal bool prepared;
internal bool isSent;
internal bool invokeSent;
Expand Down
22 changes: 4 additions & 18 deletions js/src/Ice/ConnectionI.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class ConnectionI {
}

if (isTwoWay) {
this.sendMessage(OutgoingMessage.createForStream(response.outputStream, true));
this.sendMessage(OutgoingMessage.createForStream(response.outputStream));
}
--this._dispatchCount;

Expand Down Expand Up @@ -1057,7 +1057,7 @@ export class ConnectionI {
os.writeInt(Protocol.headerSize); // Message size.

scheduleCloseTimeout(this);
this.sendMessage(OutgoingMessage.createForStream(os, false));
this.sendMessage(OutgoingMessage.createForStream(os));
}

idleCheck(idleTimeout) {
Expand Down Expand Up @@ -1120,7 +1120,7 @@ export class ConnectionI {
os.writeByte(0);
os.writeInt(Protocol.headerSize); // Message size.
try {
this.sendMessage(OutgoingMessage.createForStream(os, false));
this.sendMessage(OutgoingMessage.createForStream(os));
} catch (ex) {
this.setState(StateClosed, ex);
}
Expand Down Expand Up @@ -1297,7 +1297,6 @@ export class ConnectionI {
Debug.assert(this._state < StateClosed);

if (this._sendStreams.length > 0) {
message.doAdopt();
this._sendStreams.push(message);
return AsyncStatus.Queued;
}
Expand All @@ -1320,8 +1319,6 @@ export class ConnectionI {
return AsyncStatus.Sent;
}

message.doAdopt();

this._writeStream.swap(message.stream);
this._sendStreams.push(message);

Expand Down Expand Up @@ -1619,15 +1616,6 @@ class OutgoingMessage {
this.outAsync = null;
}

doAdopt() {
if (this.adopt) {
const stream = new OutputStream(Protocol.currentProtocolEncoding);
stream.swap(this.stream);
this.stream = stream;
this.adopt = false;
}
}

sent() {
if (this.outAsync !== null) {
this.outAsync.sent();
Expand All @@ -1640,10 +1628,9 @@ class OutgoingMessage {
}
}

static createForStream(stream, adopt) {
static createForStream(stream) {
const m = new OutgoingMessage();
m.stream = stream;
m.adopt = adopt;
m.isSent = false;
m.requestId = 0;
m.outAsync = null;
Expand All @@ -1656,7 +1643,6 @@ class OutgoingMessage {
m.outAsync = out;
m.requestId = requestId;
m.isSent = false;
m.adopt = false;
return m;
}
}

0 comments on commit 6dd93db

Please sign in to comment.