Example #1
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
            {
                Console.WriteLine("wtf? " + eventArgs.ExceptionObject.ToString());
            };
            AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) =>
            {
                Console.WriteLine("ops " + eventArgs.Exception.ToString());
            };

//			Console.WriteLine("Is Server GC: " + GCSettings.IsServerGC);
//			GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
//			Console.WriteLine("Compaction mode: " + GCSettings.LargeObjectHeapCompactionMode);
//			Console.WriteLine("Latency mode: " + GCSettings.LatencyMode);
//			GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;
//			Console.WriteLine("New Latency mode: " + GCSettings.LatencyMode);

            var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(Dns.GetHostAddresses(TargetHost)[1], port);

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                Console.WriteLine("Cancelling...");
                cancellationToken.Cancel();
                socket.Close();
                _event.Set();
            };

            Console.WriteLine("Client started");

            _socket2Streams = new SocketHolder();
//			_socket2Streams.WireStreams(cancellationToken.Token, );


//				delegate
//			{
//				cancellationToken.Cancel();
//				Console.WriteLine("closed...");
//			});
//			_amqpWriter = new AmqpPrimitivesWriter(_socket2Streams.Writer, null, null);
//			_amqpReader = new AmqpPrimitivesReader(_socket2Streams.Reader);

//			Task.Factory.StartNew(WriteFrames, cancellationToken, TaskCreationOptions.LongRunning);
//			Task.Factory.StartNew(ReadFrames, cancellationToken, TaskCreationOptions.LongRunning);
            new Thread(WriteFrames)
            {
                IsBackground = true, Name = "A"
            }.Start();
            new Thread(ReadFrames)
            {
                IsBackground = true, Name = "B"
            }.Start();

            _event.WaitOne();

            Console.WriteLine("Done..");
            // Thread.CurrentThread.Join();
        }
        public ConnectionIO(Connection connection) : base(channelNum: 0)
        {
            _cancellationTokenSource = new CancellationTokenSource();
            _cancellationToken       = _cancellationTokenSource.Token;

            _conn         = connection;
            _socketHolder = new SocketHolder(_cancellationTokenSource.Token);

            _commandOutboxEvent = new AutoResetEvent(false);
            // _commandOutboxEvent = new AutoResetSuperSlimLock(false);
            _commandOutbox = new ConcurrentQueue <CommandToSend>();

            _cmdToSendObjPool = new ObjectPool <CommandToSend>(() => new CommandToSend(i => _cmdToSendObjPool.PutObject(i)), 200, true);
        }
Example #3
0
        public ConnectionIO(Connection connection) : base(channelNum: 0)
        {
            _conn         = connection;
            _socketHolder = new SocketHolder();

            _commandOutboxEvent = new AutoResetEvent(false);
            _waitingServerReply = new ManualResetEventSlim(true);
            // _commandOutboxEvent = new AutoResetSuperSlimLock(false);
            _commandOutbox = new ConcurrentQueue <CommandToSend>();

            _cmdToSendObjPool = new ObjectPool <CommandToSend>(() => new CommandToSend(i => _cmdToSendObjPool.PutObject(i)), 200, true);

            _amqpWriter  = new AmqpPrimitivesWriter();
            _amqpReader  = new AmqpPrimitivesReader();
            _frameReader = new FrameReader();
        }