예제 #1
0
파일: Handle.cs 프로젝트: zsybupt/corefxlab
 public virtual void Dispose(bool disposing)
 {
     if (!IsDisposing && !IsDisposed)
     {
         UVInterop.uv_close(_handle, CloseCallback);
     }
 }
예제 #2
0
        public unsafe void TryWrite(Memory <byte> data)
        {
            // This can work with Span<byte> because it's synchronous but we need pinning support
            EnsureNotDisposed();

            void *pointer;

            if (!data.TryGetPointer(out pointer))
            {
                throw new InvalidOperationException("Pointer not available");
            }

            IntPtr ptrData = (IntPtr)pointer;
            var    length  = data.Length;

            if (IsUnix)
            {
                var buffer = new UVBuffer.Unix(ptrData, (uint)length);
                UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
            }
            else
            {
                var buffer = new UVBuffer.Windows(ptrData, (uint)length);
                UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
            }
        }
예제 #3
0
        public unsafe void TryWrite(Span <byte> data)
        {
            EnsureNotDisposed();

            ArraySegment <byte> array;
            void * pointer;
            IntPtr ptrData;

            if (data.TryGetArrayElseGetPointer(out array, out pointer))
            {
                throw new NotImplementedException("needs to pin the array");
            }
            else
            {
                ptrData = (IntPtr)pointer;
            }

            if (IsUnix)
            {
                var buffer = new UVBuffer.Unix(ptrData, (uint)data.Length);
                UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
            }
            else
            {
                var buffer = new UVBuffer.Windows(ptrData, (uint)data.Length);
                UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
            }
        }
예제 #4
0
        public unsafe void TryWrite(byte[] data, int length)
        {
            Debug.Assert(data != null);
            if (data.Length < length)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            EnsureNotDisposed();

            fixed(byte *pData = data)
            {
                IntPtr ptrData = (IntPtr)pData;

                if (IsUnix)
                {
                    var buffer = new UVBuffer.Unix(ptrData, (uint)length);
                    UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
                }
                else
                {
                    var buffer = new UVBuffer.Windows(ptrData, (uint)length);
                    UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
                }
            }
        }
예제 #5
0
파일: Tcp.cs 프로젝트: prepare/Espresso
        static sockaddr_in6 CreateSockaddrIp6(string ip, int port)
        {
            sockaddr_in6 address;
            int          result = UVInterop.uv_ip6_addr(ip, port, out address);

            UVException.ThrowIfError(result);
            return(address);
        }
예제 #6
0
        public UVRequest(RequestType type)
        {
            var size = UVInterop.uv_req_size(type);

            _handle         = Marshal.AllocHGlobal(size);
            _requestPointer = (uv_req_t *)_handle;

            GCHandle = GCHandle.Alloc(this, GCHandleType.Normal);
        }
예제 #7
0
        public UVLoop()
        {
            _pool = UVBuffer.Default;
            var size       = UVInterop.uv_loop_size().ToInt32();
            var loopHandle = Marshal.AllocHGlobal(size); // this needs to be deallocated

            UVException.ThrowIfError(UVInterop.uv_loop_init(loopHandle));
            _handle = loopHandle;
        }
예제 #8
0
        public void ReadStart()
        {
            EnsureNotDisposed();

            if (IsUnix)
            {
                UVException.ThrowIfError(UVInterop.uv_read_start(Handle, UVBuffer.AllocateUnixBuffer, ReadUnix));
            }
            else
            {
                UVException.ThrowIfError(UVInterop.uv_read_start(Handle, UVBuffer.AllocWindowsBuffer, ReadWindows));
            }
        }
예제 #9
0
파일: Tcp.cs 프로젝트: prepare/Espresso
 static void Bind(TcpListener listener, string ipAddress, int port, bool ip6 = false, bool dualstack = false)
 {
     if (ip6)
     {
         sockaddr_in6 address = CreateSockaddrIp6(ipAddress.ToString(), port);
         UVException.ThrowIfError(UVInterop.uv_tcp_bind(listener.Handle, ref address, (uint)(dualstack ? 0 : 1)));
     }
     else
     {
         sockaddr_in address = CreateSockaddr(ipAddress.ToString(), port);
         UVException.ThrowIfError(UVInterop.uv_tcp_bind(listener.Handle, ref address, 0));
     }
 }
예제 #10
0
        public unsafe void TryWrite(Span <byte> data)
        {
            EnsureNotDisposed();

            IntPtr ptrData = (IntPtr)data.UnsafePointer;

            if (IsUnix)
            {
                var buffer = new UVBuffer.Unix(ptrData, (uint)data.Length);
                UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
            }
            else
            {
                var buffer = new UVBuffer.Windows(ptrData, (uint)data.Length);
                UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
            }
        }
예제 #11
0
파일: Stream.cs 프로젝트: zsybupt/corefxlab
        public unsafe void TryWrite(ReadOnlySpan <byte> data)
        {
            // This can work with Span<byte> because it's synchronous but we need pinning support
            EnsureNotDisposed();

            fixed(byte *source = &MemoryMarshal.GetReference(data))
            {
                var length = data.Length;

                if (IsUnix)
                {
                    var buffer = new UVBuffer.Unix((IntPtr)source, (uint)length);
                    UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
                }
                else
                {
                    var buffer = new UVBuffer.Windows((IntPtr)source, (uint)length);
                    UVException.ThrowIfError(UVInterop.uv_try_write(Handle, &buffer, 1));
                }
            }
        }
예제 #12
0
        static void OnNotified(IntPtr handle, int status)
        {
            var listener = As <UVListener <TStream> >(handle);

            var stream     = listener.CreateStream();
            var connection = stream as TStream;

            try
            {
                UVException.ThrowIfError(UVInterop.uv_accept(listener.Handle, connection.Handle));
            }
            catch (Exception e)
            {
                stream.Dispose();
                connection.Dispose();
                Environment.FailFast(e.ToString());
            }

            if (listener.ConnectionAccepted != null)
            {
                listener.ConnectionAccepted(connection);
            }
        }
예제 #13
0
 public void Stop()
 {
     UVInterop.uv_stop(_handle);
 }
예제 #14
0
파일: Tcp.cs 프로젝트: prepare/Espresso
 public Tcp(UVLoop loop) : base(loop, HandleType.UV_TCP)
 {
     UVInterop.uv_tcp_init(loop.Handle, Handle);
 }
예제 #15
0
파일: Tcp.cs 프로젝트: prepare/Espresso
 void SetNoDelay(bool value)
 {
     UVInterop.uv_tcp_nodelay(Handle, value ? 1 : 0);
 }
예제 #16
0
        static string ErrorCodeToText(int errorCode)
        {
            var nullTerminatedUtf8 = (byte *)UVInterop.uv_err_name(errorCode);

            return(NullTerminatedUtf8ToString(nullTerminatedUtf8));
        }
예제 #17
0
        static string ErrorCodeToDescription(int errorCode)
        {
            var nullTerminatedUtf8 = (byte *)UVInterop.uv_strerror(errorCode);

            return(NullTerminatedUtf8ToString(nullTerminatedUtf8));
        }
예제 #18
0
파일: Tcp.cs 프로젝트: prepare/Espresso
 public TcpListener(string ipAddress, int port, UVLoop loop) : base(loop, HandleType.UV_TCP)
 {
     UVException.ThrowIfError(UVInterop.uv_tcp_init(Loop.Handle, Handle));
     Bind(this, ipAddress, port);
 }
예제 #19
0
 public DisposeRequest(UVHandle handle) : base(RequestType.UV_SHUTDOWN)
 {
     _handle = handle;
     UVInterop.uv_shutdown(Handle, _handle.Handle, CallbackDelegate);
 }
예제 #20
0
파일: Tcp.cs 프로젝트: prepare/Espresso
 void SetKeepAlive(bool value, int delay)
 {
     UVInterop.uv_tcp_keepalive(Handle, value ? 1 : 0, delay);
 }
예제 #21
0
 public void Listen(int backlog)
 {
     UVInterop.uv_listen(Handle, backlog, Notified);
 }
예제 #22
0
파일: Handle.cs 프로젝트: zsybupt/corefxlab
 protected static int GetSize(HandleType type)
 {
     return(UVInterop.uv_handle_size(type));
 }
예제 #23
0
 public void Run()
 {
     UVInterop.uv_run(_handle, uv_run_mode.UV_RUN_DEFAULT);
 }