Ejemplo n.º 1
0
        private async void HandleRequest(byte[] data, IPEndPoint remote)
        {
            DnsRequestMessage request = null;

            try
            {
                request = DnsRequestMessage.FromArray(data);

                OnEvent(OnRequested, new RequestedEventArgs(request, data, remote));

                IResponse response = await _coder.Code(request);

                OnEvent(OnResponded, new RespondedEventArgs(request, response, data, remote));

                await _udp.SendAsync(response.ToArray(), response.Size, remote).WithCancellationTimeout(TimeSpan.FromMilliseconds(UDP_TIMEOUT));
            }
            catch (SocketException e) { OnError(e); }
            catch (ArgumentException e) { OnError(e); }
            catch (IndexOutOfRangeException e) { OnError(e); }
            catch (OperationCanceledException e) { OnError(e); }
            catch (IOException e) { OnError(e); }
            catch (ObjectDisposedException e) { OnError(e); }
            catch (Model.ResponseException e)
            {
                IResponse response = e.Response;

                if (response == null)
                {
                    response = DnsResponseMessage.FromRequest(request);
                }

                try
                {
                    await _udp.SendAsync(response.ToArray(), response.Size, remote).WithCancellationTimeout(TimeSpan.FromMilliseconds(UDP_TIMEOUT));
                }
                catch (SocketException) { }
                catch (OperationCanceledException) { }
                finally { OnError(e); }
            }
        }
Ejemplo n.º 2
0
        private async void HandleRequest(string sessionID, byte[] data)
        {
            DnsRequestMessage request = null;

            try
            {
                request = DnsRequestMessage.FromArray(data);

                OnEvent(OnRequested, new RequestedEventArgs(request, data));

                IResponse response = await _coder.Code(request);

                OnEvent(OnResponded, new RespondedEventArgs(request, response, data));

                _udpServer.SendAsync(sessionID, response.ToArray());
            }
            catch (SocketException e) { OnError(e); }
            catch (ArgumentException e) { OnError(e); }
            catch (IndexOutOfRangeException e) { OnError(e); }
            catch (OperationCanceledException e) { OnError(e); }
            catch (IOException e) { OnError(e); }
            catch (ObjectDisposedException e) { OnError(e); }
            catch (ResponseException e)
            {
                IResponse response = e.Response;

                if (response == null)
                {
                    response = DnsResponseMessage.FromRequest(request);
                }

                try
                {
                    _udpServer.SendAsync(sessionID, response.ToArray());
                }
                catch (SocketException) { }
                catch (OperationCanceledException) { }
                finally { OnError(e); }
            }
        }