Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
hhblaze committed Nov 22, 2019
1 parent 9d8bc60 commit 8f73587
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions Process1/SharmIpc/SharmIpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ public eProtocolVersion ProtocolVersion
get { return this.sm.ProtocolVersion; }
}

/// <summary>
/// Default is false. Descibed in https://github.com/hhblaze/SharmIPC/issues/6
/// <para>Gives ability to parse packages in the same receiving thread before processing them in another thread</para>
/// <para>Programmer is responsible for the returning control back ASAP from RemoteCallHandler via Task.Run(()=>process(msg))</para>
/// </summary>
bool ExternalProcessing = false;

/// <summary>
/// SharmIpc constructor
/// </summary>
Expand All @@ -153,9 +160,10 @@ public eProtocolVersion ProtocolVersion
/// <param name="maxQueueSizeInBytes">If remote partner is temporary not available, messages are accumulated in the sending buffer. This value sets the upper threshold of the buffer in bytes.</param>
/// <param name="ExternalExceptionHandler">External exception handler can be supplied, will be returned Description from SharmIPC, like class.method name and handeled exception</param>
/// <param name="protocolVersion">Version of communication protocol. Must be the same for both communicating peers</param>
/// <param name="externalProcessing">Gives ability to parse packages in the same receiving thread before processing them in another thread</param>
public SharmIpc(string uniqueHandlerName, Func<byte[], Tuple<bool, byte[]>> remoteCallHandler, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000,
Action<string, System.Exception> ExternalExceptionHandler = null, eProtocolVersion protocolVersion = eProtocolVersion.V1)
:this(uniqueHandlerName,bufferCapacity,maxQueueSizeInBytes,ExternalExceptionHandler, protocolVersion)
Action<string, System.Exception> ExternalExceptionHandler = null, eProtocolVersion protocolVersion = eProtocolVersion.V1, bool externalProcessing = false)
:this(uniqueHandlerName,bufferCapacity,maxQueueSizeInBytes,ExternalExceptionHandler, protocolVersion, externalProcessing)
{
this.remoteCallHandler = remoteCallHandler ?? throw new Exception("tiesky.com.SharmIpc: remoteCallHandler can't be null");
}
Expand All @@ -169,19 +177,21 @@ public SharmIpc(string uniqueHandlerName, Func<byte[], Tuple<bool, byte[]>> remo
/// <param name="maxQueueSizeInBytes">If remote partner is temporary not available, messages are accumulated in the sending buffer. This value sets the upper threshold of the buffer in bytes.</param>
/// <param name="ExternalExceptionHandler">External exception handler can be supplied, will be returned Description from SharmIPC, like class.method name and handeled exception</param>
/// <param name="protocolVersion">Version of communication protocol. Must be the same for both communicating peers</param>
/// <param name="externalProcessing">Gives ability to parse packages in the same receiving thread before processing them in another thread</param>
public SharmIpc(string uniqueHandlerName, Action<ulong, byte[]> remoteCallHandler, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000,
Action<string, System.Exception> ExternalExceptionHandler = null, eProtocolVersion protocolVersion = eProtocolVersion.V1)
: this(uniqueHandlerName, bufferCapacity, maxQueueSizeInBytes, ExternalExceptionHandler, protocolVersion)
Action<string, System.Exception> ExternalExceptionHandler = null, eProtocolVersion protocolVersion = eProtocolVersion.V1, bool externalProcessing = false)
: this(uniqueHandlerName, bufferCapacity, maxQueueSizeInBytes, ExternalExceptionHandler, protocolVersion, externalProcessing)
{
this.AsyncRemoteCallHandler = remoteCallHandler ?? throw new Exception("tiesky.com.SharmIpc: remoteCallHandler can't be null"); ;

}

SharmIpc(string uniqueHandlerName, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000, Action<string, System.Exception> ExternalExceptionHandler = null,
eProtocolVersion protocolVersion = eProtocolVersion.V1)

SharmIpc(string uniqueHandlerName, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000, Action<string, System.Exception> ExternalExceptionHandler = null,
eProtocolVersion protocolVersion = eProtocolVersion.V1, bool externalProcessing = false)
{
this.Statistic.ipc = this;
this.ExternalProcessing = externalProcessing;

tmr = new Timer(new TimerCallback((state) =>
{
Expand Down Expand Up @@ -258,7 +268,7 @@ internal void InternalDataArrived(eMsgType msgType, ulong msgId, byte[] bt)
{
case eMsgType.Request:

Task.Run(() =>
if (this.ExternalProcessing)
{
if (AsyncRemoteCallHandler != null)
{
Expand All @@ -270,7 +280,23 @@ internal void InternalDataArrived(eMsgType msgType, ulong msgId, byte[] bt)
{
this.remoteCallHandler(bt);
}
});
}
else
{
Task.Run(() =>
{
if (AsyncRemoteCallHandler != null)
{
//CallAsyncRemoteHandler(msgId, bt);
AsyncRemoteCallHandler(msgId, bt);
//Answer must be supplied via AsyncAnswerOnRemoteCall
}
else
{
this.remoteCallHandler(bt);
}
});
}

break;
case eMsgType.RpcRequest:
Expand Down
Binary file modified Process1/SharmIpc/bin/Debug/SharmIpc.dll
Binary file not shown.
Binary file modified Process1/SharmIpc/bin/Debug/SharmIpc.pdb
Binary file not shown.

0 comments on commit 8f73587

Please sign in to comment.