Beispiel #1
0
 internal async void RepeatAsyncRead()
 {
     //_socket.InputStream.ReadAsync(_buf.AsBuffer(), (uint)_buf.Length, Windows.Storage.Streams.InputStreamOptions.Partial).Completed = RepeatCallback;
     await Task.Run(async() => {
         while (true)
         {
             try {
                 IBuffer result = await _socket.InputStream.ReadAsync(_buf.AsBuffer(), (uint)_buf.Length, Windows.Storage.Streams.InputStreamOptions.Partial);
                 if (result.Length > 0)
                 {
                     //await _handler.OnData(_buf, 0, (int)result.Length);
                     _handler.OnData(_buf, 0, (int)result.Length);
                 }
                 else if (result.Length < 0)
                 {
                     //await _handler.OnData(_buf, 0, (int)result.Length*-1);
                     _handler.OnData(_buf, 0, (int)result.Length * -1);
                 }
                 else
                 {
                     _handler.OnClosed();
                     return;
                 }
             }
             catch (Exception ex) {
                 if (!_closed)
                 {
                     _handler.OnError(ex, ex.Message);
                 }
                 else
                 {
                     _handler.OnClosed();
                 }
                 return;
             }
         }
     });
 }
Beispiel #2
0
 public void OnChannelEOF()
 {
     _handler.OnClosed();
 }