1 /** 2 * This file is part of DCD, a development tool for the D programming language. 3 * Copyright (C) 2015 Brian Schott 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 module dcd.common.socket; 20 21 import core.sys.posix.unistd; // getuid 22 import std.format; 23 import std.process; 24 import std.path; 25 26 version (OSX) version = haveUnixSockets; 27 version (linux) version = haveUnixSockets; 28 version (BSD) version = haveUnixSockets; 29 version (FreeBSD) version = haveUnixSockets; 30 31 enum DEFAULT_PORT_NUMBER = 9166; 32 33 string generateSocketName() 34 { 35 version (haveUnixSockets) 36 { 37 immutable string socketFileName = "dcd-%d.socket".format(getuid()); 38 version (OSX) 39 return buildPath("/", "var", "tmp", socketFileName); 40 else 41 { 42 immutable string xdg = environment.get("XDG_RUNTIME_DIR"); 43 return xdg is null ? buildPath("/", "tmp", socketFileName) : buildPath(xdg, 44 "dcd.socket"); 45 } 46 } 47 else 48 { 49 assert(0); 50 } 51 }