[Mono-dev] HttpListener
Greg Young
gregoryyoung1 at gmail.com
Wed Dec 5 13:52:24 UTC 2012
I was in looking at some code today in httplistener and didn't understand
some of the stuff going on (was hitting a performance penalty due to it).
In particular I was a bit confused when looking at Begin and EndGetContext
(included below).. It would seem harmful to call ares.Complete below while
holding a lock to wait_queue. I just wanted to see what someone may have
been thinking before spending time on a patch
public IAsyncResult BeginGetContext (AsyncCallback callback, Object state)
{
CheckDisposed ();
if (!listening)
throw new InvalidOperationException ("Please, call Start before
using this method.");
ListenerAsyncResult ares = new ListenerAsyncResult (callback, state);
// lock wait_queue early to avoid race conditions
lock (wait_queue) {
lock (ctx_queue) {
HttpListenerContext ctx = GetContextFromQueue ();
if (ctx != null) {
ares.Complete (ctx, true);
return ares;
}
}
wait_queue.Add (ares);
}
return ares;
}
public HttpListenerContext EndGetContext (IAsyncResult asyncResult)
{
CheckDisposed ();
if (asyncResult == null)
throw new ArgumentNullException ("asyncResult");
ListenerAsyncResult ares = asyncResult as ListenerAsyncResult;
if (ares == null)
throw new ArgumentException ("Wrong IAsyncResult.", "asyncResult");
if (!ares.IsCompleted)
ares.AsyncWaitHandle.WaitOne ();
lock (wait_queue) {
int idx = wait_queue.IndexOf (ares);
if (idx >= 0)
wait_queue.RemoveAt (idx);
}
HttpListenerContext context = ares.GetContext ();
context.ParseAuthentication (SelectAuthenticationScheme (context));
return context; // This will throw on error.
}
--
Le doute n'est pas une condition agréable, mais la certitude est absurde.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20121205/d4faccab/attachment-0001.html>
More information about the Mono-devel-list
mailing list