示例#1
0
 private PhysicalConnection GetConnection(TextWriter log)
 {
     if (state == (int)State.Disconnected)
     {
         try
         {
             if (!Multiplexer.IsDisposed)
             {
                 Multiplexer.LogLocked(log, "Connecting {0}...", Name);
                 Multiplexer.Trace("Connecting...", Name);
                 if (ChangeState(State.Disconnected, State.Connecting))
                 {
                     Interlocked.Increment(ref socketCount);
                     Interlocked.Exchange(ref connectStartTicks, Environment.TickCount);
                     // separate creation and connection for case when connection completes synchronously
                     // in that case PhysicalConnection will call back to PhysicalBridge, and most of  PhysicalBridge methods assumes that physical is not null;
                     physical = new PhysicalConnection(this);
                     physical.BeginConnect(log);
                 }
             }
             return(null);
         }
         catch (Exception ex)
         {
             Multiplexer.LogLocked(log, "Connect {0} failed: {1}", Name, ex.Message);
             Multiplexer.Trace("Connect failed: " + ex.Message, Name);
             ChangeState(State.Disconnected);
             OnInternalError(ex);
             throw;
         }
     }
     return(physical);
 }
 private PhysicalConnection GetConnection(TextWriter log)
 {
     if (state == (int)State.Disconnected)
     {
         try
         {
             if (!multiplexer.IsDisposed)
             {
                 Multiplexer.LogLocked(log, "Connecting {0}...", Name);
                 Multiplexer.Trace("Connecting...", Name);
                 if (ChangeState(State.Disconnected, State.Connecting))
                 {
                     Interlocked.Increment(ref socketCount);
                     Interlocked.Exchange(ref connectStartTicks, Environment.TickCount);
                     // separate creation and connection for case when connection completes synchronously
                     // in that case PhysicalConnection will call back to PhysicalBridge, and most of  PhysicalBridge methods assumes that physical is not null;
                     physical = new PhysicalConnection(this);
                     physical.BeginConnect(log);
                 }
             }
             return null;
         }
         catch (Exception ex)
         {
             Multiplexer.LogLocked(log, "Connect {0} failed: {1}", Name, ex.Message);
             Multiplexer.Trace("Connect failed: " + ex.Message, Name);
             ChangeState(State.Disconnected);
             OnInternalError(ex);
             throw;
         }
     }
     return physical;
 }