Beispiel #1
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");
        }
Beispiel #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);
              }
        }
        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 ();
            }
        }
Beispiel #4
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;
			}
		}
Beispiel #5
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();
                    }
                });
            }
        }