Refactored a few for HttpStreamAsyncResult.cs

This commit is contained in:
sta 2015-04-07 15:26:47 +09:00
parent 0a07e10c90
commit 8793576fba
2 changed files with 69 additions and 18 deletions

View File

@ -194,7 +194,7 @@ namespace WebSocketSharp.Net
if (!ares.IsCompleted)
ares.AsyncWaitHandle.WaitOne ();
if (ares.Error != null)
if (ares.HasException)
throw new HttpListenerException (400, "I/O operation aborted.");
return ares.Count;

View File

@ -46,27 +46,22 @@ namespace WebSocketSharp.Net
{
#region Private Fields
private byte[] _buffer;
private AsyncCallback _callback;
private bool _completed;
private int _count;
private Exception _exception;
private int _offset;
private object _state;
private object _sync;
private int _syncRead;
private ManualResetEvent _waitHandle;
#endregion
#region Internal Fields
#region Internal Constructors
internal byte [] Buffer;
internal int Count;
internal Exception Error;
internal int Offset;
internal int SyncRead;
#endregion
#region Public Constructors
public HttpStreamAsyncResult (AsyncCallback callback, object state)
internal HttpStreamAsyncResult (AsyncCallback callback, object state)
{
_callback = callback;
_state = state;
@ -75,6 +70,62 @@ namespace WebSocketSharp.Net
#endregion
#region Internal Properties
internal byte[] Buffer {
get {
return _buffer;
}
set {
_buffer = value;
}
}
internal int Count {
get {
return _count;
}
set {
_count = value;
}
}
internal Exception Exception {
get {
return _exception;
}
}
internal bool HasException {
get {
return _exception != null;
}
}
internal int Offset {
get {
return _offset;
}
set {
_offset = value;
}
}
internal int SyncRead {
get {
return _syncRead;
}
set {
_syncRead = value;
}
}
#endregion
#region Public Properties
public object AsyncState {
@ -92,7 +143,7 @@ namespace WebSocketSharp.Net
public bool CompletedSynchronously {
get {
return SyncRead == Count;
return _syncRead == _count;
}
}
@ -105,9 +156,9 @@ namespace WebSocketSharp.Net
#endregion
#region Public Methods
#region Internal Methods
public void Complete ()
internal void Complete ()
{
lock (_sync) {
if (_completed)
@ -122,9 +173,9 @@ namespace WebSocketSharp.Net
}
}
public void Complete (Exception exception)
internal void Complete (Exception exception)
{
Error = exception;
_exception = exception;
Complete ();
}