예제 #1
0
        public void StartListening(object data)
        {
            listener = new UnixListener(path);
            Mono.Unix.Native.Syscall.chmod(path,
                                           Mono.Unix.Native.FilePermissions.S_IRUSR |
                                           Mono.Unix.Native.FilePermissions.S_IWUSR |
                                           Mono.Unix.Native.FilePermissions.S_IRGRP |
                                           Mono.Unix.Native.FilePermissions.S_IWGRP |
                                           Mono.Unix.Native.FilePermissions.S_IROTH |
                                           Mono.Unix.Native.FilePermissions.S_IWOTH);

            if (server_thread == null)
            {
                listener.Start();

                string[] uris = new String [1];
                uris     = new String [1];
                uris [0] = GetChannelUri();
                channel_data.ChannelUris = uris;

                server_thread = new Thread(new ThreadStart(WaitForConnections));
                server_thread.IsBackground = true;
                server_thread.Start();
            }
        }
예제 #2
0
        private static void Main(string[] args)
        {
            Console.SetOut(EvalOutput);
            Console.SetError(EvalOutput);
            Console.SetIn(DummyInput);

            try {
                Syscall.unlink(args[0]);
            } catch {}
            UnixListener sock = new UnixListener(args[0]);

            sock.Start();
            Syscall.chmod(args[0], FilePermissions.ACCESSPERMS);

            while (true)
            {
                NetworkStream s = new NetworkStream(sock.AcceptSocket(), true);
                Task.Run(() => {
                    try {
                        ProcessConnection(s);
                    } finally {
                        s.Dispose();
                    }
                });
            }
        }
예제 #3
0
        public void TestSocketFileCreateDelete()
        {
            var socketFile = Path.GetTempFileName();

            // we just want the file name, not the file
            File.Delete(socketFile);

            using (var listener = new UnixListener(socketFile)) {
                // creating an instance of UnixListener should create the file
                Assert.IsTrue(File.Exists(socketFile), "#A01");
            }
            // and disposing the UnixListener should delete the file
            Assert.IsFalse(File.Exists(socketFile), "#A02");
        }
 public void StartListening(object data)
 {
     this.listener = new UnixListener(this.path);
     Syscall.chmod(this.path, FilePermissions.DEFFILEMODE);
     if (this.server_thread == null)
     {
         this.listener.Start();
         string[] channelUri = new string[1];
         channelUri = new string[] { this.GetChannelUri() };
         this.channel_data.ChannelUris = channelUri;
         this.server_thread            = new Thread(new ThreadStart(this.WaitForConnections))
         {
             IsBackground = true
         };
         this.server_thread.Start();
     }
 }
예제 #5
0
        public void StartUnixSocket(string socketPath)
        {
            if (socketPath == null)
            {
                throw new ArgumentNullException("socketPath");
            }
            try {
                socketPath = Path.GetFullPath(socketPath);
                if (File.Exists(socketPath))
                {
                    var info = UnixFileSystemInfo.GetFileSystemEntry(socketPath);
                    if (info.IsSocket)
                    {
                        // if the file is a socket, it probably came from us, so overwrite it.
                        File.Delete(socketPath);
                    }
                    else
                    {
                        // don't want to overwrite anything that is not a socket file though.
                        var message = string.Format("The file '{0}' already exists.", socketPath);
                        throw new Exception(message);
                    }
                }

                // set file permission to user only.
                var prevUmask = Syscall.umask(
                    FilePermissions.S_IXUSR |
                    FilePermissions.S_IRWXG |
                    FilePermissions.S_IRWXO);
                // file is created in UnixListener()
                try {
                    listener = new UnixListener(socketPath);
                } finally {
                    Syscall.umask(prevUmask);
                }
                listener.Start();
                connectionThread = new Thread(AcceptConnections)
                {
                    Name = "UnixAgent"
                };
                connectionThread.Start();
            } catch (Exception ex) {
                var message = string.Format("Failed to start Unix Agent: {0}", ex.Message);
                throw new Exception(message, ex);
            }
        }
예제 #6
0
        public Server(string name, bool indexhelper, bool enable_network_svc)
        {
            // Use the default name when passed null
            if (name == null)
            {
                name = "socket";
            }

            this.socket_path        = Path.Combine(PathFinder.GetRemoteStorageDir(true), name);
            this.unix_listener      = new UnixListener(this.socket_path);
            this.enable_network_svc = enable_network_svc;
            this.indexhelper        = indexhelper;
            if (this.indexhelper)
            {
                this.enable_network_svc = false;
                this.webinterface       = false;
            }
        }