示例#1
0
 public UnixSocketStream(PipeName pipeName, SocketUsage socketUsage)
     : base(
         Init(socketUsage, pipeName),
         FileAccess.ReadWrite,
         true)
 {
 }
示例#2
0
        static UnixEndPoint CreateEndPoint(PipeName pipeName)
        {
            var path     = CreatePath(pipeName);
            var endPoint = new UnixEndPoint(path);

            return(endPoint);
        }
示例#3
0
        static string CreatePath(PipeName pipeName)
        {
            var path = SocketDirectory;

            Directory.CreateDirectory(path);
            return(Path.Combine(path, pipeName.ToString()));
        }
示例#4
0
 public Task <Stream> Host(PipeName name)
 {
     return(Task.Run(() =>
     {
         var stream = new NamedPipeServerStream(name.ToString());
         stream.WaitForConnection();
         return (Stream)stream;
     }));
 }
示例#5
0
 public static bool SocketExists(PipeName pipeName)
 {
     try
     {
         using (Connect(pipeName, isBlocking: false))
             return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#6
0
        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);
            }
        }
示例#7
0
        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");
            }
        }
示例#8
0
        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;
            }));
        }
示例#9
0
        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;
                    }
                }
            }
        }
示例#10
0
        public static void Unlink(PipeName pipeName)
        {
            var endPoint = CreateEndPoint(pipeName);

            Syscall.unlink(endPoint.Filename);
        }
示例#11
0
 public static Task <Stream> Connect(PipeName name)
 {
     return(GetPipeImpl().Connect(name));
 }
示例#12
0
 public static Task <Stream> Host(PipeName name)
 {
     return(GetPipeImpl().Host(name));
 }
示例#13
0
 public Task <Stream> Connect(PipeName name)
 {
     return(Task.Run(() => (Stream) new UnixSocketStream(name, SocketUsage.Client)));
 }
示例#14
0
 public Task <Stream> Host(PipeName name)
 {
     return(Task.Run(() => (Stream) new UnixSocketStream(name, SocketUsage.Host)));
 }