コード例 #1
0
 internal override void addProtocolTransport(StateTransportImpl transport)
 {
     lock (locker)
     {
         if (state != State.CONNECTING)
         {
             transport.close();
             return;
         }
         Exception t = dispatcher.run(() => listener.onTransportAdded(transport));
         if (t == null)
         {
             this.transport = transport;
             transport.ready();
             state      = State.EXCHANGE;
             shrinktime = SHRINKTIME_MIN;
         }
         else
         {
             if (Trace.isErrorEnabled())
             {
                 Trace.error(this + " addProtocolTransport = " + transport, t);
             }
             transport.close();
             _close();
         }
     }
 }
コード例 #2
0
 internal override void removeProtocolTransport(StateTransportImpl transport)
 {
     lock (locker)
     {
         if (state != State.EXCHANGE)
         {
             return;
         }
         if (this.transport != null)
         {
             transport.close();
             this.transport = null;
         }
         Exception t = dispatcher.run(() => listener.onTransportRemoved(transport));
         if (t == null)
         {
             if (!scheduleReconnect())
             {
                 _close();
             }
         }
         else
         {
             if (Trace.isErrorEnabled())
             {
                 Trace.error(this + " removeProtocolTransport = " + transport, t);
             }
             _close();
         }
         Monitor.Pulse(locker);
     }
 }
コード例 #3
0
 public NetTaskCodecSink(StateTransportImpl t)
 {
     this.t = t;
     if (this.check = t.config.isCheckOutputBuffer())
     {
         this.cfgsize = t.config.getOutputBufferSize();
     }
 }
コード例 #4
0
        private void doConnect()
        {
            StateTransportImpl transport = null;

            try
            {
                TcpClient c = new TcpClient();
                c.ReceiveBufferSize = config.getInputBufferSize();
                c.SendBufferSize    = config.getOutputBufferSize();
                transport           = new StateTransportImpl(this, () => c.Close());
                transport.setupAlarm(new Alarm(() => transport.close(new Exception("connect timeout"))));
                transport.resetAlarm(config.getConnectTimeout());
                lock (locker)
                {
                    c.BeginConnect(config.getPeerAddress().Address, config.getPeerAddress().Port, ar =>
                    {
                        try
                        {
                            c.EndConnect(ar);
                            transport.startup(c.GetStream(), (IPEndPoint)c.Client.LocalEndPoint, (IPEndPoint)c.Client.RemoteEndPoint);
                        }
                        catch (Exception e)
                        {
                            if (Trace.isErrorEnabled())
                            {
                                Trace.error("ClientManagerImpl.doConnect", e);
                            }
                            transport.close(e);
                        }
                    }, null);
                    state = State.CONNECTING;
                }
            }
            catch (Exception t)
            {
                if (Trace.isErrorEnabled())
                {
                    Trace.error(this + " doConnect", t);
                }
                _close();
            }
        }
コード例 #5
0
        public override void close()
        {
            if (Engine.remove(this))
            {
                return;
            }
            lock (locker)
            {
                autoReconnect = false;
                switch (state)
                {
                case State.EXCHANGE:
                    StateTransportImpl _transport = transport;
                    transport = null;
                    _transport.close();
                    while (state != State.CLOSE)
                    {
                        Monitor.Wait(locker);
                    }
                    break;

                case State.CONNECTING:
                    Exception e = dispatcher.run(() => listener.onAbort(null));
                    if (e != null && Trace.isErrorEnabled())
                    {
                        Trace.error(this + " connectAbort", e);
                    }
                    break;

                case State.INIT:
                    if (future != null)
                    {
                        future.Dispose();
                    }
                    break;
                }
                dispatcher.await();
                dispatcher.run(() => listener.onManagerUninitialized(this));
            }
        }
コード例 #6
0
 public CodecSink(StateTransportImpl t)
 {
     this.t = t;
 }
コード例 #7
0
 internal abstract void addProtocolTransport(StateTransportImpl transport);
コード例 #8
0
 internal abstract void removeProtocolTransport(StateTransportImpl transport);