public UnixSocketStream(PipeName pipeName, SocketUsage socketUsage) : base( Init(socketUsage, pipeName), FileAccess.ReadWrite, true) { }
static UnixEndPoint CreateEndPoint(PipeName pipeName) { var path = CreatePath(pipeName); var endPoint = new UnixEndPoint(path); return(endPoint); }
static string CreatePath(PipeName pipeName) { var path = SocketDirectory; Directory.CreateDirectory(path); return(Path.Combine(path, pipeName.ToString())); }
public Task <Stream> Host(PipeName name) { return(Task.Run(() => { var stream = new NamedPipeServerStream(name.ToString()); stream.WaitForConnection(); return (Stream)stream; })); }
public static bool SocketExists(PipeName pipeName) { try { using (Connect(pipeName, isBlocking: false)) return(true); } catch (Exception) { return(false); } }
static Socket Host(PipeName pipeName) { var endPoint = CreateEndPoint(pipeName); using (var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified)) { socket.Bind(endPoint); socket.Listen(1); var handler = socket.Accept(); return(handler); } }
static Socket Init(SocketUsage socketUsage, PipeName pipeName) { switch (socketUsage) { case SocketUsage.Client: return(Connect(pipeName, isBlocking: true)); case SocketUsage.Host: return(Host(pipeName)); default: throw new ArgumentException("socketUsage"); } }
public Task <Stream> Connect(PipeName name) { return(Task.Run(() => { var pipeName = name.ToString(); var stream = new NamedPipeClientStream(pipeName); while (NamedPipeDoesNotExist(pipeName)) { Thread.Sleep(10); } stream.Connect(); return (Stream)stream; })); }
static Socket Connect(PipeName pipeName, bool isBlocking) { var endPoint = CreateEndPoint(pipeName); var path = CreatePath(pipeName); var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); while (true) { if (!File.Exists(path)) { if (isBlocking) { Thread.Sleep(1); continue; } else { throw new FileNotFoundException("Failed to find Unix socket.", path); } } try { socket.Connect(endPoint); return(socket); } catch (SocketException) { if (isBlocking) { Thread.Sleep(10); } else { throw; } } } }
public static void Unlink(PipeName pipeName) { var endPoint = CreateEndPoint(pipeName); Syscall.unlink(endPoint.Filename); }
public static Task <Stream> Connect(PipeName name) { return(GetPipeImpl().Connect(name)); }
public static Task <Stream> Host(PipeName name) { return(GetPipeImpl().Host(name)); }
public Task <Stream> Connect(PipeName name) { return(Task.Run(() => (Stream) new UnixSocketStream(name, SocketUsage.Client))); }
public Task <Stream> Host(PipeName name) { return(Task.Run(() => (Stream) new UnixSocketStream(name, SocketUsage.Host))); }