protected DnsUdpContext CreateContext() { DnsUdpContext context = m_contextPool.Get(); if (context == null) { context = new DnsUdpContext(); } context.Init(); return(context); }
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); } } }
public void ProcessingComplete(DnsUdpContext context) { try { if (context != null) { this.ReleaseContext(context); } } catch (Exception ex) { this.NotifyError(ex); } finally { base.ProcessingComplete(); } }
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(); } }
void ReleaseContext(DnsUdpContext context) { context.Reset(); m_contextPool.Put(context); }
public void ProcessingComplete(DnsUdpContext context) { try { if (context != null) { this.ReleaseContext(context); } } catch(Exception ex) { this.NotifyError(ex); } finally { base.ProcessingComplete(); } }
protected DnsUdpContext CreateContext() { DnsUdpContext context = m_contextPool.Get(); if (context == null) { context = new DnsUdpContext(); } context.Init(); return context; }