コード例 #1
0
 /// <inheritdoc/>
 public void BuildFilterChain(IoFilterChain chain)
 {
     foreach (EntryImpl entry in _entries)
     {
         chain.AddLast(entry.Name, entry.Filter);
     }
 }
コード例 #2
0
 public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     if (_count == 0)
         _filter.Init();
     _count++;
     _filter.OnPreAdd(parent, name, nextFilter);
 }
コード例 #3
0
 public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     _filter.OnPostRemove(parent, name, nextFilter);
     _count--;
     if (_count == 0)
         _filter.Destroy();
 }
コード例 #4
0
 /// <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.");
     }
 }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        /// <inheritdoc/>
        public override void OnPreRemove(IoFilterChain parent, String name, INextFilter nextFilter)
        {
            IoSession session = parent.Session;

            session.RemoveAttribute(NEXT_FILTER);
            session.RemoveAttribute(SSL_HANDLER);
        }
コード例 #7
0
 /// <inheritdoc/>
 public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     if (parent.Contains(GetType()))
     {
         throw new InvalidOperationException("Only one " + GetType().Name + " is permitted.");
     }
 }
コード例 #8
0
ファイル: IoFilterChainTest.cs プロジェクト: xlg210/Mina.NET
 public void SetUp()
 {
     dummySession = new DummySession();
     handler      = new DummyHandler(this);
     dummySession.SetHandler(handler);
     chain      = dummySession.FilterChain;
     testResult = String.Empty;
 }
コード例 #9
0
 public void SetUp()
 {
     dummySession = new DummySession();
     handler = new DummyHandler(this);
     dummySession.SetHandler(handler);
     chain = dummySession.FilterChain;
     testResult = String.Empty;
 }
コード例 #10
0
 /// <inheritdoc/>
 public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     if (_count == 0)
     {
         _filter.Init();
     }
     _count++;
     _filter.OnPreAdd(parent, name, nextFilter);
 }
コード例 #11
0
 /// <inheritdoc/>
 public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     _filter.OnPostRemove(parent, name, nextFilter);
     _count--;
     if (_count == 0)
     {
         _filter.Destroy();
     }
 }
コード例 #12
0
ファイル: DummySession.cs プロジェクト: xlg210/Mina.NET
        /// <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));
        }
コード例 #13
0
ファイル: SslFilter.cs プロジェクト: sdgdsffdsfff/hermes.net
        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);
        }
コード例 #14
0
 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);
 }
コード例 #15
0
ファイル: SerialSession.cs プロジェクト: zesus19/c5.v1
        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);
        }
コード例 #16
0
ファイル: AbstractIoSession.cs プロジェクト: xlg210/Mina.NET
        /// <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);
        }
コード例 #17
0
 /// <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);
 }
コード例 #18
0
ファイル: SerialSession.cs プロジェクト: zesus19/c5.v1
        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);
        }
コード例 #19
0
        /// <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);
        }
コード例 #20
0
ファイル: AbstractIoService.cs プロジェクト: wxjwz/Mina.NET
        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));
            }
        }
コード例 #21
0
 /// <inheritdoc/>
 public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     // Clean everything
     DisposeCodec(parent.Session);
 }
コード例 #22
0
 public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     test.testResult += "REMOVED";
 }
コード例 #23
0
 public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     test.testResult += "ADDED";
 }
コード例 #24
0
ファイル: IoFilterAdapter.cs プロジェクト: xlg210/Mina.NET
 /// <inheritdoc/>
 public virtual void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
 }
コード例 #25
0
 public override void OnPreRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     _filter.OnPreRemove(parent, name, nextFilter);
 }
コード例 #26
0
 public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     _filter.OnPostAdd(parent, name, nextFilter);
 }
コード例 #27
0
ファイル: KeepAliveFilter.cs プロジェクト: zesus19/c5.v1
 /// <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.");
 }
コード例 #28
0
 /// <inheritdoc/>
 public override void OnPreRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     _filter.OnPreRemove(parent, name, nextFilter);
 }
コード例 #29
0
        /// <inheritdoc/>
        public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter)
        {
            SslHandler handler = GetSslSessionHandler(parent.Session);

            handler.Handshake(nextFilter);
        }
コード例 #30
0
ファイル: IoFilterChainTest.cs プロジェクト: xlg210/Mina.NET
 public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     test.testResult += "ADDED";
 }
コード例 #31
0
ファイル: LoopbackConnector.cs プロジェクト: xlg210/Mina.NET
        /// <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);
        }
コード例 #32
0
ファイル: IoFilterAdapter.cs プロジェクト: zhangf911/Mina.NET
 /// <inheritdoc/>
 public virtual void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 { }
コード例 #33
0
 /// <inheritdoc/>
 public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     // Clean everything
     DisposeCodec(parent.Session);
 }
コード例 #34
0
 /// <inheritdoc/>
 public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     _filter.OnPostAdd(parent, name, nextFilter);
 }
コード例 #35
0
ファイル: IoFilterAdapter.cs プロジェクト: xlg210/Mina.NET
 /// <inheritdoc/>
 public virtual void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
 }
コード例 #36
0
ファイル: KeepAliveFilter.cs プロジェクト: xlg210/Mina.NET
 /// <inheritdoc/>
 public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     ResetStatus(parent.Session);
 }
コード例 #37
0
ファイル: IoFilterChainTest.cs プロジェクト: xlg210/Mina.NET
 public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     test.testResult += "REMOVED";
 }
コード例 #38
0
ファイル: KeepAliveFilter.cs プロジェクト: zesus19/c5.v1
 /// <inheritdoc/>
 public override void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     ResetStatus(parent.Session);
 }
コード例 #39
0
ファイル: SslFilter.cs プロジェクト: sdgdsffdsfff/hermes.net
 public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     SslHandler handler = GetSslSessionHandler(parent.Session);
     handler.Handshake(nextFilter);
 }
コード例 #40
0
ファイル: IoFilterAdapter.cs プロジェクト: zhangf911/Mina.NET
 /// <inheritdoc/>
 public virtual void OnPostRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 { }
コード例 #41
0
ファイル: SslFilter.cs プロジェクト: sdgdsffdsfff/hermes.net
 public override void OnPreRemove(IoFilterChain parent, String name, INextFilter nextFilter)
 {
     IoSession session = parent.Session;
     session.RemoveAttribute(NEXT_FILTER);
     session.RemoveAttribute(SSL_HANDLER);
 }