Shadowsocks.Util.Sockets.WrappedSocket.EndReceive C# (CSharp) Méthode

EndReceive() public méthode

public EndReceive ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult
Résultat int
        public int EndReceive(IAsyncResult asyncResult)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (!Connected)
            {
                throw new SocketException((int) SocketError.NotConnected);
            }

            return _activeSocket.EndReceive(asyncResult);
        }

Usage Example

Exemple #1
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            int length = (int)ar.AsyncState;

            try
            {
                var bytesRead = _socket.EndReceive(ar);

                if (bytesRead == 0)
                {
                    OnFinish(length);
                    return;
                }

                length += bytesRead;

                int i;
                while ((i = IndexOf(_lineBuffer, _bufferIndex, length, _delimiterBytes, _delimiterSearchOffsetTable,
                                    _delimiterSearchCharTable)) != -1)
                {
                    var    decodeLen = i - _bufferIndex;
                    string line      = _encoding.GetString(_lineBuffer, _bufferIndex, decodeLen);

                    _bufferIndex = i + _delimiterBytes.Length;
                    length      -= decodeLen;
                    length      -= _delimiterBytes.Length;

                    var stop = _onLineRead(line, _state);
                    if (stop)
                    {
                        OnFinish(length);
                        return;
                    }
                }
                if (length == _lineBuffer.Length)
                {
                    OnException(new IndexOutOfRangeException("LineBuffer full! Try increace maxLineBytes!"));
                    OnFinish(length);

                    return;
                }

                if (_bufferIndex > 0)
                {
                    Buffer.BlockCopy(_lineBuffer, _bufferIndex, _lineBuffer, 0, length);
                    _bufferIndex = 0;
                }

                _socket.BeginReceive(_lineBuffer, length, _lineBuffer.Length - length, 0, ReceiveCallback, length);
            }
            catch (Exception ex)
            {
                OnException(ex);
                OnFinish(length);
            }
        }
All Usage Examples Of Shadowsocks.Util.Sockets.WrappedSocket::EndReceive