Ejemplo n.º 1
0
        public string ReadString()
        {
            SemReadStream.Wait();
            byte[] inBuffer;
            try
            {
                int    len     = 0;
                byte[] lenbuff = new byte[4];
                _inputStream.Read(lenbuff, 0, 4);
                len      = ToInt(lenbuff);
                inBuffer = new byte[len];
                _inputStream.Read(inBuffer, 0, len);
            }
            finally
            {
                SemReadStream.Release();
            }


            return(_streamEncoding.GetString(inBuffer));
        }
Ejemplo n.º 2
0
        public async Task <string> ReadStringAsync(CancellationToken token)
        {
            int len = 0;

            byte[] lenbuff = new byte[4];
            byte[] inBuffer;
            await SemReadStream.WaitAsync(token);

            try
            {
                await _inputStream.ReadAsync(lenbuff, 0, 4, token);

                len      = ToInt(lenbuff);
                inBuffer = new byte[len];
                await _inputStream.ReadAsync(inBuffer, 0, len, token);
            }
            finally
            {
                SemReadStream.Release();
            }
            return(_streamEncoding.GetString(inBuffer));
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     SemWriteStream?.Dispose();
     SemReadStream?.Dispose();
 }