Ejemplo n.º 1
0
        public void Resolve(string node, string service, Action <UvArgs <IPEndPoint[]> > callback = null)
        {
            var hints    = addrinfo.CreateHints();
            var hintsPtr = this.Loop.Allocs.Alloc(Marshal.SizeOf(typeof(addrinfo)));

            Marshal.StructureToPtr(hints, hintsPtr, fDeleteOld: false);

            try
            {
                _resolveReq = this.Loop.Requests.Create(uv_req_type.UV_GETADDRINFO);
                CheckError(Uvi.uv_getaddrinfo(this.Loop.Handle, _resolveReq, _resolveDelegate, node, service, hintsPtr));
                this.Status      = HandleStatus.Resolving;
                _resolveCallback = new UvEndPointsCallback(this, callback);
            }
            catch (Exception)
            {
                this.Loop.Requests.Delete(_resolveReq);
                _connectCallback = null;
                throw;
            }
            finally
            {
                this.Loop.Allocs.Free(hintsPtr);
            }
        }
Ejemplo n.º 2
0
        private void OnResolve(IntPtr resolver, int status, IntPtr addrinfo)
        {
            var callback = _resolveCallback;

            _resolveCallback = null;

            try
            {
                IPEndPoint[] value = null;
                if (status == 0)
                {
                    var info = ((addrinfo)Marshal.PtrToStructure(addrinfo, typeof(addrinfo)));
                    value = info.EndPoints.ToArray();
                }

                callback.Invoke(status, value, this.OnResolve, this.Resolved);
            }
            finally
            {
                Uvi.uv_freeaddrinfo(addrinfo);
                this.Loop.Requests.Delete(_resolveReq);
            }
        }
Ejemplo n.º 3
0
        public void Resolve(string node, string service, Action<UvArgs<IPEndPoint[]>> callback = null)
        {
            var hints = addrinfo.CreateHints();
            var hintsPtr = this.Loop.Allocs.Alloc(Marshal.SizeOf(typeof(addrinfo)));
            Marshal.StructureToPtr(hints, hintsPtr, fDeleteOld: false);

            try
            {
                _resolveReq = this.Loop.Requests.Create(uv_req_type.UV_GETADDRINFO);
                CheckError(Uvi.uv_getaddrinfo(this.Loop.Handle, _resolveReq, _resolveDelegate, node, service, hintsPtr));
                this.Status = HandleStatus.Resolving;
                _resolveCallback = new UvEndPointsCallback(this, callback);
            }
            catch (Exception)
            {
                this.Loop.Requests.Delete(_resolveReq);
                _connectCallback = null;
                throw;
            }
            finally
            {
                this.Loop.Allocs.Free(hintsPtr);
            }
        }
Ejemplo n.º 4
0
        private void OnResolve(IntPtr resolver, int status, IntPtr addrinfo)
        {
            var callback = _resolveCallback;
            _resolveCallback = null;

            try
            {
                IPEndPoint[] value = null;
                if (status == 0)
                {
                    var info = ((addrinfo)Marshal.PtrToStructure(addrinfo, typeof(addrinfo)));
                    value = info.EndPoints.ToArray();
                }

                callback.Invoke(status, value, this.OnResolve, this.Resolved);
            }
            finally
            {
                Uvi.uv_freeaddrinfo(addrinfo);
                this.Loop.Requests.Delete(_resolveReq);
            }
        }