Example #1
0
        private void HandleConnectedClient(object sender, ConnectedEventArgs <IPEndPoint> args)
        {
            lock (_syncLock)
            {
                if (!_connected)
                {
                    //stop connection timer..
                    _poller.Dispose();

                    //first attempt to handshake..
                    _injector.HandShake = HandShakePhases.ClientTalkFirst;
                    _communication.Send(_injector, _rem);

                    //start handshake countdown..
                    _poller = new Timer(HandleHandShakeTimeout, null, TimeSpan.FromMilliseconds(TimeOut > 0 ? TimeOut : DEFAULTTIMEOUT), TimeSpan.Zero);

                    //_loc = _communication.Local; //todo
                    _connected = true;
                    Log.Debug("Handshake started with: {0}", args.remote.ToString());
                }
                else
                {
                    Log.Warn("A connection has been called with an already connected client. Connected to: {0}", args.remote.ToString());
                }
            }
        }
Example #2
0
        private void CommitTransaction(DeviceTransaction transaction)
        {
            Contract.Requires(transaction != null);
            Contract.Requires(!string.IsNullOrEmpty(transaction.Command));
            var transactionsInFlight = Interlocked.Increment(ref activeTransactions);

            if (transactionsInFlight > 1)
            {
                // This should never happen and if it does then we have a serious concurrency bug
                log.Error()
                .Message("Detected transaction overlap before committing {transaction}", transaction)
                .Write();
                throw new InvalidOperationException("Detected transaction overlap");
            }
            transaction.MakeHot();
            transaction.ObserveResponse(observableReceiveSequence);
            using (var responseSequence = observableReceiveSequence.Connect())
            {
                channel.Send(transaction.Command);
                var succeeded = transaction.WaitForCompletionOrTimeout();
                if (!succeeded)
                {
                    log.Warn()
                    .Transaction(transaction)
                    .Message("Transaction {id} timed out with reason: {message}",
                             transaction.TransactionId, transaction.ErrorMessage.SingleOrDefault())
                    .Write();
                }
            }
            if (transaction.Failed)
            {
                log.Warn()
                .Transaction(transaction)
                .Message("Transaction {id} was marked as FAILED", transaction.TransactionId)
                .Write();
            }
            log.Info()
            .Transaction(transaction)
            .Message("Transaction {id} completed", transaction.TransactionId);
            transactionsInFlight = Interlocked.Decrement(ref activeTransactions);
            if (transactionsInFlight != 0)
            {
                // This should never happen and if it does then we have a serious concurrency bug
                log.Error()
                .Message("Detected transaction overlap after completing {transaction}", transaction);
                throw new InvalidOperationException(
                          "Detected transaction overlap, please report this as an issue on GitHub and include your log file");
            }
        }
Example #3
0
        private static void SendData(ICommunicationChannel channel, Stopwatch watch)
        {
            var dataBytes = new byte[65536];

            for (int i = 0; i < dataBytes.Length; i++)
            {
                dataBytes[i] = 0x65;
            }

            var dataBytesStr = System.Text.Encoding.UTF8.GetString(dataBytes);

            watch.Start();
            for (int i = 0; i < 20000; i++)
            {
                channel.Send(dataBytesStr);
            }
        }
 public void RequestHardwareStatus()
 {
     channel.Send(Constants.CmdGetInfo);
 }
Example #5
0
 protected void Send(object objectToSend)
 {
     _communication.Send(objectToSend, _rem);
 }
 private void SendCommand(string command)
 {
     channel.Send(EnsureCommandEncapsulation(command));
 }