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(); } } }
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); } }
public NetTaskCodecSink(StateTransportImpl t) { this.t = t; if (this.check = t.config.isCheckOutputBuffer()) { this.cfgsize = t.config.getOutputBufferSize(); } }
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(); } }
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)); } }
public CodecSink(StateTransportImpl t) { this.t = t; }
internal abstract void addProtocolTransport(StateTransportImpl transport);
internal abstract void removeProtocolTransport(StateTransportImpl transport);