Пример #1
0
        private void WireStreams(Socket newSocket, Action notifyWhenClosed)
        {
            if (_socket != null)             // reset
            {
                _socketIsClosed = 0;

                // TODO: replace cancellation token in ringbuffers

                // _inputBuffer.Reset();
                // _outputBuffer.Reset();
            }

            _socket           = newSocket;
            _notifyWhenClosed = notifyWhenClosed;

            // WriteLoop
            _socketConsumer = new SocketConsumer(_socket, _outputBuffer, _token, _index);
            _socketConsumer.OnNotifyClosed += OnSocketClosed;

            // ReadLoop
            _socketProducer = new SocketProducer(_socket, _inputBuffer, _token, _index);
            _socketProducer.OnNotifyClosed += OnSocketClosed;

            Writer = new InternalBigEndianWriter(_outputRingBufferStream);
            Reader = new InternalBigEndianReader(_inputRingBufferStream);
//
//			_socketConsumer.Start();
        }
        public ReusableTempWriter(ArrayPool <byte> bufferPool, ObjectPool <ReusableTempWriter> memStreamPool)
        {
            _memoryStream = new MemoryStreamSlim(bufferPool, AmqpPrimitivesWriter.BufferSize);

            _innerWriter = new InternalBigEndianWriter(_memoryStream);

            _writer2 = new AmqpPrimitivesWriter(_innerWriter, bufferPool, memStreamPool);
        }
        public ReusableTempWriter(ArrayPool<byte> bufferPool, ObjectPool<ReusableTempWriter> memStreamPool)
        {
            _memoryStream = new MemoryStreamSlim(bufferPool, AmqpPrimitivesWriter.BufferSize);

            _innerWriter = new InternalBigEndianWriter(_memoryStream);

            _writer2 = new AmqpPrimitivesWriter(_innerWriter, bufferPool, memStreamPool);
        }
        public AmqpPrimitivesWriter(InternalBigEndianWriter writer, ArrayPool <byte> bufferPool,
                                    ObjectPool <ReusableTempWriter> memStreamPool)
        {
            _writer = writer;

            _bufferPool = bufferPool ?? new DefaultArrayPool <byte>(BufferSize, 5);
            if (memStreamPool == null)
            {
                memStreamPool = new ObjectPool <ReusableTempWriter>(() =>
                {
                    Console.WriteLine("Creating new writer...");
                    return(new ReusableTempWriter(new DefaultArrayPool <byte>(BufferSize, 5), _memStreamPool));
                }, 6);
            }
            _memStreamPool = memStreamPool;
        }
        public AmqpPrimitivesWriter(InternalBigEndianWriter writer, ArrayPool<byte> bufferPool,
									ObjectPool<ReusableTempWriter> memStreamPool)
        {
            _writer = writer;

            _bufferPool = bufferPool ?? new DefaultArrayPool<byte>(BufferSize, 5);
            if (memStreamPool == null)
            {
                memStreamPool = new ObjectPool<ReusableTempWriter>(() =>
                {
                    Console.WriteLine("Creating new writer...");
                    return new ReusableTempWriter(new DefaultArrayPool<byte>(BufferSize, 5), _memStreamPool);
                }, 6);
            }
            _memStreamPool = memStreamPool;
        }
Пример #6
0
        internal void WireStreams(CancellationToken cancellationToken, Action notifyWhenClosed)
        {
            _inputBuffer.Restart();

            // _socket = newSocket;
            _notifyWhenClosed = notifyWhenClosed;

            // WriteLoop
            _socketConsumer = new SocketStreamWriterAdapter(_socket);
            _socketConsumer.OnNotifyClosed += OnSocketClosed;

            // ReadLoop
            _socketProducer = new SocketProducer(_socket, _inputBuffer, cancellationToken, _index);
            _socketProducer.OnNotifyClosed += OnSocketClosed;

            Writer = new InternalBigEndianWriter(_socketConsumer);
            Reader = new InternalBigEndianReader(_inputRingBufferStream);
        }
        public SocketRingBuffers(Socket socket, CancellationToken cancellationToken, Action notifyWhenClosed, Action flushWrite)
        {
            _notifyWhenClosed = notifyWhenClosed;

            _inputBuffer = new ByteRingBuffer(cancellationToken);
            _outputBuffer = new ByteRingBuffer(cancellationToken);

            _inputRingBufferStream = new RingBufferStreamAdapter(_inputBuffer);
            _outputRingBufferStream = new RingBufferStreamAdapter(_outputBuffer);

            // WriteLoop
            _socketConsumer = new SocketConsumer(socket, _outputBuffer, cancellationToken, flushWrite);
            _socketConsumer.OnNotifyClosed += OnSocketClosed;

            // ReadLoop
            _socketProducer = new SocketProducer(socket, _inputBuffer, cancellationToken);
            _socketProducer.OnNotifyClosed += OnSocketClosed;

            Writer = new InternalBigEndianWriter(_outputRingBufferStream);
            Reader = new InternalBigEndianReader(_inputRingBufferStream);
        }
Пример #8
0
        public void WireStreams(CancellationToken cancellationToken, Action notifyWhenClosed)
        {
            _inputBuffer.SetSocket(_socket, OnSocketClosed);

            _inputBuffer.ReenableBuffers();

            _notifyWhenClosed = notifyWhenClosed;

            // WriteLoop
            _socketConsumer = new SocketStreamWriterAdapter(_socket)
            {
                OnNotifyClosed = OnSocketClosed
            };

            // ReadLoop
            // _socketProducer = new SocketProducer(_socket, _inputBuffer, cancellationToken, _index);
            // _socketProducer.OnNotifyClosed += OnSocketClosed;
            Writer = new InternalBigEndianWriter(_socketConsumer.Write);
            Reader = new InternalBigEndianReader(_inputRingBufferStream);
            // Reader = new publicBigEndianReader(new SocketStreamReaderAdapter(_socket));
        }
        public SocketRingBuffers(Socket socket, CancellationToken cancellationToken, Action notifyWhenClosed, Action flushWrite)
        {
            _notifyWhenClosed = notifyWhenClosed;

            _inputBuffer  = new ByteRingBuffer(cancellationToken);
            _outputBuffer = new ByteRingBuffer(cancellationToken);

            _inputRingBufferStream  = new RingBufferStreamAdapter(_inputBuffer);
            _outputRingBufferStream = new RingBufferStreamAdapter(_outputBuffer);

            // WriteLoop
            _socketConsumer = new SocketConsumer(socket, _outputBuffer, cancellationToken, flushWrite);
            _socketConsumer.OnNotifyClosed += OnSocketClosed;

            // ReadLoop
            _socketProducer = new SocketProducer(socket, _inputBuffer, cancellationToken);
            _socketProducer.OnNotifyClosed += OnSocketClosed;

            Writer = new InternalBigEndianWriter(_outputRingBufferStream);
            Reader = new InternalBigEndianReader(_inputRingBufferStream);
        }
 public void Initialize(InternalBigEndianWriter writer)
 {
     _writer = writer;
 }
Пример #11
0
		private void WireStreams(Socket newSocket, Action notifyWhenClosed)
		{
			if (_socket != null) // reset
			{
				_socketIsClosed = 0; 

				// TODO: replace cancellation token in ringbuffers

				// _inputBuffer.Reset();
				// _outputBuffer.Reset();
			}

			_socket = newSocket;
			_notifyWhenClosed = notifyWhenClosed;

			// WriteLoop
			_socketConsumer = new SocketConsumer(_socket, _outputBuffer, _token, _index);
			_socketConsumer.OnNotifyClosed += OnSocketClosed;

			// ReadLoop
			_socketProducer = new SocketProducer(_socket, _inputBuffer, _token, _index);
			_socketProducer.OnNotifyClosed += OnSocketClosed;

			Writer = new InternalBigEndianWriter(_outputRingBufferStream);
			Reader = new InternalBigEndianReader(_inputRingBufferStream);
//
//			_socketConsumer.Start();
		}