Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 public static void CloseChannel(MPProtectedChannel channel)
 {
     channel.Close();
 }
Exemplo n.º 5
0
 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); }
 }
Exemplo n.º 6
0
 public static void ReleaseChannel(MPProtectedChannel channel)
 {
     MPChannelsPool.ReleaseChannel(channel);
 }