public override int EndRead(IAsyncResult ar) { var s = socket; Debug.WriteLine(String.Format("NS ({0}): EndRead ({1})", s == null ? "<unknown>" : s.InternalRemoteEndPoint.ToString(), ar == null ? "<unknown>" : ar.GetType().Name)); int res = 0; CheckDisposed(); if (ar == null) { throw new ArgumentNullException("async result is null"); } if (s == null) { throw new IOException("Connection closed"); } try { res = s.EndReceive(ar); } catch (Exception e) { throw new IOException("EndRead failure", e); } return(res); }
public override int EndRead(IAsyncResult asyncResult) { Debug.Write(String.Format("BNS ({0}): EndRead ({1}) [m_inputBuffer_pos = {2}, m_inputBuffer_read_ahead = {3}]", NetworkStream.InternalSocket.InternalRemoteEndPoint, asyncResult == null ? "<unknown>" : asyncResult.GetType().Name, m_inputBuffer_pos, m_inputBuffer_read_ahead)); try { if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } var rar = asyncResult as ReadAsyncResult; if (rar != null) { if (rar.EndReadCalled) { throw new InvalidOperationException("EndRead was already called"); } rar.EndReadCalled = true; if (!rar.IsCompleted) { rar.AsyncWaitHandle.Wait(); } Debug.Write(String.Format(" returns {0}", rar.DataReceived)); return(rar.DataReceived); } var rsr = asyncResult as ReadSyncResult; if (rsr != null) { if (rsr.EndReadCalled) { throw new InvalidOperationException("EndRead was already called"); } rsr.EndReadCalled = true; Debug.Write(String.Format(" returns {0}", rsr.DataReceived)); return(rsr.DataReceived); } } finally { Debug.WriteLine(String.Empty); } return(m_stream.EndRead(asyncResult)); }
public override void EndWrite(IAsyncResult asyncResult) { Debug.WriteLine("BNS ({0}): EndWrite ({1}) [m_outputBuffer_pos = {2}]", NetworkStream.InternalSocket.InternalRemoteEndPoint, asyncResult == null ? "<unknown>" : asyncResult.GetType().Name, m_outputBuffer_pos); if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } var wsr = asyncResult as WriteSyncResult; if (wsr != null) { if (wsr.EndWriteCalled) { throw new InvalidOperationException("EndWrite was already called"); } wsr.EndWriteCalled = true; return; } var war = asyncResult as WriteAsyncResult; if (war != null) { if (war.EndWriteCalled) { throw new InvalidOperationException("EndWrite was already called"); } war.EndWriteCalled = true; if (!war.IsCompleted) { war.AsyncWaitHandle.Wait(); } return; } m_stream.EndWrite(asyncResult); }
public override void EndWrite(IAsyncResult ar) { var s = socket; Debug.WriteLine("NS ({0}): EndWrite ({1}) ", s == null ? "<unknown>" : s.InternalRemoteEndPoint.ToString(), ar == null ? "<unknown>" : ar.GetType().Name); CheckDisposed(); if (ar == null) { throw new ArgumentNullException("async result is null"); } if (s == null) { throw new IOException("Connection closed"); } try { s.EndSend(ar); } catch (Exception e) { throw new IOException("EndWrite failure", e); } }