private UvPipeHandle ListenPipe(bool useFileHandle) { var pipe = new UvPipeHandle(Log); try { pipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); if (!useFileHandle) { pipe.Bind(EndPointInformation.SocketPath); } else { pipe.Open((IntPtr)EndPointInformation.FileHandle); } } catch { pipe.Dispose(); throw; } return(pipe); }
private UvPipeHandle ListenPipe(bool useFileHandle) { var pipe = new UvPipeHandle(Log); try { pipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); if (!useFileHandle) { // UnixDomainSocketEndPoint.ToString() returns the path pipe.Bind(EndPoint.ToString()); } else { pipe.Open((IntPtr)((FileHandleEndPoint)EndPoint).FileHandle); } } catch { pipe.Dispose(); throw; } return(pipe); }
private void PostCallback() { ListenPipe = new UvPipeHandle(Log); ListenPipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); ListenPipe.Bind(_pipeName); ListenPipe.Listen(LibuvConstants.ListenBacklog, (pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this); }
/// <summary> /// Creates the socket used to listen for incoming connections /// </summary> protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, false); socket.Bind(ServerAddress.UnixPipePath); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return(socket); }
/// <summary> /// Creates the socket used to listen for incoming connections /// </summary> protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); socket.Bind(ServerAddress.UnixPipePath); socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return(socket); }
/// <summary> /// Creates the socket used to listen for incoming connections /// </summary> protected override UvStreamHandle CreateListenSocket(string host, int port) { var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, false); socket.Bind(host); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return(socket); }
private void PostCallback() { ListenPipe = new UvPipeHandle(Log); ListenPipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); ListenPipe.Bind(_pipeName); #pragma warning disable CS0618 ListenPipe.Listen(TransportContext.Options.Backlog, (pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this); #pragma warning restore CS0618 }
public void InitAndCloseServerPipe() { var loop = new UvLoopHandle(_logger); var pipe = new UvPipeHandle(_logger); loop.Init(_uv); pipe.Init(loop, (a, b) => { }, true); pipe.Bind(@"\\.\pipe\InitAndCloseServerPipe"); pipe.Dispose(); loop.Run(); pipe.Dispose(); loop.Dispose(); }
public async Task StartAsync( string pipeName, ServerAddress address, KestrelThread thread, Func <Frame, Task> application) { await StartAsync(address, thread, application).ConfigureAwait(false); await Thread.PostAsync(_ => { ListenPipe = new UvPipeHandle(Log); ListenPipe.Init(Thread.Loop, false); ListenPipe.Bind(pipeName); ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null); }, null).ConfigureAwait(false); }
/// <summary> /// Creates the socket used to listen for incoming connections /// </summary> protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); try { socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); socket.Bind(ServerAddress.UnixPipePath); } catch { socket.Dispose(); throw; } return(socket); }
public void ServerPipeListenForConnections() { const string pipeName = @"\\.\pipe\ServerPipeListenForConnections"; var loop = new UvLoopHandle(_logger); var serverListenPipe = new UvPipeHandle(_logger); loop.Init(_uv); serverListenPipe.Init(loop, (a, b) => { }, false); serverListenPipe.Bind(pipeName); serverListenPipe.Listen(128, (backlog, status, error, state) => { var serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, (a, b) => { }, true); try { serverListenPipe.Accept(serverConnectionPipe); } catch (Exception) { serverConnectionPipe.Dispose(); return; } var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); var pool = new MemoryPool(); var block = pool.Lease(); block.GetIterator().CopyFrom(new ArraySegment <byte>(new byte[] { 1, 2, 3, 4 })); var start = new MemoryPoolIterator(block, 0); var end = new MemoryPoolIterator(block, block.Data.Count); writeRequest.Write( serverConnectionPipe, start, end, 1, (handle, status2, error2, state2) => { writeRequest.Dispose(); serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); pool.Return(block); pool.Dispose(); }, null); }, null); var worker = new Thread(() => { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, (a, b) => { }, true); connect.Init(loop2); connect.Connect(clientConnectionPipe, pipeName, (handle, status, error, state) => { var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(8192), 8192); connect.Dispose(); clientConnectionPipe.ReadStart( (handle2, cb, state2) => buf, (handle2, status2, state2) => { if (status2 == Constants.EOF) { clientConnectionPipe.Dispose(); } }, null); }, null); loop2.Run(); loop2.Dispose(); }); worker.Start(); loop.Run(); loop.Dispose(); worker.Join(); }
public void ServerPipeDispatchConnections() { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); var loop = new UvLoopHandle(_logger); loop.Init(_uv); var serverConnectionPipe = default(UvPipeHandle); var serverConnectionPipeAcceptedEvent = new ManualResetEvent(false); var serverConnectionTcpDisposedEvent = new ManualResetEvent(false); var serverListenPipe = new UvPipeHandle(_logger); serverListenPipe.Init(loop, (a, b) => { }, false); serverListenPipe.Bind(pipeName); serverListenPipe.Listen(128, (handle, status, error, state) => { serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, (a, b) => { }, true); try { serverListenPipe.Accept(serverConnectionPipe); serverConnectionPipeAcceptedEvent.Set(); } catch (Exception ex) { Console.WriteLine(ex); serverConnectionPipe.Dispose(); serverConnectionPipe = null; } }, null); var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop, (a, b) => { }); var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); serverListenTcp.Bind(address); var port = serverListenTcp.GetSockIPEndPoint().Port; serverListenTcp.Listen(128, (handle, status, error, state) => { var serverConnectionTcp = new UvTcpHandle(_logger); serverConnectionTcp.Init(loop, (a, b) => { }); serverListenTcp.Accept(serverConnectionTcp); serverConnectionPipeAcceptedEvent.WaitOne(); var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); writeRequest.Write2( serverConnectionPipe, new ArraySegment <ArraySegment <byte> >(new ArraySegment <byte>[] { new ArraySegment <byte>(new byte[] { 1, 2, 3, 4 }) }), serverConnectionTcp, (handle2, status2, error2, state2) => { writeRequest.Dispose(); serverConnectionTcp.Dispose(); serverConnectionTcpDisposedEvent.Set(); serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); serverListenTcp.Dispose(); }, null); }, null); var worker = new Thread(() => { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, (a, b) => { }, true); connect.Init(loop2); connect.Connect(clientConnectionPipe, pipeName, (handle, status, error, state) => { connect.Dispose(); var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); serverConnectionTcpDisposedEvent.WaitOne(); clientConnectionPipe.ReadStart( (handle2, cb, state2) => buf, (handle2, status2, state2) => { if (status2 == Constants.EOF) { clientConnectionPipe.Dispose(); return; } var clientConnectionTcp = new UvTcpHandle(_logger); clientConnectionTcp.Init(loop2, (a, b) => { }); clientConnectionPipe.Accept(clientConnectionTcp); var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); clientConnectionTcp.ReadStart( (handle3, cb, state3) => buf2, (handle3, status3, state3) => { if (status3 == Constants.EOF) { clientConnectionTcp.Dispose(); } }, null); }, null); }, null); loop2.Run(); loop2.Dispose(); }); var worker2 = new Thread(() => { try { serverConnectionPipeAcceptedEvent.WaitOne(); var socket = TestConnection.CreateConnectedLoopbackSocket(port); socket.Send(new byte[] { 6, 7, 8, 9 }); socket.Shutdown(SocketShutdown.Send); var cb = socket.Receive(new byte[64]); socket.Dispose(); } catch (Exception ex) { Console.WriteLine(ex); } }); worker.Start(); worker2.Start(); loop.Run(); loop.Dispose(); worker.Join(); worker2.Join(); }
public void ServerPipeListenForConnections() { const string pipeName = @"\\.\pipe\ServerPipeListenForConnections"; var loop = new UvLoopHandle(_logger); var serverListenPipe = new UvPipeHandle(_logger); loop.Init(_uv); serverListenPipe.Init(loop, (a, b) => { }, false); serverListenPipe.Bind(pipeName); serverListenPipe.Listen(128, async(backlog, status, error, state) => { var serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, (a, b) => { }, true); try { serverListenPipe.Accept(serverConnectionPipe); } catch (Exception) { serverConnectionPipe.Dispose(); return; } var writeRequest = new UvWriteReq(_logger); writeRequest.DangerousInit(loop); await writeRequest.WriteAsync( serverConnectionPipe, new ReadOnlyBuffer(new byte[] { 1, 2, 3, 4 })); writeRequest.Dispose(); serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); }, null); var worker = new Thread(() => { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); var connect = new UvConnectRequest(_logger); loop2.Init(_uv); clientConnectionPipe.Init(loop2, (a, b) => { }, true); connect.DangerousInit(loop2); connect.Connect(clientConnectionPipe, pipeName, (handle, status, error, state) => { var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(8192), 8192); connect.Dispose(); clientConnectionPipe.ReadStart( (handle2, cb, state2) => buf, (handle2, status2, state2) => { if (status2 == TestConstants.EOF) { clientConnectionPipe.Dispose(); } }, null); }, null); loop2.Run(); loop2.Dispose(); }); worker.Start(); loop.Run(); loop.Dispose(); worker.Join(); }
public void ServerPipeListenForConnections() { var loop = new UvLoopHandle(_logger); var serverListenPipe = new UvPipeHandle(_logger); loop.Init(_uv); serverListenPipe.Init(loop, false); serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections"); serverListenPipe.Listen(128, (_1, status, error, _2) => { var serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, true); try { serverListenPipe.Accept(serverConnectionPipe); } catch (Exception) { serverConnectionPipe.Dispose(); return; } var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); var block = MemoryPoolBlock2.Create( new ArraySegment <byte>(new byte[] { 1, 2, 3, 4 }), dataPtr: IntPtr.Zero, pool: null, slab: null); var start = new MemoryPoolIterator2(block, 0); var end = new MemoryPoolIterator2(block, block.Data.Count); writeRequest.Write( serverConnectionPipe, start, end, 1, (_3, status2, error2, _4) => { writeRequest.Dispose(); serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); block.Unpin(); }, null); }, null); var worker = new Thread(() => { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); connect.Init(loop2); connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeListenForConnections", (_1, status, error, _2) => { var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(8192), 8192); connect.Dispose(); clientConnectionPipe.ReadStart( (_3, cb, _4) => buf, (_3, status2, _4) => { if (status2 == 0) { clientConnectionPipe.Dispose(); } }, null); }, null); loop2.Run(); loop2.Dispose(); }); worker.Start(); loop.Run(); loop.Dispose(); worker.Join(); }
public void ServerPipeDispatchConnections() { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); var loop = new UvLoopHandle(_logger); loop.Init(_uv); var serverConnectionPipe = default(UvPipeHandle); var serverConnectionPipeAcceptedEvent = new ManualResetEvent(false); var serverConnectionTcpDisposedEvent = new ManualResetEvent(false); var serverListenPipe = new UvPipeHandle(_logger); serverListenPipe.Init(loop, false); serverListenPipe.Bind(pipeName); serverListenPipe.Listen(128, (_1, status, error, _2) => { serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, true); try { serverListenPipe.Accept(serverConnectionPipe); serverConnectionPipeAcceptedEvent.Set(); } catch (Exception ex) { Console.WriteLine(ex); serverConnectionPipe.Dispose(); serverConnectionPipe = null; } }, null); var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop); var address = ServerAddress.FromUrl("http://localhost:54321/"); serverListenTcp.Bind(address); serverListenTcp.Listen(128, (_1, status, error, _2) => { var serverConnectionTcp = new UvTcpHandle(_logger); serverConnectionTcp.Init(loop); serverListenTcp.Accept(serverConnectionTcp); serverConnectionPipeAcceptedEvent.WaitOne(); var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); writeRequest.Write2( serverConnectionPipe, new ArraySegment <ArraySegment <byte> >(new ArraySegment <byte>[] { new ArraySegment <byte>(new byte[] { 1, 2, 3, 4 }) }), serverConnectionTcp, (_3, status2, error2, _4) => { writeRequest.Dispose(); serverConnectionTcp.Dispose(); serverConnectionTcpDisposedEvent.Set(); serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); serverListenTcp.Dispose(); }, null); }, null); var worker = new Thread(() => { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); connect.Init(loop2); connect.Connect(clientConnectionPipe, pipeName, (_1, status, error, _2) => { connect.Dispose(); var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); serverConnectionTcpDisposedEvent.WaitOne(); clientConnectionPipe.ReadStart( (_3, cb, _4) => buf, (_3, status2, _4) => { if (status2 == 0) { clientConnectionPipe.Dispose(); return; } var clientConnectionTcp = new UvTcpHandle(_logger); clientConnectionTcp.Init(loop2); clientConnectionPipe.Accept(clientConnectionTcp); var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); clientConnectionTcp.ReadStart( (_5, cb, _6) => buf2, (_5, status3, _6) => { if (status3 == 0) { clientConnectionTcp.Dispose(); } }, null); }, null); }, null); loop2.Run(); loop2.Dispose(); }); var worker2 = new Thread(() => { try { serverConnectionPipeAcceptedEvent.WaitOne(); var socket = new Socket(SocketType.Stream, ProtocolType.IP); socket.Connect(IPAddress.Loopback, 54321); socket.Send(new byte[] { 6, 7, 8, 9 }); socket.Shutdown(SocketShutdown.Send); var cb = socket.Receive(new byte[64]); socket.Dispose(); } catch (Exception ex) { Console.WriteLine(ex); } }); worker.Start(); worker2.Start(); loop.Run(); loop.Dispose(); worker.Join(); worker2.Join(); }
public void ServerPipeListenForConnections() { var loop = new UvLoopHandle(_logger); var serverListenPipe = new UvPipeHandle(_logger); loop.Init(_uv); serverListenPipe.Init(loop, false); serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections"); serverListenPipe.Listen(128, (_1, status, error, _2) => { var serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, true); try { serverListenPipe.Accept(serverConnectionPipe); } catch (Exception) { serverConnectionPipe.Dispose(); return; } var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); writeRequest.Write( serverConnectionPipe, new ArraySegment <ArraySegment <byte> >(new ArraySegment <byte>[] { new ArraySegment <byte>(new byte[] { 1, 2, 3, 4 }) }), (_3, status2, error2, _4) => { writeRequest.Dispose(); serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); }, null); }, null); var worker = new Thread(() => { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); connect.Init(loop2); connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeListenForConnections", (_1, status, error, _2) => { var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(8192), 8192); connect.Dispose(); clientConnectionPipe.ReadStart( (_3, cb, _4) => buf, (_3, status2, errCode, error2, _4) => { if (status2 == 0) { clientConnectionPipe.Dispose(); } }, null); }, null); loop2.Run(); loop2.Dispose(); }); worker.Start(); loop.Run(); loop.Dispose(); worker.Join(); }