private void ReadCallback(IAsyncResult ar) { BeginReceiveDelegate asyncState = (BeginReceiveDelegate)ar.AsyncState; if ((this.m_socket == null) || (this.m_sslStream == null)) { if (asyncState != null) { asyncState(0); } } else { try { int bytesReceived = this.m_sslStream.EndRead(ar); if (asyncState != null) { asyncState(bytesReceived); } } catch (Exception exception) { object[] args = new object[] { exception }; s_log.LogWarning("Exception while trying to call EndRead. {0}", args); if (asyncState != null) { asyncState(0); } } } }
public void BeginReceive(byte[] buffer, int size, BeginReceiveDelegate beginReceiveDelegate) { try { if (this.m_sslStream == null) { throw new NullReferenceException("m_sslStream is null!"); } this.m_sslStream.BeginRead(buffer, 0, size, new AsyncCallback(this.ReadCallback), beginReceiveDelegate); } catch (Exception exception) { object[] args = new object[] { exception }; s_log.LogWarning("Exception while trying to call BeginRead. {0}", args); if (beginReceiveDelegate != null) { beginReceiveDelegate(0); } } }