Exemplo n.º 1
0
        public IAsyncResult BeginReadValue(long size, AsyncCallback callback, object state)
        {
            AsyncNetworkOperation asyncNetIO = new AsyncNetworkOperation(callback, state, NetworkOperation.ReadValue);
            asyncNetIO.ValueSizeToRead = size;
            //
            // Check whether we already have a command in our buffer
            //
            if (_dataStream.Length > 0) {

                byte[] possibleValue = TryReadValue(_dataStream, size);
                if (possibleValue != null) {
                    //
                    // We already have a command in our buffer. No need to fire off another read
                    asyncNetIO.SetCompleted(possibleValue, null);
                    return asyncNetIO;
                }
            }
            _socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, ReadCallback, asyncNetIO);
            return asyncNetIO;
        }
Exemplo n.º 2
0
        public IAsyncResult BeginReadLine(AsyncCallback callback, object state)
        {
            AsyncNetworkOperation asyncNetIO = new AsyncNetworkOperation(callback, state, NetworkOperation.ReadLine);
            //
            // Check whether we already have a command in our buffer
            //
            if (_dataStream.Length >0 ) {

                string possibleCommand = TryReadLine(_dataStream);
                if (possibleCommand != null) {
                    //
                    // We already have a command in our buffer. No need to fire off another read
                    asyncNetIO.SetCompleted(possibleCommand, null);
                    return asyncNetIO;
                }
            }

            _socket.BeginReceive(_buffer,0,  _buffer.Length, SocketFlags.None, ReadCallback,asyncNetIO);
            return asyncNetIO;
        }