Ejemplo n.º 1
0
 void Flush(bool disposing)
 {
     if (_remainingSpaceInOutputSegment == 0)
         _socket.Flush();
     else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength)
     {
         if (disposing)
             _currentOutputSegment.Dispose();
     }
     else
     {
         unsafe
         {
             _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment;
         }
         _socket.Send(_currentOutputSegment, RIO_SEND_FLAGS.NONE);
         _currentOutputSegment.Dispose();
         if (disposing)
         {
             _remainingSpaceInOutputSegment = 0;
             _outputSegmentTotalLength = 0;
         }
         else
         {
             _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
             _outputSegmentTotalLength = _currentOutputSegment.TotalLength;
             _remainingSpaceInOutputSegment = _outputSegmentTotalLength;
         }
     }
 }
Ejemplo n.º 2
0
 public void Dispose()
 {
     _currentValue?.Dispose();
     _currentValue = null;
     if (_continuation != null)
         _continuation();
 }
Ejemplo n.º 3
0
 public void Flush(bool disposing)
 {
     if (_remainingSpaceInOutputSegment == 0)
     {
         _socket.Flush();
     }
     else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength)
     {
         _currentOutputSegment.Dispose();
         return;
     }
     else
     {
         unsafe
         {
             _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment;
         }
         _socket.SendAndDispose(_currentOutputSegment, RIO_SEND_FLAGS.NONE);
         if (!disposing)
         {
             _currentOutputSegment          = _socket.SendBufferPool.GetBuffer();
             _outputSegmentTotalLength      = _currentOutputSegment.TotalLength;
             _remainingSpaceInOutputSegment = _outputSegmentTotalLength;
         }
         else
         {
             _remainingSpaceInOutputSegment = 0;
             _outputSegmentTotalLength      = 0;
         }
     }
 }
Ejemplo n.º 4
0
        void CompleteRead()
        {
            var tmp = _currentInputSegment;

            _currentInputSegment = _nextInputSegment;
            _currentInputSegment.GetResult();
            _nextInputSegment = tmp;
            if (_currentInputSegment.CurrentContentLength != 0)
            {
                _socket.BeginReceive(_nextInputSegment);
            }

            OnIncommingSegment(_currentInputSegment);

            if (_currentInputSegment.CurrentContentLength != 0)
            {
                if (_nextInputSegment.IsCompleted)
                {
                    CompleteRead();
                }
                else
                {
                    _nextInputSegment.OnCompleted(completeReadDelegate);
                }
            }
            else
            {
                Dispose();
            }
        }
Ejemplo n.º 5
0
        private void GetNewSegment()
        {
            _currentInputSegment = _incommingSegments.GetResult();
            if (_currentInputSegment == null)
            {
                _readtcs.SetResult(0);
                return;
            }

            _bytesReadInCurrentSegment = 0;
            _currentContentLength = _currentInputSegment.CurrentContentLength;

            if (_currentContentLength == 0)
            {
                _currentInputSegment.Dispose();
                _currentInputSegment = null;
                _readtcs.SetResult(0);
                return;
            }
            else
            {
                _socket.BeginReceive();
                CompleteRead();
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            pipeLineDeph = int.Parse(args.FirstOrDefault(f => f.StartsWith("-p"))?.Substring(2) ?? "16");
            int connections = int.Parse(args.FirstOrDefault(f => f.StartsWith("-c"))?.Substring(2) ?? "1024");

            Console.WriteLine("RioSharp http server");
            Console.WriteLine("Optimizing for " + connections + " connections");
            Console.WriteLine("Optimizing for pipeline depth of: " + pipeLineDeph);

            sendPool = new RioFixedBufferPool(10 * connections, 256 * pipeLineDeph);
            recivePool = new RioFixedBufferPool(10 * connections, 256 * pipeLineDeph);

            listener = new RioTcpListener(sendPool, recivePool, (uint)connections);
            currentSegment = listener.PreAllocateWrite(GetResponse());
            responseBytes = GetResponse();
            //Task.Run(async () =>
            //{
            //    while (true)
            //    {
            //        UpdateResponse();
            //        await Task.Delay(60000);
            //    }
            //});

            listener.OnAccepted = new Action<RioSocket>(s => ThreadPool.QueueUserWorkItem(o => Servebuff((RioSocket)o), s));
            listener.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5000), 1024 * connections);
            Console.WriteLine("Listening on : http://localhost:5000");
            Console.WriteLine("Press enter to exit");
            Console.ReadLine();

            listener.Dispose();

            
        }
Ejemplo n.º 7
0
 public RioSegmentReader(RioSocket socket)
 {
     _socket              = socket;
     _nextInputSegment    = _socket.ReceiveBufferPool.GetBuffer();
     _currentInputSegment = _socket.ReceiveBufferPool.GetBuffer();
     completeReadDelegate = CompleteRead;
 }
Ejemplo n.º 8
0
 public void Flush(bool moreData)
 {
     if (_remainingSpaceInOutputSegment == 0)
         _socket.CommitSend();
     else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength)
         return;
     else
     {
         unsafe
         {
             _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment;
         }
         _socket.SendInternal(_currentOutputSegment, RIO_SEND_FLAGS.NONE);
         _currentOutputSegment.DisposeWhenComplete();
         if (moreData)
         {
             _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
             _outputSegmentTotalLength = _currentOutputSegment.TotalLength;
             _remainingSpaceInOutputSegment = _outputSegmentTotalLength;
         }
         else
         {
             _remainingSpaceInOutputSegment = 0;
             _outputSegmentTotalLength = 0;
         }
     }
 }
Ejemplo n.º 9
0
 public RioSegmentReader(RioSocket socket)
 {
     _socket = socket;
     _nextInputSegment = _socket.ReceiveBufferPool.GetBuffer();
     _currentInputSegment = _socket.ReceiveBufferPool.GetBuffer();
     completeReadDelegate = CompleteRead;
 }
Ejemplo n.º 10
0
        private void CompleteRead()
        {
            var toCopy = _currentContentLength - _bytesReadInCurrentSegment;

            if (toCopy > _readCount)
            {
                toCopy = _readCount;
            }

            unsafe
            {
                fixed(byte *p = &_readBuffer[_readoffset])
                Buffer.MemoryCopy(_currentInputSegment.RawPointer + _bytesReadInCurrentSegment, p, _readCount, toCopy);
            }

            _bytesReadInCurrentSegment += toCopy;

            if (_currentContentLength == _bytesReadInCurrentSegment)
            {
                _currentInputSegment.Dispose();
                _currentInputSegment = null;
            }

            _readtcs.SetResult(toCopy);
        }
Ejemplo n.º 11
0
        private void GetNewSegment()
        {
            _currentInputSegment = _incommingSegments.GetResult();
            if (_currentInputSegment == null)
            {
                _readtcs.SetResult(0);
                return;
            }

            _bytesReadInCurrentSegment = 0;
            _currentContentLength      = _currentInputSegment.CurrentContentLength;

            if (_currentContentLength == 0)
            {
                _currentInputSegment.Dispose();
                _currentInputSegment = null;
                _readtcs.SetResult(0);
                return;
            }
            else
            {
                _socket.BeginReceive();
                CompleteRead();
            }
        }
Ejemplo n.º 12
0
 internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
     {
         WinSock.ThrowLastWSAError();
     }
 }
Ejemplo n.º 13
0
        public RioBufferSegment GetResult()
        {
            var res = _currentValue;

            _currentValue = null;
            return(res);
        }
Ejemplo n.º 14
0
        public void Flush(bool moreData)
        {
            if (_remainingSpaceInOutputSegment == 0)
                _socket.CommitSend();
            else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength)
                return;
            else
            {
                unsafe
                {
                    _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment;
                }
                _socket.SendInternal(_currentOutputSegment, RIO_SEND_FLAGS.NONE);

                if (moreData)
                {
                    _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
                    _outputSegmentTotalLength = _currentOutputSegment.TotalLength;
                    _remainingSpaceInOutputSegment = _outputSegmentTotalLength;
                }
                else
                {
                    _remainingSpaceInOutputSegment = 0;
                    _outputSegmentTotalLength = 0;
                }

            }
        }
Ejemplo n.º 15
0
        internal void Send(RioBufferSegment segment, IPEndPoint remoteAdress, RIO_SEND_FLAGS flags)
        {
            Debug.Assert(inUse);
            var adresssegment = AllocateAdress(remoteAdress);

            Send(segment, adresssegment, flags);
            adresssegment.Dispose();
        }
Ejemplo n.º 16
0
 internal virtual void Send(RioBufferSegment segment, RioBufferSegment remoteAdress, RIO_SEND_FLAGS flags)
 {
     Debug.Assert(inUse);
     if (!RioStatic.SendEx(_requestQueue, segment.SegmentPointer, 1, RIO_BUF.NullSegment, remoteAdress.SegmentPointer, RIO_BUF.NullSegment, RIO_BUF.NullSegment, flags, segment.Index))
     {
         WinSock.ThrowLastWSAError();
     }
 }
Ejemplo n.º 17
0
 public void WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
             WinSock.ThrowLastWSAError();
     }
 }
Ejemplo n.º 18
0
 internal virtual void SendAndDispose(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     Debug.Assert(inUse);
     segment.DisposeOnComplete();
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
     {
         WinSock.ThrowLastWSAError();
     }
 }
Ejemplo n.º 19
0
 public RioStream(RioSocket socket)
 {
     _socket = socket;
     _currentInputSegment            = null;
     _currentOutputSegment           = _socket.SendBufferPool.GetBuffer();
     _getNewSegmentDelegate          = GetNewSegment;
     socket.OnIncommingSegmentUnsafe = (sock, s) => _incommingSegments.Set(s);
     socket.BeginReceive();
 }
Ejemplo n.º 20
0
 public RioStream(RioConnectionOrientedSocket socket)
 {
     _socket = socket;
     _currentInputSegment = null;
     _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
     _getNewSegmentDelegate = GetNewSegment;
     socket.OnIncommingSegment = s => _incommingSegments.Set(s);
     socket.ReciveInternal();
 }
Ejemplo n.º 21
0
 public RioStream(RioSocket socket)
 {
     _socket = socket;
     _currentInputSegment = null;
     _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
     _getNewSegmentDelegate = GetNewSegment;
     socket.OnIncommingSegmentUnsafe = (sock, s) => _incommingSegments.Set(s);
     socket.BeginReceive();
 }
Ejemplo n.º 22
0
 public void Dispose()
 {
     _currentValue?.Dispose();
     _currentValue = null;
     if (_continuation != null)
     {
         _continuation();
     }
 }
Ejemplo n.º 23
0
        public unsafe RioBufferSegment BeginReceive(RioBufferSegment segment)
        {

            segment.SetNotComplete();
            if (!RioStatic.Receive(_requestQueue, segment.SegmentPointer, 1, RIO_RECEIVE_FLAGS.NONE, segment.Index))
                WinSock.ThrowLastWSAError();

            return segment;
        }
        public override RioBufferSegment BeginReceive(RioBufferSegment segment)
        {
            Debug.Assert(inUse);
            lastReceiveStart = RioSocketPool.CurrentTime;
            Interlocked.Increment(ref pendingRecives);
            segment._internalCompletionSignal = onreadCompletion;
            segment.socketId = currentId;

            return(base.BeginReceive(segment));
        }
        internal override void Send(RioBufferSegment segment, RIO_SEND_FLAGS flags)
        {
            Debug.Assert(inUse);
            lastSendStart = RioSocketPool.CurrentTime;
            Interlocked.Increment(ref pendingSends);
            segment._internalCompletionSignal = onSendCompletion;
            segment.socketId = currentId;

            base.Send(segment, flags);
        }
Ejemplo n.º 26
0
 public RioBufferSegment WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         Segment.SetNotComplete();
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
             WinSock.ThrowLastWSAError();
     }
     return Segment;
 }
Ejemplo n.º 27
0
 public void WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
         {
             WinSock.ThrowLastWSAError();
         }
     }
 }
Ejemplo n.º 28
0
        public unsafe RioBufferSegment BeginReceive(RioBufferSegment segment)
        {
            segment.SetNotComplete();
            if (!RioStatic.Receive(_requestQueue, segment.SegmentPointer, 1, RIO_RECEIVE_FLAGS.NONE, segment.Index))
            {
                WinSock.ThrowLastWSAError();
            }

            return(segment);
        }
Ejemplo n.º 29
0
        public void Start()
        {
            _nextInputSegment = _nextInputSegment ?? _socket.ReceiveBufferPool.GetBuffer();
            _currentInputSegment = _currentInputSegment ?? _socket.ReceiveBufferPool.GetBuffer();
            _socket.BeginReceive(_nextInputSegment);

            if (_nextInputSegment.IsCompleted)
                CompleteRead();
            else
                _nextInputSegment.OnCompleted(completeReadDelegate);
        }
Ejemplo n.º 30
0
 public RioStream(RioSocket socket)
 {
     _socket = socket;
     _currentInputSegment           = _socket.ReceiveBufferPool.GetBuffer();
     _currentOutputSegment          = _socket.SendBufferPool.GetBuffer();
     _nextInputSegment              = _socket.ReceiveBufferPool.GetBuffer();
     _getNewSegmentDelegateDelegate = GetNewSegmentDelegateWrapper;
     _outputSegmentTotalLength      = _currentOutputSegment.TotalLength;
     _remainingSpaceInOutputSegment = _outputSegmentTotalLength;
     _socket.BeginReceive(_nextInputSegment);
     _waitCallback = WaitCallbackcallback;
 }
Ejemplo n.º 31
0
 public RioBufferSegment WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         Segment.SetNotComplete();
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
         {
             WinSock.ThrowLastWSAError();
         }
     }
     return(Segment);
 }
Ejemplo n.º 32
0
        public virtual RioBufferSegment BeginReceive(RioBufferSegment segment)
        {
            Debug.Assert(inUse);
            segment.SegmentPointer->Length = segment.TotalLength;
            segment.SetNotComplete();
            if (!RioStatic.Receive(_requestQueue, segment.SegmentPointer, 1, RIO_RECEIVE_FLAGS.NONE, segment.Index))
            {
                WinSock.ThrowLastWSAError();
            }

            return(segment);
        }
Ejemplo n.º 33
0
        public RioFixedBufferPool(int segmentCount, int segmentLength)
        {
            AllSegments = new RioBufferSegment[segmentCount];
            TotalLength = segmentCount * segmentLength;
            BufferPointer = Marshal.AllocHGlobal(TotalLength);
            _segmentpointer = Marshal.AllocHGlobal(Marshal.SizeOf<RIO_BUFSEGMENT>() * segmentCount);

            for (int i = 0; i < segmentCount; i++)
            {
                var b = new RioBufferSegment(this, BufferPointer ,_segmentpointer, i, segmentLength );
                AllSegments[i] = b;
                _availableSegments.Enqueue(b);
            }
        }
Ejemplo n.º 34
0
        public RioFixedBufferPool(int segmentCount, int segmentLength)
        {
            AllSegments     = new RioBufferSegment[segmentCount];
            TotalLength     = segmentCount * segmentLength;
            BufferPointer   = Marshal.AllocHGlobal(TotalLength);
            _segmentpointer = Marshal.AllocHGlobal(Marshal.SizeOf <RIO_BUFSEGMENT>() * segmentCount);

            for (int i = 0; i < segmentCount; i++)
            {
                var b = new RioBufferSegment(this, BufferPointer, _segmentpointer, i, segmentLength);
                AllSegments[i] = b;
                _availableSegments.Enqueue(b);
            }
        }
Ejemplo n.º 35
0
        public RioFixedBufferPool(int segmentCount, int segmentLength)
        {
            AllSegments     = new RioBufferSegment[segmentCount];
            TotalLength     = segmentCount * segmentLength;
            BufferPointer   = Kernel32.VirtualAlloc(IntPtr.Zero, (uint)TotalLength, 0x00001000 | 0x00002000, 0x04);
            _segmentpointer = Kernel32.VirtualAlloc(IntPtr.Zero, (uint)(Marshal.SizeOf <RIO_BUF>() * segmentCount), 0x00001000 | 0x00002000, 0x04);

            for (int i = 0; i < segmentCount; i++)
            {
                var b = new RioBufferSegment(this, BufferPointer, _segmentpointer, i, segmentLength);
                AllSegments[i] = b;
                _availableSegments.Enqueue(b);
            }
        }
Ejemplo n.º 36
0
        public RioFixedBufferPool(int segmentCount, int segmentLength)
        {
            AllSegments = new RioBufferSegment[segmentCount];
            TotalLength = segmentCount * segmentLength;
            BufferPointer = Kernel32.VirtualAlloc(IntPtr.Zero, (uint)TotalLength, 0x00001000 | 0x00002000, 0x04);
            _segmentpointer = Kernel32.VirtualAlloc(IntPtr.Zero, (uint)(Marshal.SizeOf<RIO_BUF>() * segmentCount), 0x00001000 | 0x00002000, 0x04);

            for (int i = 0; i < segmentCount; i++)
            {
                var b = new RioBufferSegment(this, BufferPointer, _segmentpointer, i, segmentLength);
                AllSegments[i] = b;
                _availableSegments.Enqueue(b);
            }
        }
Ejemplo n.º 37
0
 int GetNewSegment()
 {
     if (_nextInputSegment.CurrentContentLength == 0)
     {
         _nextInputSegment.Dispose();
         _currentInputSegment.Dispose();
         return(0);
     }
     else
     {
         _bytesReadInCurrentSegment = 0;
         _nextInputSegment          = _socket.BeginReceive(Interlocked.Exchange(ref _currentInputSegment, _nextInputSegment));
         return(CompleteRead());
     }
 }
Ejemplo n.º 38
0
        public void Start()
        {
            _nextInputSegment    = _nextInputSegment ?? _socket.ReceiveBufferPool.GetBuffer();
            _currentInputSegment = _currentInputSegment ?? _socket.ReceiveBufferPool.GetBuffer();
            _socket.BeginReceive(_nextInputSegment);

            if (_nextInputSegment.IsCompleted)
            {
                CompleteRead();
            }
            else
            {
                _nextInputSegment.OnCompleted(completeReadDelegate);
            }
        }
Ejemplo n.º 39
0
        public void CompleteRead()
        {
            var tmp = _currentInputSegment;
            _currentInputSegment = _nextInputSegment;
            _nextInputSegment = tmp;

            _socket.BeginReceive(_nextInputSegment);

            OnIncommingSegment(_currentInputSegment);

            if (_nextInputSegment.IsCompleted)
                CompleteRead();
            else
                _nextInputSegment.OnCompleted(completeReadDelegate);
        }
Ejemplo n.º 40
0
        public void Set(RioBufferSegment item)
        {
            bool taken = false;
            _spinLock.Enter(ref taken);
            //if (!taken)
            //    throw new ArgumentException("fuu");

            //if (_currentValue != null)
            //    throw new ArgumentException("fuu");
            
            _currentValue = item;
            _spinLock.Exit();

            if (_continuation != null)
                ThreadPool.QueueUserWorkItem(_continuationWrapperDelegate, null);
        }
Ejemplo n.º 41
0
        public FlippingRioStream(RioSocket socket)
        {
            _socket = socket;
            _currentInputSegment = _socket.ReceiveBufferPool.GetBuffer();
            _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
            _nextInputSegment = _socket.ReceiveBufferPool.GetBuffer();

            if (_nextInputSegment._awaitableState != RioBufferSegment._notStarted)
            {

            }

            _getNewSegmentDelegateDelegate = GetNewSegmentDelegateWrapper;

            _outputSegmentTotalLength = _currentOutputSegment.TotalLength;
            _remainingSpaceInOutputSegment = _outputSegmentTotalLength;
            _socket.BeginReceive(_nextInputSegment);

            _waitCallback = WaitCallbackcallback;
        }
Ejemplo n.º 42
0
        public void CompleteRead()
        {
            var tmp = _currentInputSegment;

            _currentInputSegment = _nextInputSegment;
            _nextInputSegment    = tmp;

            _socket.BeginReceive(_nextInputSegment);

            OnIncommingSegment(_currentInputSegment);

            if (_nextInputSegment.IsCompleted)
            {
                CompleteRead();
            }
            else
            {
                _nextInputSegment.OnCompleted(completeReadDelegate);
            }
        }
Ejemplo n.º 43
0
        public void Set(RioBufferSegment item)
        {
            bool taken = false;

            _spinLock.Enter(ref taken);
            //if (!taken)
            //    throw new ArgumentException("fuu");

            //if (_currentValue != null)
            //    throw new ArgumentException("fuu");

            _currentValue = item;
            _spinLock.Exit();

            if (_continuation != null)
            {
                var res = _continuation;
                _continuation = null;
                ThreadPool.QueueUserWorkItem(_continuationWrapperDelegate, res);
            }
        }
Ejemplo n.º 44
0
        private int GetNewSegment()
        {
            var tmp = _currentInputSegment;
            _nextInputSegment.GetResult();
            _currentInputSegment = _nextInputSegment;

            _bytesReadInCurrentSegment = 0;
            _currentContentLength = _currentInputSegment.CurrentContentLength;

            if (_currentContentLength == 0)
            {
                _currentInputSegment.Dispose();
                tmp.Dispose();
                return 0;
            }
            else
            {
                _nextInputSegment = tmp;
                _socket.BeginReceive(_nextInputSegment);
                return CompleteRead();
            }
        }
Ejemplo n.º 45
0
        void CompleteRead()
        {
            var tmp = _currentInputSegment;
            _currentInputSegment = _nextInputSegment;
            _currentInputSegment.GetResult();
            _nextInputSegment = tmp;
            if (_currentInputSegment.CurrentContentLength != 0)
                _socket.BeginReceive(_nextInputSegment);

            OnIncommingSegment(_currentInputSegment);

            if (_currentInputSegment.CurrentContentLength != 0)
            {
                if (_nextInputSegment.IsCompleted)
                    CompleteRead();
                else
                    _nextInputSegment.OnCompleted(completeReadDelegate);
            }
            else {
                Dispose();
            }
        }
Ejemplo n.º 46
0
        static void Main(string[] args)
        {
            pipeLineDeph = int.Parse(args.FirstOrDefault(f => f.StartsWith("-p"))?.Substring(2) ?? "16");
            int connections = int.Parse(args.FirstOrDefault(f => f.StartsWith("-c"))?.Substring(2) ?? "1024");

            sendPool = new RioFixedBufferPool(10 * connections, 140 * pipeLineDeph);
            recivePool = new RioFixedBufferPool(10 * connections, 128 * pipeLineDeph);

            listener = new RioTcpListener(sendPool, recivePool, 1024);
            currentSegment = listener.PreAllocateWrite(GetResponse());
            responseBytes = GetResponse();
            //Task.Run(async () =>
            //{
            //    while (true)
            //    {
            //        UpdateResponse();
            //        await Task.Delay(60000);
            //    }
            //});

            listener.OnAccepted = new Action<RioConnectionOrientedSocket>(s => ThreadPool.QueueUserWorkItem(o => Servebuff((RioConnectionOrientedSocket)o), s));
            listener.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5000), 1024 * connections);
            Console.ReadLine();
        }
Ejemplo n.º 47
0
        static unsafe void ProcessSocket(RioBufferSegment s, ServeState state) {
            uint current = 0;
            var r = s.CurrentContentLength;
            var reqs = 0;

            if (r == 0)
            {
                state.reader.Dispose();
                state.socket.Dispose();
                return;
            }

            for (int i = 0; state.leftoverLength != 0 && i < 4 - state.leftoverLength; i++)
            {
                current += s.DataPointer[i];
                current = current << 8;
                if (current == endOfRequest)
                    reqs++;
            }

            state.leftoverLength = r % 4;
            var length = r - state.leftoverLength;

            byte* currentPtr = s.DataPointer + state.oldleftoverLength;

            var start = currentPtr;
            var end = currentPtr + length;

            for (; start <= end; start++)
            {
                if (*(uint*)start == endOfRequest)
                    reqs++;
            }
            
            state.oldleftoverLength = state.leftoverLength;

            for (int i = r - state.leftoverLength; i < r; i++)
            {
                current += s.DataPointer[i];
                current = current << 4;
            }

            state.socket.Send(reqz[reqs]);
        }
Ejemplo n.º 48
0
 void SetInUse(RioBufferSegment buf, bool value)
 {
     buf.InUse = value;
 }
Ejemplo n.º 49
0
 public bool TryGetBuffer(out RioBufferSegment buf) => _availableSegments.TryDequeue(out buf);
Ejemplo n.º 50
0
 public void ReleaseBuffer(RioBufferSegment buffer)
 {
     SetInUse(buffer, false);
     _availableSegments.Enqueue(buffer);
 }
Ejemplo n.º 51
0
 void SetInUse(RioBufferSegment buf, bool value)
 {
     buf.InUse = value;
 }
Ejemplo n.º 52
0
 int GetNewSegment()
 {
     _nextInputSegment.GetResult();
     _currentContentLength = _nextInputSegment.CurrentContentLength;
     if (disposing || _currentContentLength == 0)
     {
         _nextInputSegment.Dispose();
         _currentInputSegment.Dispose();
         toCopy = 0;
         return 0;
     }
     else
     {
         _bytesReadInCurrentSegment = 0;
         _nextInputSegment = _socket.BeginReceive(Interlocked.Exchange(ref _currentInputSegment, _nextInputSegment));
         return CompleteRead();
     }
 }
Ejemplo n.º 53
0
 public bool TryGetBuffer(out RioBufferSegment buf) => _availableSegments.TryDequeue(out buf);
Ejemplo n.º 54
0
 public RioBufferSegment Send(RioBufferSegment Segment)
 {
     Debug.Assert(inUse);
     Send(Segment, RIO_SEND_FLAGS.NONE);
     return Segment;
 }
Ejemplo n.º 55
0
 public RioBufferSegment GetResult()
 {
     var res = _currentValue;
     _currentValue = null;
     return res;
 }
Ejemplo n.º 56
0
 public void ReleaseBuffer(RioBufferSegment buffer)
 {
     SetInUse(buffer, false);
     _availableSegments.Enqueue(buffer);
 }
Ejemplo n.º 57
0
        private void CompleteRead()
        {
            var toCopy = _currentContentLength - _bytesReadInCurrentSegment;
            if (toCopy > _readCount)
                toCopy = _readCount;

            unsafe
            {
                fixed (byte* p = &_readBuffer[_readoffset])
                    Buffer.MemoryCopy(_currentInputSegment.RawPointer + _bytesReadInCurrentSegment, p, _readCount, toCopy);
            }

            _bytesReadInCurrentSegment += toCopy;

            if (_currentContentLength == _bytesReadInCurrentSegment)
            {
                _currentInputSegment.Dispose();
                _currentInputSegment = null;
            }

            _readtcs.SetResult(toCopy);
        }
Ejemplo n.º 58
0
 public void ReleaseBuffer(RioBufferSegment buffer)
 {
     _availableSegments.Enqueue(buffer);
 }
Ejemplo n.º 59
0
 internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
         WinSock.ThrowLastWSAError();
 }
Ejemplo n.º 60
0
        public virtual RioBufferSegment BeginReceive(RioBufferSegment segment)
        {
            Debug.Assert(inUse);
            segment.SegmentPointer->Length = segment.TotalLength;
            segment.SetNotComplete();
            if (!RioStatic.Receive(_requestQueue, segment.SegmentPointer, 1, RIO_RECEIVE_FLAGS.NONE, segment.Index))
                WinSock.ThrowLastWSAError();

            return segment;
        }