Skip to content

Commit 33c3a0d

Browse files
committed
[Com] only invoke when channel open and small fixes
1 parent 824abdc commit 33c3a0d

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

Source/com/Administrator.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,19 @@ namespace RPC {
418418
}
419419
void Clear()
420420
{
421-
_message.Release();
422-
_channel.Release();
423-
_instance.Release();
421+
if (_message.IsValid() == true) {
422+
_message.Release();
423+
}
424+
if (_channel.IsValid() == true) {
425+
_channel.Release();
426+
}
427+
if (_instance.IsValid() == true) {
428+
_instance.Release();
429+
}
424430
}
425431
void Set(Core::IPCChannel& channel, const Core::ProxyType<Core::IIPC>& message)
426432
{
427-
ASSERT(_message->Label() == InvokeMessage::Id());
433+
ASSERT(message->Label() == InvokeMessage::Id());
428434

429435
_message = message;
430436
_channel = Core::ProxyType<Core::IPCChannel>(channel);
@@ -458,12 +464,15 @@ namespace RPC {
458464

459465
static void Invoke(Core::ProxyType<Core::IPCChannel>& channel, Core::ProxyType<Core::IIPC>& data)
460466
{
461-
Core::ProxyType<InvokeMessage> message = { ExtractInvokeMessage(data) };
462-
if (message.IsValid() == true) {
463-
_administrator.Invoke(channel, message);
464-
channel->ReportResponse(data);
465-
} else {
466-
SYSLOG(Logging::Error, (_T("COMRPC Invoke message incorrectly formatted!")));
467+
ASSERT(channel.IsValid() == true);
468+
if (channel->IsOpen() == true) { // if the channel has closed in the mean time no need to process the message... (note this is an optimization and not thread safe, the AddRef we do in Set makes sure the instance is still valid)
469+
Core::ProxyType<InvokeMessage> message = { ExtractInvokeMessage(data) };
470+
if (message.IsValid() == true) {
471+
_administrator.Invoke(channel, message);
472+
channel->ReportResponse(data);
473+
} else {
474+
SYSLOG(Logging::Error, (_T("COMRPC Invoke message incorrectly formatted!")));
475+
}
467476
}
468477
}
469478

Source/core/IPCConnector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ POP_WARNING()
759759
virtual uint32_t Id() const = 0;
760760
virtual string Origin() const = 0;
761761
virtual uint32_t ReportResponse(Core::ProxyType<IIPC>& inbound) = 0;
762+
virtual bool IsOpen() const = 0;
762763

763764
private:
764765
virtual uint32_t Execute(const ProxyType<IIPC>& command, IDispatchType<IIPC>* completed) = 0;
@@ -930,6 +931,10 @@ POP_WARNING()
930931

931932
return (Core::ERROR_NONE);
932933
}
934+
bool IsOpen() const override
935+
{
936+
return _link.IsOpen();
937+
}
933938
virtual void StateChange()
934939
{
935940
__StateChange();

0 commit comments

Comments
 (0)