Dispose() public method

public Dispose ( ) : void
return void
Exemplo n.º 1
0
        private void OnQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
                                        ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen,
                                        IntPtr rdata, uint ttl, IntPtr context)
        {
            switch (rrtype)
            {
            case ServiceType.A:
                IPAddress address;

                if (rdlen == 4)
                {
                    // ~4.5 times faster than Marshal.Copy into byte[4]
                    uint address_raw = (uint)(Marshal.ReadByte(rdata, 3) << 24);
                    address_raw |= (uint)(Marshal.ReadByte(rdata, 2) << 16);
                    address_raw |= (uint)(Marshal.ReadByte(rdata, 1) << 8);
                    address_raw |= (uint)Marshal.ReadByte(rdata, 0);

                    address = new IPAddress(address_raw);
                }
                else if (rdlen == 16)
                {
                    byte [] address_raw = new byte[rdlen];
                    Marshal.Copy(rdata, address_raw, 0, rdlen);
                    address = new IPAddress(address_raw, interfaceIndex);
                }
                else
                {
                    break;
                }

                if (hostentry == null)
                {
                    hostentry          = new IPHostEntry();
                    hostentry.HostName = hosttarget;
                }

                if (hostentry.AddressList != null)
                {
                    ArrayList list = new ArrayList(hostentry.AddressList);
                    list.Add(address);
                    hostentry.AddressList = list.ToArray(typeof(IPAddress)) as IPAddress [];
                }
                else
                {
                    hostentry.AddressList = new IPAddress [] { address };
                }

                ServiceResolvedEventHandler handler = Resolved;
                if (handler != null)
                {
                    handler(this, new ServiceResolvedEventArgs(this));
                }

                break;

            case ServiceType.TXT:
                if (TxtRecord != null)
                {
                    TxtRecord.Dispose();
                }

                TxtRecord = new TxtRecord(rdlen, rdata);
                break;

            default:
                break;
            }

            sdRef.Deallocate();
        }