public static bool TryCreateUnixSocket(string path, out Socket socket, string perm = null) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { throw new ArgumentException("path must not be empty", "path"); } socket = null; try { string realPath; if (path.StartsWith("\\0", StringComparison.Ordinal) && path.IndexOf("\\0", 1, StringComparison.Ordinal) < 0) { realPath = '\0' + path.Substring(2); } else { realPath = path; } if (perm == null) { socket = new UnixSocket(realPath); Logger.Write(LogLevel.Debug, "Listening on file {0} with default permissions", realPath); } else { ushort uperm; if (!UInt16.TryParse(perm, out uperm)) { Logger.Write(LogLevel.Error, "Error parsing permissions \"{0}\". Use octal.", perm); return(false); } uperm = Convert.ToUInt16(uperm.ToString(), 8); socket = new UnixSocket(realPath, uperm); Logger.Write(LogLevel.Debug, "Listening on file {0} with permissions {1}", realPath, Convert.ToString(uperm, 8)); } } catch (System.Net.Sockets.SocketException e) { Logger.Write(LogLevel.Error, "Error creating the socket: {0}", e.Message); return(false); } return(true); }
public static bool TryCreateUnixSocket(string path, out Socket socket, string perm = null) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { throw new ArgumentException("path must not be empty", "path"); } socket = null; try { string realPath; if (path.StartsWith("\\0") && path.IndexOf('\0', 1) < 0) { realPath = '\0' + path.Substring(2); } else { realPath = path; } ushort uperm = UInt16.MaxValue; if (perm != null) { if (!UInt16.TryParse(perm, out uperm)) { Logger.Write(LogLevel.Error, "Error parsing permissions. Use octal"); return(false); } socket = new UnixSocket(realPath, uperm); } socket = new UnixSocket(realPath); } catch (System.Net.Sockets.SocketException e) { Logger.Write(LogLevel.Error, "Error creating the socket: {0}", e.Message); return(false); } Logger.Write(LogLevel.Debug, "Listening on file: {0}", path); return(true); }