Exemplo n.º 1
0
        public void Init()
        {
            int loopSize = LibuvNative.uv_loop_size();

            InitUnmanaged(loopSize);
            LibuvNative.uv_loop_init(this);
        }
Exemplo n.º 2
0
        public int TryWrite(LibuvNative.uv_buf_t buf)
        {
            _writeBufs    = _writeBufs ?? new LibuvNative.uv_buf_t[1];
            _writeBufs[0] = buf;

            return(LibuvNative.uv_try_write(this, _writeBufs, 1));
        }
Exemplo n.º 3
0
        public void Init(LibuvLoopHandle loopHandle)
        {
            int tcpHandleSize = LibuvNative.uv_handle_size(LibuvNative.HandleType.TCP);

            InitUnmanaged(tcpHandleSize);

            LibuvNative.uv_tcp_init(loopHandle, this);
        }
Exemplo n.º 4
0
        // TODO: проверка на поток
        protected override bool ReleaseHandle()
        {
            IntPtr handlePtr = handle;

            if (handlePtr != IntPtr.Zero)
            {
                handle = IntPtr.Zero;

                LibuvNative.uv_close(handlePtr, ReleaseUnmanaged);
            }
            return(true);
        }
Exemplo n.º 5
0
        unsafe protected override bool ReleaseHandle()
        {
            IntPtr handlePtr = handle;

            if (handlePtr != IntPtr.Zero)
            {
                // uv_loop_close очищает gcHandlePtr.
                var gcHandlePtr = *(IntPtr *)handlePtr;

                LibuvNative.uv_loop_close(this.InternalGetHandle());

                handle = IntPtr.Zero;

                ReleaseUnmanaged(handlePtr, gcHandlePtr);
            }

            return(true);
        }
Exemplo n.º 6
0
        public void Bind(ServerAddress address)
        {
            IPEndPoint endpoint = CreateIPEndpoint(address);

            var addressText = endpoint.Address.ToString();

            SockAddr addr;
            int      ip4Status = LibuvNative.uv_ip4_addr(addressText, endpoint.Port, out addr);

            if (ip4Status < 0)
            {
                int ip6Status = LibuvNative.uv_ip6_addr(addressText, endpoint.Port, out addr);
                if (ip6Status < 0)
                {
                    // TODO:
                    throw new Exception();
                }
            }

            LibuvNative.uv_tcp_bind(this, ref addr, 0 /* flags */);
        }
Exemplo n.º 7
0
 public void Stop()
 {
     LibuvNative.uv_stop(this);
 }
Exemplo n.º 8
0
 // TODO: mode = 0?
 public void Run(int mode)
 {
     LibuvNative.uv_run(this, mode);
 }
Exemplo n.º 9
0
 public void Reference()
 {
     LibuvNative.uv_ref(this);
 }
Exemplo n.º 10
0
 public void Unreference()
 {
     LibuvNative.uv_unref(this);
 }
Exemplo n.º 11
0
 public void ReadStop()
 {
     LibuvNative.uv_read_stop(this);
 }
Exemplo n.º 12
0
 public void ReadStart(AllocCallback allocCallback, ReadCallback readCallback)
 {
     _allocCallback = allocCallback;
     _readCallback  = readCallback;
     LibuvNative.uv_read_start(this, AllocCb, ReadCb);
 }
Exemplo n.º 13
0
 public void Accept(LibuvStreamHandle clientStreamHandle)
 {
     LibuvNative.uv_accept(this /* serverStreamHandle */, clientStreamHandle);
 }
Exemplo n.º 14
0
 public void Listen(int backlog, ConnectionCallback connectionCallback)
 {
     _connectionCallback = connectionCallback;
     LibuvNative.uv_listen(this, backlog, ConnectionCb);
 }