Beispiel #1
0
 public virtual void OpenConnection(ConnectionInfo info, IConnectionListener listener)
 {
     int currPhase;
     object CS$2$0000;
     lock ((CS$2$0000 = this.stateMutex))
     {
         this.CloseConnection();
         currPhase = ++this.phase;
     }
     ConnectionInfo myInfo = (ConnectionInfo) info.Clone();
     if (myInfo.EnableStreamSense && !myInfo.Polling)
     {
         LSClient testClient = new LSClient();
         ExtConnectionListener myListener = new ExtConnectionListener(listener);
         ConnectionInfo mySubInfo = (ConnectionInfo) info.Clone();
         mySubInfo.EnableStreamSense = false;
         new Thread(delegate {
             try
             {
                 testClient.OpenConnection(mySubInfo, myListener);
             }
             catch (Exception)
             {
             }
         }) { IsBackground = true }.Start();
         if (!myListener.WaitStreamingTimeoutAnswer())
         {
             lock ((CS$2$0000 = this.stateMutex))
             {
                 if (currPhase == this.phase)
                 {
                     this.subClient = testClient;
                 }
                 else
                 {
                     AsynchCloseConnection(testClient);
                     return;
                 }
             }
             myListener.FlushAndStart();
         }
         else
         {
             AsynchCloseConnection(testClient);
             lock ((CS$2$0000 = this.stateMutex))
             {
                 if (currPhase != this.phase)
                 {
                     return;
                 }
             }
             LSClient pollClient = new LSClient();
             myInfo.Polling = true;
             pollClient.OpenConnection(myInfo, listener);
             lock ((CS$2$0000 = this.stateMutex))
             {
                 if (currPhase == this.phase)
                 {
                     this.subClient = pollClient;
                 }
                 else
                 {
                     AsynchCloseConnection(pollClient);
                 }
             }
         }
     }
     else
     {
         MyServerListener serverListener = new MyServerListener(this, listener, currPhase);
         bool ok = false;
         try
         {
             ServerManager newManager = new ServerManager(myInfo, serverListener);
             newManager.Connect();
             ok = true;
             lock ((CS$2$0000 = this.stateMutex))
             {
                 if (currPhase == this.phase)
                 {
                     this.connListener = listener;
                     this.asyncListener = serverListener;
                     this.connManager = newManager;
                 }
                 else
                 {
                     CloseFlushing(newManager, serverListener, listener);
                     return;
                 }
             }
             newManager.Start();
         }
         finally
         {
             if (!ok)
             {
                 serverListener.OnClosed(null);
             }
         }
     }
 }
Beispiel #2
0
 public virtual void OpenConnection(ConnectionInfo info, IConnectionListener listener)
 {
     ConnectionInfo info2 = (ConnectionInfo) info.Clone();
     info2.useGetForStreaming = true;
     lock (this.connMutex)
     {
         object obj3;
         this.CloseConnection();
         if (info2.enableStreamSense && !info2.isPolling)
         {
             ThreadStart start = null;
             LSClient testClient = new LSClient();
             ExtConnectionListener myListener = new ExtConnectionListener(listener);
             ConnectionInfo mySubInfo = (ConnectionInfo) info.Clone();
             mySubInfo.enableStreamSense = false;
             new Thread(() => {
                 try
                 {
                     testClient.OpenConnection(mySubInfo, myListener);
                 }
                 catch (Exception)
                 {
                 }
             }).Start();
             if (!myListener.WaitStreamingTimeoutAnswer())
             {
                 lock ((obj3 = this.stateMutex))
                 {
                     this.subClient = testClient;
                 }
                 myListener.FlushAndStart();
             }
             else
             {
                 if (start == null)
                 {
                     start = delegate {
                         testClient.CloseConnection();
                     };
                 }
                 new Thread(start).Start();
                 LSClient client = new LSClient();
                 info2.isPolling = true;
                 client.OpenConnection(info2, listener);
                 lock ((obj3 = this.stateMutex))
                 {
                     this.subClient = client;
                 }
             }
         }
         else
         {
             int num;
             lock ((obj3 = this.stateMutex))
             {
                 num = this.phase + 1;
             }
             MyServerListener asyncListener = new MyServerListener(this, listener, num);
             bool flag2 = false;
             try
             {
                 ServerManager manager = new ServerManager(info2, asyncListener);
                 manager.Connect();
                 lock ((obj3 = this.stateMutex))
                 {
                     this.connListener = listener;
                     this.asyncListener = asyncListener;
                     this.phase = num;
                     this.connManager = manager;
                 }
                 flag2 = true;
                 manager.Start();
             }
             finally
             {
                 if (!flag2)
                 {
                     asyncListener.OnClosed(null);
                 }
             }
         }
     }
 }