识别 IPC 连接的路径
【Identifying paths for IPC connections】
net.connect()、net.createConnection()、server.listen() 和 socket.connect() 采用 path 参数来识别 IPC 端点。
在Unix上,本地域也称为Unix域。路径是
文件系统路径名。当路径名的长度为 时,它会抛出错误
大于“sizeof(sockaddr_un.sun_path)”的长度。典型的数值有
Linux上是107字节,macOS上是103字节。如果Node.js API抽象会生成
Unix 域套接字,它也会解除 Unix 域套接字的关联。对于
例如,net.createServer() 可以创建 Unix 域套接字,并且
server.close() 会解除关联。但如果用户创建了Unix域
在这些抽象之外,用户需要将其移除。一样
当Node.js API创建Unix域套接字时,程序会生效,但程序随后
撞击声。简而言之,Unix 域套接字会在文件系统中可见,且
会持续存在直到解除绑定。在 Linux 上,你可以通过添加 Unix 抽象套接字来使用
“\0” 映射到路径起始,例如 “\0abstract”。通往Unix的道路
抽象套接字在文件系统中不可见,且会自动消失
当所有对套接字的开引用都关闭时。
【On Unix, the local domain is also known as the Unix domain. The path is a
file system pathname. It will throw an error when the length of pathname is
greater than the length of sizeof(sockaddr_un.sun_path). Typical values are
107 bytes on Linux and 103 bytes on macOS. If a Node.js API abstraction creates
the Unix domain socket, it will unlink the Unix domain socket as well. For
example, net.createServer() may create a Unix domain socket and
server.close() will unlink it. But if a user creates the Unix domain
socket outside of these abstractions, the user will need to remove it. The same
applies when a Node.js API creates a Unix domain socket but the program then
crashes. In short, a Unix domain socket will be visible in the file system and
will persist until unlinked. On Linux, You can use Unix abstract socket by adding
\0 to the beginning of the path, such as \0abstract. The path to the Unix
abstract socket is not visible in the file system and it will disappear automatically
when all open references to the socket are closed.】
在 Windows 上,本地域使用命名管道来实现。路径必须指向 \?\pipe\ 或 \\.\pipe\ 中的一个条目。任何字符都是允许的,但后者可能会对管道名称进行一些处理,例如解析 .. 序列。尽管看起来可能不是这样,管道命名空间是平面的。管道不会持久存在。当最后一个对它的引用关闭时,管道会被移除。与 Unix 域套接字不同,Windows 会在拥有它的进程退出时关闭并移除管道。
【On Windows, the local domain is implemented using a named pipe. The path must
refer to an entry in \\?\pipe\ or \\.\pipe\. Any characters are permitted,
but the latter may do some processing of pipe names, such as resolving ..
sequences. Despite how it might look, the pipe namespace is flat. Pipes will
not persist. They are removed when the last reference to them is closed.
Unlike Unix domain sockets, Windows will close and remove the pipe when the
owning process exits.】
JavaScript 字符串转义要求路径使用额外的反斜杠进行转义,例如:
【JavaScript string escaping requires paths to be specified with extra backslash escaping such as:】
net.createServer().listen(
path.join('\\\\?\\pipe', process.cwd(), 'myctl'));