提交 a989b3d7 编写于 作者: L Lakshmi Priya Sekar

Use resource strings for unix exceptions.


Commit migrated from https://github.com/dotnet/corefx/commit/cf37dbd8b73a26012ae045054b8abd127b8fd585
上级 34559edd
......@@ -387,4 +387,22 @@
<data name="offset_out_of_range" xml:space="preserve">
<value>Offset exceeds the length of buffer.</value>
</data>
<data name="net_io_operation_aborted" xml:space="preserve">
<value>I/O operation aborted: '{0}'.</value>
</data>
<data name="net_invalid_path" xml:space="preserve">
<value>Invalid path.</value>
</data>
<data name="net_no_client_certificate" xml:space="preserve">
<value>Client certificate not found.</value>
</data>
<data name="net_listener_auth_errors" xml:space="preserve">
<value>Authentication errors.</value>
</data>
<data name="net_listener_close" xml:space="preserve">
<value>Listener closed.</value>
</data>
<data name="net_invalid_port" xml:space="preserve">
<value>Invalid port in prefix.</value>
</data>
</root>
\ No newline at end of file
......@@ -95,8 +95,8 @@ public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, Asy
throw new ArgumentOutOfRangeException(nameof(count), SR.offset_out_of_range);
HttpStreamAsyncResult ares = new HttpStreamAsyncResult();
ares.Callback = cback;
ares.State = state;
ares._callback = cback;
ares._state = state;
if (_no_more_data)
{
ares.Complete();
......@@ -108,23 +108,23 @@ public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, Asy
if (count == 0)
{
// got all we wanted, no need to bother the decoder yet
ares.Count = nread;
ares._count = nread;
ares.Complete();
return ares;
}
if (!_decoder.WantMore)
{
_no_more_data = nread == 0;
ares.Count = nread;
ares._count = nread;
ares.Complete();
return ares;
}
ares.Buffer = new byte[8192];
ares.Offset = 0;
ares.Count = 8192;
ares._buffer = new byte[8192];
ares._offset = 0;
ares._count = 8192;
ReadBufferState rb = new ReadBufferState(buffer, offset, count, ares);
rb.InitialCount += nread;
base.BeginRead(ares.Buffer, ares.Offset, ares.Count, OnRead, rb);
base.BeginRead(ares._buffer, ares._offset, ares._count, OnRead, rb);
return ares;
}
......@@ -135,20 +135,20 @@ private void OnRead(IAsyncResult base_ares)
try
{
int nread = base.EndRead(base_ares);
_decoder.Write(ares.Buffer, ares.Offset, nread);
_decoder.Write(ares._buffer, ares._offset, nread);
nread = _decoder.Read(rb.Buffer, rb.Offset, rb.Count);
rb.Offset += nread;
rb.Count -= nread;
if (rb.Count == 0 || !_decoder.WantMore || nread == 0)
{
_no_more_data = !_decoder.WantMore && nread == 0;
ares.Count = rb.InitialCount - rb.Count;
ares._count = rb.InitialCount - rb.Count;
ares.Complete();
return;
}
ares.Offset = 0;
ares.Count = Math.Min(8192, _decoder.ChunkLeft + 6);
base.BeginRead(ares.Buffer, ares.Offset, ares.Count, OnRead, rb);
ares._offset = 0;
ares._count = Math.Min(8192, _decoder.ChunkLeft + 6);
base.BeginRead(ares._buffer, ares._offset, ares._count, OnRead, rb);
}
catch (Exception e)
{
......@@ -157,22 +157,22 @@ private void OnRead(IAsyncResult base_ares)
}
}
public override int EndRead(IAsyncResult ares)
public override int EndRead(IAsyncResult asyncResult)
{
if (_disposed)
throw new ObjectDisposedException(GetType().ToString());
HttpStreamAsyncResult my_ares = ares as HttpStreamAsyncResult;
if (ares == null)
throw new ArgumentException("Invalid IAsyncResult", "ares");
HttpStreamAsyncResult ares = asyncResult as HttpStreamAsyncResult;
if (asyncResult == null)
throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
if (!ares.IsCompleted)
ares.AsyncWaitHandle.WaitOne();
if (!asyncResult.IsCompleted)
asyncResult.AsyncWaitHandle.WaitOne();
if (my_ares.Error != null)
throw new HttpListenerException(400, "I/O operation aborted: " + my_ares.Error.Message);
if (ares._error != null)
throw new HttpListenerException(400, SR.Format(SR.net_io_operation_aborted, ares._error.Message));
return my_ares.Count;
return ares._count;
}
public override void Close()
......
......@@ -242,7 +242,7 @@ private HttpListener MatchFromList(string host, string path, List<ListenerPrefix
if (path.StartsWith(ppath))
{
bestLength = ppath.Length;
bestMatch = p.Listener;
bestMatch = p._listener;
prefix = p;
}
}
......@@ -321,7 +321,7 @@ public void AddPrefix(ListenerPrefix prefix, HttpListener listener)
{
current = _unhandledPrefixes;
future = current != null ? new List<ListenerPrefix>(current) : new List<ListenerPrefix>();
prefix.Listener = listener;
prefix._listener = listener;
AddSpecial(future, prefix);
} while (Interlocked.CompareExchange(ref _unhandledPrefixes, future, current) != current);
return;
......@@ -333,7 +333,7 @@ public void AddPrefix(ListenerPrefix prefix, HttpListener listener)
{
current = _allPrefixes;
future = current != null ? new List<ListenerPrefix>(current) : new List<ListenerPrefix>();
prefix.Listener = listener;
prefix._listener = listener;
AddSpecial(future, prefix);
} while (Interlocked.CompareExchange(ref _allPrefixes, future, current) != current);
return;
......
......@@ -78,10 +78,10 @@ private static void AddPrefixInternal(string p, HttpListener listener)
{
ListenerPrefix lp = new ListenerPrefix(p);
if (lp.Path.IndexOf('%') != -1)
throw new HttpListenerException(400, "Invalid path.");
throw new HttpListenerException(400, SR.net_invalid_path);
if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1)
throw new HttpListenerException(400, "Invalid path.");
throw new HttpListenerException(400, SR.net_invalid_path);
// listens on all the interfaces if host name cannot be parsed by IPAddress.
HttpEndPointListener epl = GetEPListener(lp.Host, lp.Port, listener, lp.Secure);
......
......@@ -336,12 +336,12 @@ public HttpListenerContext EndGetContext(IAsyncResult asyncResult)
{
throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
}
if (ares.EndCalled)
if (ares._endCalled)
{
throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, nameof(EndGetContext)));
}
ares.EndCalled = true;
ares._endCalled = true;
if (!ares.IsCompleted)
ares.AsyncWaitHandle.WaitOne();
......@@ -376,7 +376,7 @@ public HttpListenerContext GetContext()
}
ListenerAsyncResult ares = (ListenerAsyncResult)BeginGetContext(null, null);
ares.InGet = true;
ares._inGet = true;
return EndGetContext(ares);
}
......
......@@ -106,7 +106,7 @@ public bool Remove(string uriPrefix)
{
_listener.CheckDisposed();
if (uriPrefix == null)
throw new ArgumentNullException("uriPrefix");
throw new ArgumentNullException(nameof(uriPrefix));
bool result = _prefixes.Remove(uriPrefix);
if (result && _listener.IsListening)
......
......@@ -72,7 +72,7 @@ public override ChannelBinding GetChannelBinding(ChannelBindingKind kind)
private bool _ka_set;
private bool _keep_alive;
private delegate X509Certificate2 GCCDelegate();
private GCCDelegate _gcc_delegate;
private GCCDelegate _gccDelegate;
private static byte[] s_100continue = Encoding.ASCII.GetBytes("HTTP/1.1 100 Continue\r\n\r\n");
......@@ -437,7 +437,7 @@ public int ClientCertificateError
{
HttpConnection cnc = _context.Connection;
if (cnc.ClientCertificate == null)
throw new InvalidOperationException("No client certificate");
throw new InvalidOperationException(SR.net_no_client_certificate);
int[] errors = cnc.ClientCertificateErrors;
if (errors != null && errors.Length > 0)
return errors[0];
......@@ -613,20 +613,20 @@ public string[] UserLanguages
public IAsyncResult BeginGetClientCertificate(AsyncCallback requestCallback, object state)
{
if (_gcc_delegate == null)
_gcc_delegate = new GCCDelegate(GetClientCertificate);
return _gcc_delegate.BeginInvoke(requestCallback, state);
if (_gccDelegate == null)
_gccDelegate = new GCCDelegate(GetClientCertificate);
return _gccDelegate.BeginInvoke(requestCallback, state);
}
public X509Certificate2 EndGetClientCertificate(IAsyncResult asyncResult)
{
if (asyncResult == null)
throw new ArgumentNullException("asyncResult");
throw new ArgumentNullException(nameof(asyncResult));
if (_gcc_delegate == null)
if (_gccDelegate == null)
throw new InvalidOperationException();
return _gcc_delegate.EndInvoke(asyncResult);
return _gccDelegate.EndInvoke(asyncResult);
}
public X509Certificate2 GetClientCertificate()
......
......@@ -156,12 +156,12 @@ public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, Asy
if (nread > 0 || nread == -1)
{
HttpStreamAsyncResult ares = new HttpStreamAsyncResult();
ares.Buffer = buffer;
ares.Offset = offset;
ares.Count = count;
ares.Callback = cback;
ares.State = state;
ares.SynchRead = Math.Max(0, nread);
ares._buffer = buffer;
ares._offset = offset;
ares._count = count;
ares._callback = cback;
ares._state = state;
ares._synchRead = Math.Max(0, nread);
ares.Complete();
return ares;
}
......@@ -189,10 +189,9 @@ public override int EndRead(IAsyncResult asyncResult)
HttpStreamAsyncResult r = (HttpStreamAsyncResult)asyncResult;
if (!asyncResult.IsCompleted)
asyncResult.AsyncWaitHandle.WaitOne();
return r.SynchRead;
return r._synchRead;
}
// Close on exception?
int nread = _stream.EndRead(asyncResult);
if (_remainingBody > 0 && nread > 0)
{
......
......@@ -39,17 +39,17 @@ internal class HttpStreamAsyncResult : IAsyncResult
private ManualResetEvent _handle;
private bool _completed;
internal byte[] Buffer;
internal int Offset;
internal int Count;
internal AsyncCallback Callback;
internal object State;
internal int SynchRead;
internal Exception Error;
internal byte[] _buffer;
internal int _offset;
internal int _count;
internal AsyncCallback _callback;
internal object _state;
internal int _synchRead;
internal Exception _error;
public void Complete(Exception e)
{
Error = e;
_error = e;
Complete();
}
......@@ -64,14 +64,14 @@ public void Complete()
if (_handle != null)
_handle.Set();
if (Callback != null)
Callback.BeginInvoke(this, null, null);
if (_callback != null)
_callback.BeginInvoke(this, null, null);
}
}
public object AsyncState
{
get { return State; }
get { return _state; }
}
public WaitHandle AsyncWaitHandle
......@@ -90,7 +90,7 @@ public WaitHandle AsyncWaitHandle
public bool CompletedSynchronously
{
get { return (SynchRead == Count); }
get { return (_synchRead == _count); }
}
public bool IsCompleted
......
......@@ -46,8 +46,8 @@ internal class ListenerAsyncResult : IAsyncResult
private HttpListenerContext _context;
private object _locker = new object();
private ListenerAsyncResult _forward;
internal bool EndCalled;
internal bool InGet;
internal bool _endCalled;
internal bool _inGet;
public ListenerAsyncResult(AsyncCallback cb, object state)
{
......@@ -63,8 +63,8 @@ internal void Complete(Exception exc)
return;
}
_exception = exc;
if (InGet && (exc is ObjectDisposedException))
_exception = new HttpListenerException(500, "Listener closed");
if (_inGet && (exc is ObjectDisposedException))
_exception = new HttpListenerException(500, SR.net_listener_close);
lock (_locker)
{
_completed = true;
......@@ -87,7 +87,7 @@ private static void InvokeCallback(object o)
}
try
{
ares.cb(ares);
ares._cb(ares);
}
catch
{
......@@ -127,7 +127,7 @@ internal void Complete(HttpListenerContext context, bool synch)
for (int i = 0; next._forward != null; i++)
{
if (i > 20)
Complete(new HttpListenerException(400, "Too many authentication errors"));
Complete(new HttpListenerException(400, SR.net_listener_auth_errors));
next = next._forward;
}
}
......
......@@ -40,7 +40,7 @@ internal sealed class ListenerPrefix
private string _path;
private bool _secure;
private IPAddress[] _addresses;
public HttpListener Listener;
internal HttpListener _listener;
public ListenerPrefix(string prefix)
{
......@@ -70,7 +70,7 @@ public string Host
public int Port
{
get { return (int)_port; }
get { return _port; }
}
public string Path
......@@ -105,7 +105,7 @@ private void Parse(string uri)
int length = uri.Length;
int start_host = uri.IndexOf(':') + 3;
if (start_host >= length)
throw new ArgumentException("No host specified.");
throw new ArgumentException(SR.net_listener_host);
int colon = uri.IndexOf(':', start_host, length - start_host);
int root;
......@@ -113,7 +113,7 @@ private void Parse(string uri)
{
_host = uri.Substring(start_host, colon - start_host);
root = uri.IndexOf('/', colon, length - colon);
_port = (ushort)Int32.Parse(uri.Substring(colon + 1, root - colon - 1));
_port = (ushort)int.Parse(uri.Substring(colon + 1, root - colon - 1));
_path = uri.Substring(root);
}
else
......@@ -133,44 +133,44 @@ public static void CheckUri(string uri)
throw new ArgumentNullException("uriPrefix");
if (!uri.StartsWith("http://") && !uri.StartsWith("https://"))
throw new ArgumentException("Only 'http' and 'https' schemes are supported.");
throw new ArgumentException(SR.net_listener_scheme);
int length = uri.Length;
int start_host = uri.IndexOf(':') + 3;
if (start_host >= length)
throw new ArgumentException("No host specified.");
throw new ArgumentException(SR.net_listener_host);
int colon = uri.IndexOf(':', start_host, length - start_host);
if (start_host == colon)
throw new ArgumentException("No host specified.");
throw new ArgumentException(SR.net_listener_host);
int root;
if (colon > 0)
{
root = uri.IndexOf('/', colon, length - colon);
if (root == -1)
throw new ArgumentException("No path specified.");
throw new ArgumentException(SR.net_invalid_path);
try
{
int p = Int32.Parse(uri.Substring(colon + 1, root - colon - 1));
int p = int.Parse(uri.Substring(colon + 1, root - colon - 1));
if (p <= 0 || p >= 65536)
throw new Exception();
throw new ArgumentException(SR.net_invalid_port);
}
catch
{
throw new ArgumentException("Invalid port.");
throw new ArgumentException(SR.net_invalid_port);
}
}
else
{
root = uri.IndexOf('/', start_host, length - start_host);
if (root == -1)
throw new ArgumentException("No path specified.");
throw new ArgumentException(SR.net_invalid_path);
}
if (uri[uri.Length - 1] != '/')
throw new ArgumentException("The prefix must end with '/'");
throw new ArgumentException(SR.net_listener_slash);
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册