protected static Mono.Unix.UnixEndPoint CreateEndPoint(string path) { if (path == null) { throw new ArgumentNullException("path"); } Mono.Unix.UnixEndPoint ep = new Mono.Unix.UnixEndPoint( path); if (System.IO.File.Exists(path)) { System.Net.Sockets.Socket conn = new System.Net.Sockets.Socket( System.Net.Sockets.AddressFamily.Unix, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.IP); try { conn.Connect(ep); conn.Close(); throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, Strings.UnixSocket_AlreadyExists, path)); } catch (System.Net.Sockets.SocketException) { } System.IO.File.Delete(path); } return(ep); }
protected UnixSocket(Mono.Unix.UnixEndPoint localEndPoint) : base(System.Net.Sockets.AddressFamily.Unix, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.IP, localEndPoint) { }
protected static Mono.Unix.UnixEndPoint CreateEndPoint (string path) { if (path == null) throw new ArgumentNullException ("path"); Mono.Unix.UnixEndPoint ep = new Mono.Unix.UnixEndPoint ( path); if (System.IO.File.Exists (path)) { System.Net.Sockets.Socket conn = new System.Net.Sockets.Socket ( System.Net.Sockets.AddressFamily.Unix, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.IP); try { conn.Connect (ep); conn.Close (); throw new InvalidOperationException ( string.Format (CultureInfo.CurrentCulture, Strings.UnixSocket_AlreadyExists, path)); } catch (System.Net.Sockets.SocketException) { } System.IO.File.Delete (path); } return ep; }
/// <summary> /// Defines the unix socket path to listen on. The socket file can't exist before this method is called and Fos's process has to have /// permissions to remove the file when the server is stopped. /// </summary> public void Bind(string socketPath) { unixSocketFilePath = socketPath; var endpoint = new Mono.Unix.UnixEndPoint(socketPath); unixListenSocket.Bind(endpoint); }
private Stream CreateSocketStream(IPAddress ip, bool unix) { EndPoint endPoint; if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && unix) { endPoint = new Mono.Unix.UnixEndPoint(hostList); } else { endPoint = new IPEndPoint(ip, (int)port); } Socket socket = unix ? new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP) : new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (keepalive > 0) { SetKeepAlive(socket, keepalive); } IAsyncResult ias = socket.BeginConnect(endPoint, null, null); if (!ias.AsyncWaitHandle.WaitOne((int)timeOut * 1000)) { socket.Dispose(); return(null); } try { socket.EndConnect(ias); } catch (Exception) { socket.Dispose(); throw; } MyNetworkStream stream = new MyNetworkStream(socket, true); GC.SuppressFinalize(socket); GC.SuppressFinalize(stream); return(stream); }
private Stream CreateSocketStream(IPAddress ip, bool unix) { EndPoint endPoint; if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && unix) endPoint = new Mono.Unix.UnixEndPoint(hostList); else endPoint = new IPEndPoint(ip, (int)port); Socket socket = unix ? new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP) : new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (keepalive > 0) { SetKeepAlive(socket, keepalive); } IAsyncResult ias = socket.BeginConnect(endPoint, null, null); if (!ias.AsyncWaitHandle.WaitOne((int)timeOut * 1000)) { socket.Dispose(); return null; } try { socket.EndConnect(ias); } catch (Exception) { socket.Dispose(); throw; } MyNetworkStream stream = new MyNetworkStream(socket, true); GC.SuppressFinalize(socket); GC.SuppressFinalize(stream); return stream; }
/// <summary> /// Defines the unix socket path to listen on. /// </summary> public void Bind(string socketPath) { var endpoint = new Mono.Unix.UnixEndPoint(socketPath); unixListenSocket.Bind (endpoint); }
private void loop() { #if UNIX Debug.WriteLine(this + ": starting ConsoleInterface ..."); string name = System.Net.Dns.GetHostName(); try { EndPoint endPoint = new Mono.Unix.UnixEndPoint(((SettingsHost)ServiceManager.Services[typeof(SettingsHost)]).Settings.SocketFile); Socket sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); sock.Connect(endPoint); while (true) { Console.Write("storm@" + name + "# "); string cmd = Console.ReadLine(); cmd.Trim(); if (cmd == "help") { Console.WriteLine("shutdown restart status"); } else { sock.Send(Encoding.ASCII.GetBytes(cmd)); if (cmd == "shutdown") { Debug.WriteLine(this + ": exit loop ..."); sock.Close(); return; } } } } catch (Exception e) { //Console.WriteLine(this + ": " + e.ToString()); } Debug.WriteLine(this + ": exit loop ..."); #endif }