Exemple #1
0
                static void OnSocketConnect(IAsyncResult result)
                {
                    if (result.CompletedSynchronously)
                    {
                        return;
                    }

                    ConnectAsyncResult thisPtr = (ConnectAsyncResult)result.AsyncState;

                    Exception completionException = null;
                    bool      completeSelf        = false;

                    try
                    {
                        completeSelf = thisPtr.CompleteSocketConnect(result);
                    }
                    catch (Exception e)
                    {
                        completeSelf        = true;
                        completionException = e;
                    }

                    if (completeSelf)
                    {
                        thisPtr.Complete(false, completionException);
                    }
                }
Exemple #2
0
        static void OnConnectAsyncComplete(ImpinjReader reader, ConnectAsyncResult result, string errorMessage)
        {
            // This event handler is called asynchronously
            // when the connection attempt has completed.

            // Check the result of the connection attempt
            if (result == ConnectAsyncResult.Success)
            {
                // Successfully connection to the reader. Now configure  and start it.
                Console.WriteLine("Successfully connected to {0}", reader.Address);
                reader.ApplyDefaultSettings();
                Console.WriteLine("Starting reader...");
                //reader.Start();
                SetReport(reader);
                // Wait for the user to press enter.
                Console.WriteLine("Press enter to exit.");
                Console.ReadLine();
                textWriter.Close();

                //cleanup
                reader.Stop();
                reader.Disconnect();
                Console.WriteLine("Reader stopped. Press enter to exit.");
            }
            else
            {
                // Failed to connect to the reader
                Console.WriteLine("Failure while connecting to {0} : {1}", reader.Address, errorMessage);
            }
        }
Exemple #3
0
        // block api
        public void Connect()
        {
            if (Connected)
            {
                return;
            }

            Log.Info("BeginReceive sysSocket.Connect(hostIp, hostPort);");
            try
            {
                sysSocket.Connect(hostIp, hostPort);
            }
            catch (Exception e)
            {
                Log.Error("ClientNetwork BeginReceive throw exp:{0}", e);
                defferedConnected = new ConnectAsyncResult()
                {
                    Ex = e,
                };

                return;
            }

            defferedConnected = new ConnectAsyncResult()
            {
                Conn = new Connector(sysSocket, 0),
            };
        }
Exemple #4
0
        public void Poll()
        {
            try
            {
                if (defferedConnected != null)
                {
                    connector = defferedConnected.Conn;
                    connector.BeginReceive();

                    // notify
                    if (ConnectorConnected != null)
                    {
                        ConnectorConnected(defferedConnected.Conn, defferedConnected.Ex);
                    }

                    defferedConnected = null;
                }

                RefreshMessageQueue();
                RefreshClient();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
        public override IAsyncResult BeginConnect(System.Net.EndPoint endPoint, AsyncCallback callback, Object state)
        {
            ConnectAsyncResult lWrapper = new ConnectAsyncResult(callback, state);

            this.fInnerConnection.BeginConnect(endPoint, lWrapper.ConnectionConnect, this);

            return(lWrapper);
        }
 private static void Reader_ConnectAsyncComplete(ImpinjReader reader, ConnectAsyncResult result, string errorMessage)
 {
     if (result == ConnectAsyncResult.Success)
     {
         reader.ApplyDefaultSettings();
         reader.Start();
         Console.WriteLine("Started...");
     }
     else
     {
         Console.WriteLine(errorMessage);
     }
 }
Exemple #7
0
            static void OnConnect(TransportAsyncCallbackArgs args)
            {
                ConnectAsyncResult thisPtr = (ConnectAsyncResult)args.UserToken;

                if (!thisPtr.CompleteSelf(args.CompletedSynchronously, args.Exception))
                {
                    if (args.Transport != null)
                    {
                        // completed by timer
                        args.Transport.Abort();
                    }
                }
            }
Exemple #8
0
            static void OnConnect(TransportAsyncCallbackArgs args)
            {
                ConnectAsyncResult thisPtr = (ConnectAsyncResult)args.UserToken;

                if (args.Exception != null)
                {
                    thisPtr.Complete(args.CompletedSynchronously, args.Exception);
                }
                else
                {
                    thisPtr.transport = args.Transport;
                    thisPtr.Complete(args.CompletedSynchronously);
                }
            }
        public IConnection EndConnect(IAsyncResult result)
        {
            Socket socket = ConnectAsyncResult.End(result);

            return(this.CreateConnection(socket));
        }
Exemple #10
0
 public TransportBase EndConnect(IAsyncResult result)
 {
     return(ConnectAsyncResult.End(result));
 }
Exemple #11
0
 internal static IOamAsyncResult ConnectAsyncResult2IOamAsyncResult(ConnectAsyncResult car)
 {
     return(car);
 }
Exemple #12
0
        private IAsyncResult BeginConnect(ConnectParams @params,
                                      AsyncCallback asyncCallback,
                                      object asyncState)
        {
            ThrowIfAlreadyConnectedOrAsyncConnectRunning();

              connectAsyncResult = new ConnectAsyncResult();
              connectAsyncResult.BeginConnect(@params, asyncCallback, asyncState);

              return connectAsyncResult;
        }
Exemple #13
0
        public void EndConnect(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            throw new ArgumentNullException("asyncResult");
              if (asyncResult != connectAsyncResult)
            throw new ArgumentException("invalid IAsyncResult", "asyncResult");

              if (connectAsyncResult.EndConnectCalled)
            throw new InvalidOperationException("EndConnect already called");

              try {
            SetSession(connectAsyncResult.EndConnect());
              }
              finally {
            connectAsyncResult = null;
              }
        }
Exemple #14
0
 protected override void OnEndOpen(IAsyncResult result)
 {
     ConnectAsyncResult.End(result);
 }
Exemple #15
0
 public IConnection EndConnect(IAsyncResult result)
 {
     return(ConnectAsyncResult.End(result));
 }