示例#1
0
        private void CompleteAccept(IAsyncResult ar)
        {
            IoContext context = ar.AsyncState as IoContext;

            if (context != null)
            {
                try
                {
                    Socket peer = context.IpcSocket.EndAccept(ar);

                    // REC: Locate the factory associated with this endpoint
                    // and create the appropriate type of session instance:
                    if (_mapFactories.ContainsKey(context.IpcEndPoint))
                    {
                        IPEndPoint peerEP = peer.RemoteEndPoint as IPEndPoint;
                        if (ValidatePeer(peerEP))
                        {
                            VfxTcpModule tcpModule = new VfxTcpModule();
                            tcpModule.Init(peer, this.RxBuffering);

                            // REC: Create a new instance of the session handler that
                            // is configured for the endpoint and associated the
                            // client IO stream with it:
                            IVfxIpcSession session = _mapFactories[context.IpcEndPoint].CreateSession();
                            session.Init(tcpModule);
                        }
                        else
                        {
                            peer.Close();
                        }
                    }

                    // REC: Initiate another asynchronous connection:
                    context.IpcSocket.BeginAccept(CompleteAccept, context);
                }
                catch (System.ObjectDisposedException)
                {
                    // REC: This exception gets thrown when an asynchronous
                    // accept fails due to the socket it was initiated from
                    // being closed. This is part of the shutdown procedure
                    // and should just be caught and ignored.
                }
            }
        }