예제 #1
0
        /// <summary>
        /// The HandleConnect method is invoked by an asynchronous
        /// connection attempt to inform the connector that it has
        /// been completed. The connector will take the appropriate
        /// action depending on the resulting state of the request.
        /// </summary>
        /// <param name="ar">
        /// The .NET asynchronous result details.
        /// </param>
        private void HandleConnect(IAsyncResult ar)
        {
            // REC: Retrieve the original IPC state information
            // that was provided to the asynchronous operation:
            IpcState ipcState = ar.AsyncState as IpcState;

            if (ipcState != null)
            {
                try
                {
                    ipcState.IpcSocket.EndConnect(ar);
                    // REC: Dispatch the connect success event to the
                    // subscribers so that they can determine whether
                    // or not the connection should go forward.
                    EventHandler <VfxTcpConnectorEventArgs> tmpDispatch = EventDispatch;
                    if (tmpDispatch != null)
                    {
                        VfxTcpConnectorEventArgs connectArgs = new VfxTcpConnectorEventArgs();
                        connectArgs.EventType     = VfxTcpConnectorEventTypes.Event_Connect_Success;
                        connectArgs.EventSocket   = ipcState.IpcSocket;
                        connectArgs.EventEndpoint = ipcState.IpcEndpoint;
                        tmpDispatch(this, connectArgs);

                        // REC: Check the cancellation flag to determine if
                        // any subscriber wants the connection canceled:
                        if (connectArgs.EventCancel == true)
                        {
                            ipcState.IpcSocket.Close();
                            return;
                        }
                    }


                    // REC: Create a new instance of VfxTcpModule that
                    // will be used for processing IO over the socket:
                    VfxTcpModule tcpModule = new VfxTcpModule();
                    tcpModule.Init(ipcState.IpcSocket, this.RxBuffering);

                    // REC: Pass the initialized module to the instance
                    // of the VFX IPC session that is associated with the
                    // connection request:
                    ipcState.IpcSession.Init(tcpModule);
                }
                catch (System.Exception x)
                {
                    EventHandler <VfxTcpConnectorEventArgs> tmpDispatch = EventDispatch;
                    if (tmpDispatch != null)
                    {
                        VfxTcpConnectorEventArgs tmpArgs = new VfxTcpConnectorEventArgs();
                        tmpArgs.EventType      = VfxTcpConnectorEventTypes.Event_Connect_Failure;
                        tmpArgs.EventEndpoint  = ipcState.IpcEndpoint;
                        tmpArgs.EventException = x;
                        tmpDispatch(this, tmpArgs);
                    }
                }
            }
        }
예제 #2
0
 /// <summary>
 /// The HandleTcpConnector_Success event handler is invoked
 /// in response to the tcp connector establishing a connection
 /// to the peer system.
 /// </summary>
 /// <param name="sender">
 /// The connector that is dispatching the event.
 /// </param>
 /// <param name="args">
 /// The event details that are associated with the event.
 /// </param>
 private void HandleTcpConnector_Success(object sender, VfxTcpConnectorEventArgs args)
 {
     // REC: Translate the connector's success notification
     // into the corresponding IPC event and dispatch it:
     EventHandler<VfxIpcEventArgs> tmpDispatch = EventDispatch;
     if (tmpDispatch != null)
     {
         VfxIpcEventArgs tmpArgs = new VfxIpcEventArgs(VfxIpcEventTypes.Event_Connect_Success);
         tmpDispatch(this, tmpArgs);
     }
 }
예제 #3
0
 /// <summary>
 /// The HandleTcpConnector_Dispatch event handler is invoked
 /// in response to the events from the connector the endpoint
 /// is using to establish a connection.
 /// </summary>
 /// <param name="sender">
 /// The VfxTcpConnector instance that is dispatching the
 /// event to the endpoint.
 /// </param>
 /// <param name="args">
 /// The details of the event being dispatched.
 /// </param>
 private void HandleTcpConnector_Dispatch(object sender, VfxTcpConnectorEventArgs args)
 {
     switch (args.EventType)
     {
         case VfxTcpConnectorEventTypes.Event_Connect_Success:
             HandleTcpConnector_Success(sender, args);
             break;
         case VfxTcpConnectorEventTypes.Event_Connect_Failure:
             HandleTcpConnector_Failure(sender, args);
             break;
     }
 }