상속: IDisposable
예제 #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;
         }
     }
 }
예제 #2
0
 public void Dispose()
 {
     _currentValue?.Dispose();
     _currentValue = null;
     if (_continuation != null)
         _continuation();
 }
예제 #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;
         }
     }
 }
예제 #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();
            }
        }
예제 #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();
            }
        }
예제 #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();

            
        }
예제 #7
0
 public RioSegmentReader(RioSocket socket)
 {
     _socket              = socket;
     _nextInputSegment    = _socket.ReceiveBufferPool.GetBuffer();
     _currentInputSegment = _socket.ReceiveBufferPool.GetBuffer();
     completeReadDelegate = CompleteRead;
 }
예제 #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;
         }
     }
 }
예제 #9
0
 public RioSegmentReader(RioSocket socket)
 {
     _socket = socket;
     _nextInputSegment = _socket.ReceiveBufferPool.GetBuffer();
     _currentInputSegment = _socket.ReceiveBufferPool.GetBuffer();
     completeReadDelegate = CompleteRead;
 }
예제 #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);
        }
예제 #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();
            }
        }
예제 #12
0
 internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
     {
         WinSock.ThrowLastWSAError();
     }
 }
예제 #13
0
        public RioBufferSegment GetResult()
        {
            var res = _currentValue;

            _currentValue = null;
            return(res);
        }
예제 #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;
                }

            }
        }
예제 #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();
        }
예제 #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();
     }
 }
예제 #17
0
 public void WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
             WinSock.ThrowLastWSAError();
     }
 }
예제 #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();
     }
 }
예제 #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();
 }
예제 #20
0
 public RioStream(RioConnectionOrientedSocket socket)
 {
     _socket = socket;
     _currentInputSegment = null;
     _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
     _getNewSegmentDelegate = GetNewSegment;
     socket.OnIncommingSegment = s => _incommingSegments.Set(s);
     socket.ReciveInternal();
 }
예제 #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();
 }
예제 #22
0
 public void Dispose()
 {
     _currentValue?.Dispose();
     _currentValue = null;
     if (_continuation != null)
     {
         _continuation();
     }
 }
예제 #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);
        }
예제 #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;
 }
예제 #27
0
 public void WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
         {
             WinSock.ThrowLastWSAError();
         }
     }
 }
예제 #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);
        }
예제 #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);
        }
예제 #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;
 }
예제 #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);
 }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
            }
        }
예제 #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);
            }
        }
예제 #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);
            }
        }
예제 #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());
     }
 }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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;
        }
예제 #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);
            }
        }
예제 #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);
            }
        }
예제 #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();
            }
        }
예제 #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();
            }
        }
예제 #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();
        }
예제 #47
0
파일: Program.cs 프로젝트: aL3891/RioSharp
        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]);
        }
예제 #48
0
 void SetInUse(RioBufferSegment buf, bool value)
 {
     buf.InUse = value;
 }
예제 #49
0
 public bool TryGetBuffer(out RioBufferSegment buf) => _availableSegments.TryDequeue(out buf);
예제 #50
0
 public void ReleaseBuffer(RioBufferSegment buffer)
 {
     SetInUse(buffer, false);
     _availableSegments.Enqueue(buffer);
 }
예제 #51
0
 void SetInUse(RioBufferSegment buf, bool value)
 {
     buf.InUse = value;
 }
예제 #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();
     }
 }
예제 #53
0
 public bool TryGetBuffer(out RioBufferSegment buf) => _availableSegments.TryDequeue(out buf);
예제 #54
0
 public RioBufferSegment Send(RioBufferSegment Segment)
 {
     Debug.Assert(inUse);
     Send(Segment, RIO_SEND_FLAGS.NONE);
     return Segment;
 }
예제 #55
0
 public RioBufferSegment GetResult()
 {
     var res = _currentValue;
     _currentValue = null;
     return res;
 }
예제 #56
0
 public void ReleaseBuffer(RioBufferSegment buffer)
 {
     SetInUse(buffer, false);
     _availableSegments.Enqueue(buffer);
 }
예제 #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);
        }
예제 #58
0
 public void ReleaseBuffer(RioBufferSegment buffer)
 {
     _availableSegments.Enqueue(buffer);
 }
예제 #59
0
 internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
         WinSock.ThrowLastWSAError();
 }
예제 #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;
        }