Example #1
0
        SharmIpc(string uniqueHandlerName, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000, Action <string, System.Exception> ExternalExceptionHandler = null,
                 eProtocolVersion protocolVersion = eProtocolVersion.V1)
        {
            this.Statistic.ipc = this;

            tmr = new Timer(new TimerCallback((state) =>
            {
                DateTime now = DateTime.UtcNow;

                //This timer is necessary for Calls based on Callbacks, calls based on WaitHandler have their own timeout,
                //That's why for non-callback calls, timeout will be infinite
                List <ulong> toRemove = new List <ulong>();

                //foreach (var el in df.Where(r => now.Subtract(r.Value.created).TotalMilliseconds >= r.Value.TimeoutsMs))
                foreach (var el in df.Where(r => now.Subtract(r.Value.created).TotalMilliseconds >= r.Value.TimeoutsMs).ToList())
                {
                    if (el.Value.callBack != null)
                    {
                        toRemove.Add(el.Key);
                    }
                    else
                    {
                        el.Value.Set_MRE();
                    }
                }

                ResponseCrate rc = null;
                foreach (var el in toRemove)
                {
                    if (df.TryRemove(el, out rc))
                    {
                        rc.callBack(new Tuple <bool, byte[]>(false, null));  //timeout
                    }
                }
            }), null, 10000, 10000);


            this.ExternalExceptionHandler = ExternalExceptionHandler;
            sm = new SharedMemory(uniqueHandlerName, this, bufferCapacity, maxQueueSizeInBytes, protocolVersion);
        }
Example #2
0
 /// <summary>
 /// SharmIpc constructor
 /// </summary>
 /// <param name="uniqueHandlerName">Must be unique in OS scope (can be PID [ID of the process] + other identifications)</param>
 /// <param name="remoteCallHandler">Callback routine for the remote partner requests. AsyncAnswerOnRemoteCall must be used for answer</param>
 /// <param name="bufferCapacity">bigger buffer sends larger datablocks faster. Default value is 50000</param>
 /// <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>
 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)
 {
     this.AsyncRemoteCallHandler = remoteCallHandler ?? throw new Exception("tiesky.com.SharmIpc: remoteCallHandler can't be null");;
 }