/// <inheritdoc/> public void BuildFilterChain(IoFilterChain chain) { foreach (EntryImpl entry in _entries) { chain.AddLast(entry.Name, entry.Filter); } }
public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter) { if (_count == 0) _filter.Init(); _count++; _filter.OnPreAdd(parent, name, nextFilter); }
public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter) { _filter.OnPostRemove(parent, name, nextFilter); _count--; if (_count == 0) _filter.Destroy(); }
/// <inheritdoc/> public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter) { if (parent.Contains(this)) { throw new ArgumentException("You can't add the same filter instance more than once. Create another instance and add it."); } }
void IoServiceSupport.FireSessionCreated(IoSession session) { if (session.Service is IoConnector) { // If the first connector session, fire a virtual service activation event. Boolean firstSession = _managedSessions.IsEmpty; if (firstSession) { ((IoServiceSupport)this).FireServiceActivated(); } } // If already registered, ignore. if (!_managedSessions.TryAdd(session.Id, session)) { return; } // Fire session events. IoFilterChain filterChain = session.FilterChain; filterChain.FireSessionCreated(); filterChain.FireSessionOpened(); if (_hasHandler) { DelegateUtils.SafeInvoke(SessionCreated, this, new IoSessionEventArgs(session)); } }
/// <inheritdoc/> public override void OnPreRemove(IoFilterChain parent, String name, INextFilter nextFilter) { IoSession session = parent.Session; session.RemoveAttribute(NEXT_FILTER); session.RemoveAttribute(SSL_HANDLER); }
/// <inheritdoc/> public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter) { if (parent.Contains(GetType())) { throw new InvalidOperationException("Only one " + GetType().Name + " is permitted."); } }
public void SetUp() { dummySession = new DummySession(); handler = new DummyHandler(this); dummySession.SetHandler(handler); chain = dummySession.FilterChain; testResult = String.Empty; }
/// <inheritdoc/> public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter) { if (_count == 0) { _filter.Init(); } _count++; _filter.OnPreAdd(parent, name, nextFilter); }
/// <inheritdoc/> public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter) { _filter.OnPostRemove(parent, name, nextFilter); _count--; if (_count == 0) { _filter.Destroy(); } }
/// <summary> /// </summary> public DummySession() : base(new DummyService(new DummyConfig())) { _processor = new DummyProcessor(); _filterChain = new DefaultIoFilterChain(this); IoSessionDataStructureFactory factory = new DefaultIoSessionDataStructureFactory(); AttributeMap = factory.GetAttributeMap(this); SetWriteRequestQueue(factory.GetWriteRequestQueue(this)); }
public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter) { if (parent.Contains<SslFilter>()) throw new InvalidOperationException("Only one SSL filter is permitted in a chain."); IoSession session = parent.Session; session.SetAttribute(NEXT_FILTER, nextFilter); // Create a SSL handler and start handshake. SslHandler handler = new SslHandler(this, session); session.SetAttribute(SSL_HANDLER, handler); }
protected SocketSession(IoService service, IoProcessor processor, IoSessionConfig config, System.Net.Sockets.Socket socket, EndPoint localEP, EndPoint remoteEP, Boolean reuseBuffer) : base(service) { _socket = socket; _localEP = localEP; _remoteEP = remoteEP; Config = config; if (service.SessionConfig != null) Config.SetAll(service.SessionConfig); _processor = processor; _filterChain = new DefaultIoFilterChain(this); }
public SerialSession(SerialConnector service, SerialEndPoint endpoint, SerialPort serialPort) : base(service) { _processor = service; base.Config = new SessionConfigImpl(serialPort); if (service.SessionConfig != null) Config.SetAll(service.SessionConfig); _filterChain = new DefaultIoFilterChain(this); _serialPort = serialPort; _endpoint = endpoint; _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived); }
/// <inheritdoc/> public IWriteFuture Write(Object message, EndPoint remoteEP) { if (message == null) { return(null); } if (!TransportMetadata.Connectionless && remoteEP != null) { throw new InvalidOperationException(); } // If the session has been closed or is closing, we can't either // send a message to the remote side. We generate a future // containing an exception. if (Closing || !Connected) { IWriteFuture future = new DefaultWriteFuture(this); IWriteRequest request = new DefaultWriteRequest(message, future, remoteEP); future.Exception = new WriteToClosedSessionException(request); return(future); } IoBuffer buf = message as IoBuffer; if (buf == null) { System.IO.FileInfo fi = message as System.IO.FileInfo; if (fi != null) { message = new FileInfoFileRegion(fi); } } else if (!buf.HasRemaining) { return(DefaultWriteFuture.NewNotWrittenFuture(this, new ArgumentException("message is empty. Forgot to call flip()?", "message"))); } // Now, we can write the message. First, create a future IWriteFuture writeFuture = new DefaultWriteFuture(this); IWriteRequest writeRequest = new DefaultWriteRequest(message, writeFuture, remoteEP); // Then, get the chain and inject the WriteRequest into it IoFilterChain filterChain = this.FilterChain; filterChain.FireFilterWrite(writeRequest); return(writeFuture); }
/// <summary> /// </summary> protected SocketSession(IoService service, IoProcessor processor, IoSessionConfig config, System.Net.Sockets.Socket socket, EndPoint localEP, EndPoint remoteEP, Boolean reuseBuffer) : base(service) { _socket = socket; _localEP = localEP; _remoteEP = remoteEP; Config = config; if (service.SessionConfig != null) { Config.SetAll(service.SessionConfig); } _processor = processor; _filterChain = new DefaultIoFilterChain(this); }
public SerialSession(SerialConnector service, SerialEndPoint endpoint, SerialPort serialPort) : base(service) { _processor = service; base.Config = new SessionConfigImpl(serialPort); if (service.SessionConfig != null) { Config.SetAll(service.SessionConfig); } _filterChain = new DefaultIoFilterChain(this); _serialPort = serialPort; _endpoint = endpoint; _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived); }
/// <inheritdoc/> public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter) { if (parent.Contains <SslFilter>()) { throw new InvalidOperationException("Only one SSL filter is permitted in a chain."); } IoSession session = parent.Session; session.SetAttribute(NEXT_FILTER, nextFilter); // Create a SSL handler and start handshake. SslHandler handler = new SslHandler(this, session); session.SetAttribute(SSL_HANDLER, handler); }
void IoServiceSupport.FireSessionCreated(IoSession session) { // If already registered, ignore. if (!_managedSessions.TryAdd(session.Id, session)) { return; } // Fire session events. IoFilterChain filterChain = session.FilterChain; filterChain.FireSessionCreated(); filterChain.FireSessionOpened(); if (_hasHandler) { DelegateUtils.SafeInvoke(SessionCreated, this, new IoSessionEventArgs(session)); } }
/// <inheritdoc/> public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter) { // Clean everything DisposeCodec(parent.Session); }
public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter) { test.testResult += "REMOVED"; }
public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter) { test.testResult += "ADDED"; }
/// <inheritdoc/> public virtual void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter) { }
public override void OnPreRemove(IoFilterChain parent, String name, INextFilter nextFilter) { _filter.OnPreRemove(parent, name, nextFilter); }
public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter) { _filter.OnPostAdd(parent, name, nextFilter); }
/// <inheritdoc/> public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter) { if (parent.Contains(this)) throw new ArgumentException("You can't add the same filter instance more than once. " + "Create another instance and add it."); }
/// <inheritdoc/> public override void OnPreRemove(IoFilterChain parent, String name, INextFilter nextFilter) { _filter.OnPreRemove(parent, name, nextFilter); }
/// <inheritdoc/> public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter) { SslHandler handler = GetSslSessionHandler(parent.Session); handler.Handshake(nextFilter); }
/// <inheritdoc/> protected override IConnectFuture Connect0(EndPoint remoteEP, EndPoint localEP, Action <IoSession, IConnectFuture> sessionInitializer) { LoopbackPipe entry; if (!LoopbackAcceptor.BoundHandlers.TryGetValue(remoteEP, out entry)) { return(DefaultConnectFuture.NewFailedFuture(new IOException("Endpoint unavailable: " + remoteEP))); } DefaultConnectFuture future = new DefaultConnectFuture(); // Assign the local end point dynamically, LoopbackEndPoint actualLocalEP; try { actualLocalEP = NextLocalEP(); } catch (IOException e) { return(DefaultConnectFuture.NewFailedFuture(e)); } LoopbackSession localSession = new LoopbackSession(this, actualLocalEP, Handler, entry); InitSession(localSession, future, sessionInitializer); // and reclaim the local end point when the connection is closed. localSession.CloseFuture.Complete += ReclaimLocalEP; // initialize connector session try { IoFilterChain filterChain = localSession.FilterChain; this.FilterChainBuilder.BuildFilterChain(filterChain); // The following sentences don't throw any exceptions. IoServiceSupport serviceSupport = this as IoServiceSupport; if (serviceSupport != null) { serviceSupport.FireSessionCreated(localSession); } } catch (Exception ex) { future.Exception = ex; return(future); } // initialize acceptor session LoopbackSession remoteSession = localSession.RemoteSession; ((LoopbackAcceptor)remoteSession.Service).DoFinishSessionInitialization(remoteSession, null); try { IoFilterChain filterChain = remoteSession.FilterChain; entry.Acceptor.FilterChainBuilder.BuildFilterChain(filterChain); // The following sentences don't throw any exceptions. IoServiceSupport serviceSupport = entry.Acceptor as IoServiceSupport; if (serviceSupport != null) { serviceSupport.FireSessionCreated(remoteSession); } } catch (Exception ex) { ExceptionMonitor.Instance.ExceptionCaught(ex); remoteSession.Close(true); } // Start chains, and then allow and messages read/written to be processed. This is to ensure that // sessionOpened gets received before a messageReceived ((LoopbackFilterChain)localSession.FilterChain).Start(); ((LoopbackFilterChain)remoteSession.FilterChain).Start(); return(future); }
/// <inheritdoc/> public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter) { _filter.OnPostAdd(parent, name, nextFilter); }
/// <inheritdoc/> public virtual void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter) { }
/// <inheritdoc/> public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter) { ResetStatus(parent.Session); }
public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter) { SslHandler handler = GetSslSessionHandler(parent.Session); handler.Handshake(nextFilter); }
public override void OnPreRemove(IoFilterChain parent, String name, INextFilter nextFilter) { IoSession session = parent.Session; session.RemoveAttribute(NEXT_FILTER); session.RemoveAttribute(SSL_HANDLER); }