/// <summary>
 /// Initialize and create a new DnsRequestListener object
 /// </summary>
 public DnsRequestListener(DnsRecordProvider dnsRecordProvider, int port)
 {
     // Initialize the socket event pool
     this._socketAsyncEventArgsPool = new Stack<SocketAsyncEventArgs>();
     this.Port = 53;
     this.DnsRecordProvider = dnsRecordProvider;
 }
        /// <summary>
        /// Create a new DnsServer object
        /// </summary>
        public TcpDnsRequestListener(DnsRecordProvider dnsRecordProvider, int defaultPoolSize = 5000, int port = 53) : base(dnsRecordProvider, port)
        {
            this.listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            this.connectionsSemaphore = new Semaphore(defaultPoolSize, defaultPoolSize);
            this.listenerSocket.ReceiveBufferSize = 20000000; //~20 megabytes

            // Initialize the SocketAsyncEventArgs pool
            for (int i = 0; i < defaultPoolSize; i++)
            {
                var socketEventArg = new SocketAsyncEventArgs();
                socketEventArg.Completed += TcpSocketEventArg_Completed;
                socketEventArg.RemoteEndPoint = new IPEndPoint(IPAddress.Any, this.Port);
                socketEventArg.SetBuffer(new byte[4096], 0, 4096);

                // Connect with a request
                var request = new DnsRequestListenerSession(this, socketEventArg);
                socketEventArg.UserToken = request;

                // Add to the pool
                this._socketAsyncEventArgsPool.Push(socketEventArg);
            }
        }
예제 #3
0
 /// <summary>
 /// Create a new DnsServer object
 /// </summary>
 public DnsServer(DnsRecordProvider dnsRecordProvider, int udpArgPoolSize = 5000, int tcpArgPoolSize = 5000, int port = 53)
 {
     this.TcpRequestListener = new TcpDnsRequestListener(dnsRecordProvider, tcpArgPoolSize, port);
     this.UdpRequestListener = new UdpDnsRequestListener(dnsRecordProvider, udpArgPoolSize, port);
 }