public static MPProtectedChannel GetChannel(string channelName, int waitTime) { if (MPChannelSettings.Find(channelName) == null) { return(null); } if (waitTime <= 0) { waitTime = 20 * 1000; } ManualTimer timer = new ManualTimer(waitTime); MPProtectedChannel pc = GetChannel(channelName, true); while (!timer.Timeout) { if (pc != null) { return(pc); } pc = GetChannel(channelName, false); System.Threading.Thread.Sleep(200); } MPChannels.Log(string.Format("Cannot open channel to {0}", channelName)); return(null); }
static MPProtectedChannel GetChannel(string channelName, bool newRequest) { lock (_locker) foreach (MPProtectedChannel item in list) { if (item == null) { list.Remove(item); return(null); } if (item.Connected && item.Name == channelName) { list.Remove(item); //MPChannels.Log(string.Format("Channel {0} reallocated", item.Id)); return(item); } } if (newRequest == true) { MPProtectedChannel pc = MPProtectedChannel.CreateChannel(channelName); if (pc == null) { return(null); } lock (_locker) { list.Add(pc); } } return(null); }
public static bool SendAndWaitAnswer(string channelName, string destId, object packet, int timeout, out byte[] answer) { answer = null; try { MPProtectedChannel pc = GetChannel(channelName, timeout); if (pc == null) { return(false); } if (pc.SendAndWaitAnswer(destId, packet, timeout, out answer) == false) { pc.Close(); return(false); } ReleaseChannel(pc); return(true); } catch //(Exception e) { //string s = e.ToString(); //CLog.Log("BAD error: " + s); //CLog.LogError("BAD error: " + s); } return(false); }
public static void CloseChannel(MPProtectedChannel channel) { channel.Close(); }
public static void ReleaseChannel(MPProtectedChannel channel) { //MPChannels.Log(string.Format("Channel {0} released (added to pool)", channel.Id)); channel._updateTimers(); lock (_locker) { list.Add(channel); } }
public static void ReleaseChannel(MPProtectedChannel channel) { MPChannelsPool.ReleaseChannel(channel); }