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
        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);
              }
        }
예제 #3
0
        static void Main(string[] args)
        {
            CSharpShell.InitStdOut();
            CompilerSettings settings = new CompilerSettings() { Unsafe = true };
            ConsoleReportPrinter printer = new ConsoleReportPrinter();

            CSharpShell shell = new CSharpShell(() => new Evaluator(new CompilerContext(settings, printer)) {
                InteractiveBaseClass = typeof(InteractiveBase),
                DescribeTypeExpressions = true,
                WaitOnTask = true
            });

            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 {
                        shell.ProcessConnection(s);
                    } finally {
                        s.Dispose();
                    }
                });
            }
        }