コード例 #1
0
        public SynchronizedDataSocket(IDataSocket dataSocket)
        {
            DataSocket = dataSocket;
            AsyncLock = new FifoAsyncLock();

            _disposeLock = new object();
            _isDisposed = false;
            _cancellationTokenSource = new CancellationTokenSource();
        }
 public HttpResponseStream(DefaultMazeResponse response, MazeRequest request, IDataSocket socket,
                           int packageBufferSize, int maxHeaderSize, CancellationToken requestCancellationToken)
 {
     _response                 = response;
     _request                  = request;
     _socket                   = socket;
     _packageBufferSize        = packageBufferSize;
     _maxHeaderSize            = maxHeaderSize;
     _requestCancellationToken = requestCancellationToken;
 }
コード例 #3
0
ファイル: HttpResponseStream.cs プロジェクト: 5l1v3r1/Maze-1
 public HttpResponseStream(DefaultMazeResponse response, MazeRequest request, IDataSocket socket,
                           int packageBufferSize, int maxHeaderSize, ArrayPool <byte> bufferPool, CancellationToken requestCancellationToken)
 {
     _response                 = response;
     _request                  = request;
     _socket                   = socket;
     _packageBufferSize        = packageBufferSize;
     _maxHeaderSize            = maxHeaderSize;
     _bufferPool               = bufferPool;
     _requestCancellationToken = requestCancellationToken;
     _customOffset             = socket.RequiredPreBufferLength ?? 0;
 }
コード例 #4
0
        public IDataSocket handle()
        {
            IDataSocket nsocket = null;

            lock (olock)
            {
                if (newsockets.Count > 0)
                {
                    nsocket = newsockets[0];
                    newsockets.RemoveAt(0);
                }
            }
            return(nsocket);
        }
コード例 #5
0
 public void acceptConnection(object sender, SocketAsyncEventArgs e)
 {
     if (e.SocketError == SocketError.Success)
     {
         Socket s = asyncevent.AcceptSocket;
         if (s != null)
         {
             dataSocket = new NetSocketDataSocket(s);
             state      = 2;
         }
         else
         {
             state = 0;
         }
     }
     else
     {
     }
 }
コード例 #6
0
        public void Handle()
        {
            if (socket != null)
            {
                socket.handle();

                while (true)
                {
                    var msg = socket.getMessage();
                    if (msg != null)
                    {
                        BinaryReader reader = new BinaryReader(new MemoryStream(msg));
                        uint         cmd    = reader.ReadUInt32();
                        router.Handle(this, 0, cmd, reader);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                if (ClientSocket != null)
                {
                    if (ClientSocket.isError())
                    {
                        OnError?.Invoke();
                        ClientSocket = null;
                    }
                    else
                    {
                        socket = ClientSocket.handle();
                        if (socket != null && OnConnected != null)
                        {
                            OnConnected();
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: MazeServer.cs プロジェクト: 5l1v3r1/Maze-1
        public MazeServer(IDataSocket socket, int packageBufferSize, int maxHeaderSize, ArrayPool <byte> bufferPool)
        {
            if (packageBufferSize < 6)
            {
                throw new ArgumentException("Package buffer size must be greater than 6", nameof(packageBufferSize));
            }

            if (maxHeaderSize < 100)
            {
                throw new ArgumentException("Max header size must be greater than 100", nameof(packageBufferSize));
            }

            if (packageBufferSize < maxHeaderSize)
            {
                throw new ArgumentException("Package buffer size must be greater than max header size", nameof(packageBufferSize));
            }

            _socket            = socket ?? throw new ArgumentNullException(nameof(socket));
            _bufferPool        = bufferPool ?? throw new ArgumentNullException(nameof(bufferPool));
            _packageBufferSize = packageBufferSize - 5;
            _maxHeaderSize     = maxHeaderSize;
            _customOffset      = socket.RequiredPreBufferLength ?? 0;

            _channels            = new ConcurrentDictionary <int, DataChannelInfo>();
            _activeRequests      = new ConcurrentDictionary <int, BufferQueueStream>();
            _activeResponses     = new ConcurrentDictionary <int, BufferQueueStream>();
            _waitingRequests     = new ConcurrentDictionary <int, TaskCompletionSource <HttpResponseMessage> >();
            _cancellableRequests = new ConcurrentDictionary <int, CancellationTokenSource>();
            _channelRedirects    = new ConcurrentDictionary <int, SynchronizedDataSocket>();

            socket.DataReceivedEventArgs += SocketOnDataReceivedEventArgs;

            if (Logger.IsTraceEnabled())
            {
                socket.DataReceivedEventArgs += (sender, args) =>
                                                Logger.Trace("Data received with Message Opcode {opcode}", args.Opcode);
            }
        }
コード例 #8
0
ファイル: MazeServer.cs プロジェクト: 5l1v3r1/Maze-1
 public void AddChannelRedirect(int channelId, IDataSocket targetSocket)
 {
     _channelRedirects.TryAdd(channelId, new SynchronizedDataSocket(targetSocket));
 }
コード例 #9
0
ファイル: MazeServer.cs プロジェクト: 5l1v3r1/Maze-1
 public MazeServer(IDataSocket socket) : this(socket, 8192, 4096, ArrayPool <byte> .Shared)
 {
 }