internal void ReleaseWait(short waitId)//, int replyStream) { ReplyBucket bucket = null; replyLock.Read(() => { if (!replies.ContainsKey(waitId)) { //LoggingWrapper.Write("Got reply for message " + messageId.ToString() + ", but no reply bucket exists for that id! Adding bucket and reply.", "Socket Client"); if (Log.IsDebugEnabled) { Log.DebugFormat("ReleaseWait() Got reply for message {0}, but no reply bucket exists for that id! Adding bucket and reply." , waitId); } } else { if (Log.IsDebugEnabled) { Log.DebugFormat("ReleaseWait() Got reply for message {0}" , waitId); } bucket = replies[waitId]; } }); if (bucket != null) { bucket.ReleaseWait(); } }
internal short SetWaitHandle(int waitTimeout) { //this uses GetNextMessageId to generate new ids, but also reuses ids as much as possible. This VASTLY reduces the number of replybuckets needed. ResourcePoolItem <short> idItem = idPool.GetItem(); short waitId = idItem.Item; ReplyBucket bucket = null; if (!replies.ContainsKey(waitId)) //we haven't used this waitId yet { replyLock.Write(() => { if (!replies.ContainsKey(waitId)) { if (Log.IsDebugEnabled) { Log.DebugFormat("SetWaitHandle() Creates new ReplyBucket."); } replies.Add(waitId, new ReplyBucket()); } }); } replyLock.Read(() => { bucket = replies[waitId]; }); bucket.SetValues(waitTimeout, ReplyEvent, idItem); return(waitId); }
internal void WaitForReply(short waitId) { ReplyBucket replyBucket = null; replyLock.Read(() => { if (Log.IsDebugEnabled) { Log.DebugFormat("WaitForReply() Gets reply for waitId {0}", waitId); } replyBucket = replies[waitId]; }); //don't want to hold the lock while we wait, so just get the reference then wait replyBucket.WaitForReply(waitId); }