/// <summary> /// Replaces the invokeid /// </summary> /// <param name="notify"></param> protected void InternalReceive(Notify notify) { if (RtmpUtil.IsResult(notify)) { int ourid = notify.InvokeId; CallResultWait callresult = null; lock (WaitLock) { if (WaitInvokeList != null) { int idx = WaitInvokeList.FindIndex(crw => crw.Call.InvokeId == ourid); if (idx != -1) { callresult = WaitInvokeList[idx]; WaitInvokeList.RemoveAt(idx); } } } //InvokeId was found in the waitlist, that means its one of our calls. if (callresult != null) { callresult.Result = notify; callresult.Wait.Set(); //Not blocking, lets send it to the handler instead. if (!callresult.Blocking) { OnCall(callresult.Call, callresult.Result); } return; //Return, we don't want LoL receiving the message. } int theirid; lock (InvokeIds) { if (!InvokeIds.TryGetValue(ourid, out theirid)) { StaticLogger.Error(string.Format("Call id not found for {0}", notify)); return; } InvokeIds.Remove(ourid); } notify.InvokeId = theirid; } var buf = RtmpProtocolEncoder.Encode(remotecontext, CreatePacket(notify)); if (buf == null) { StaticLogger.Fatal("Unable to encode " + notify); } else { var buff = buf.ToArray(); if (logtofiles) { using (var fs = File.Open("recv.dmp", FileMode.Append, FileAccess.Write)) { fs.Write(buff, 0, buff.Length); } } if (encode) { base.OnReceive(buff, 0, buff.Length); } } }
/// <summary> /// Call blocks until the result is received. Use Send for a nonblocking call. /// </summary> /// <param name="notify">Call</param> /// <returns>Result or null if failed</returns> public Notify Call(Notify notify) { var callresult = new CallResultWait(notify, true); lock (WaitLock) { if (WaitInvokeList == null) return null; WaitInvokeList.Add(callresult); } notify.InvokeId = CurrentInvoke.Increment(); InternalSend(notify, false); callresult.Wait.WaitOne(-1); return callresult.Result; }