示例#1
0
        protected DnsUdpContext CreateContext()
        {
            DnsUdpContext context = m_contextPool.Get();

            if (context == null)
            {
                context = new DnsUdpContext();
            }
            context.Init();

            return(context);
        }
示例#2
0
        void ReceiveCompleted(object sender, SocketAsyncEventArgs args)
        {
            bool          synchronousCompletion = true;
            DnsUdpContext context = null;

            try
            {
                int         countRead      = args.BytesTransferred;
                SocketError socketError    = args.SocketError;
                IPEndPoint  remoteEndpoint = (IPEndPoint)args.RemoteEndPoint;
                context = (DnsUdpContext)args.UserToken;
                //
                // Release the accept throttle so the listener thread can resume accepting connections
                //
                if (sender != null)
                {
                    base.AcceptCompleted(args); //async completion. Free the args..
                }
                else
                {
                    this.ReleaseAsyncArgs(args);
                }

                if (socketError == SocketError.Success && countRead > 0)
                {
                    context.BytesTransfered = countRead;
                    context.RemoteEndPoint  = remoteEndpoint;
                    synchronousCompletion   = m_requestHandler.Process(context);
                    //
                    // If completion is async, handler will call ProcessingComplete
                    //
                }
            }
            catch (SocketException)
            {
                //
                // Eat socket exceptions silently, as they happen all the time - often when the other
                // party does something abrupt
                //
            }
            catch (Exception ex)
            {
                base.NotifyError(ex);
            }
            finally
            {
                if (synchronousCompletion)
                {
                    this.ProcessingComplete(context);
                }
            }
        }
示例#3
0
 public void ProcessingComplete(DnsUdpContext context)
 {
     try
     {
         if (context != null)
         {
             this.ReleaseContext(context);
         }
     }
     catch (Exception ex)
     {
         this.NotifyError(ex);
     }
     finally
     {
         base.ProcessingComplete();
     }
 }
示例#4
0
        protected override void StartAccept()
        {
            SocketAsyncEventArgs args = base.CreateAsyncArgs(this.AllocNewAsyncArgs);

            args.RemoteEndPoint = m_fromAny;

            DnsUdpContext context = this.CreateContext();

            context.Socket = this.Socket;

            args.SetBuffer(context.DnsBuffer.Buffer, 0, context.DnsBuffer.Capacity);
            args.UserToken = context;

            if (!this.Socket.ReceiveFromAsync(args))
            {
                //
                // Call completed synchronously. Force async
                //
                base.ForceAsyncAccept(args);
                base.AcceptCompleted();
            }
        }
示例#5
0
 void ReleaseContext(DnsUdpContext context)
 {
     context.Reset();
     m_contextPool.Put(context);
 }
示例#6
0
 public void ProcessingComplete(DnsUdpContext context)
 {
     try
     {
         if (context != null)
         {
             this.ReleaseContext(context);
         }
     }
     catch(Exception ex)
     {
         this.NotifyError(ex);
     }
     finally
     {
         base.ProcessingComplete();
     }
 }
示例#7
0
 protected DnsUdpContext CreateContext()
 {
     DnsUdpContext context = m_contextPool.Get();
     if (context == null)
     {
         context = new DnsUdpContext();
     }
     context.Init();
     
     return context;
 }
示例#8
0
 void ReleaseContext(DnsUdpContext context)
 {
     context.Reset();
     m_contextPool.Put(context);
 }