跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

dgram_unix.go

45 行 · 1.4 KB历史下载
1//go:build !windows
2
3// SPDX-FileCopyrightText: Copyright The Lima Authors
4// SPDX-License-Identifier: Apache-2.0
5
6package qemu
7
8import (
9 "net"
10 "os"
11 "syscall"
12)
13
14// dgramPair returns the two ends of a connected datagram socket, as vz does
15// for its network: ours as a net.Conn for the netstack, and QEMU's as a file
16// to pass to it (-netdev dgram,local.type=fd). A datagram is a frame, and
17// unix datagram sockets neither lose nor reorder them: a full buffer blocks
18// the sender.
19func dgramPair() (ours net.Conn, qemu *os.File, err error) {
20 // The descriptors must not leak into the processes started meanwhile:
21 // QEMU gets its end through ExtraFiles.
22 syscall.ForkLock.RLock()
23 fds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_DGRAM, 0)
24 if err == nil {
25 syscall.CloseOnExec(fds[0])
26 syscall.CloseOnExec(fds[1])
27 }
28 syscall.ForkLock.RUnlock()
29 if err != nil {
30 return nil, nil, err
31 }
32 for _, fd := range fds {
33 // Best effort: the kernel caps these (net.core.wmem_max, rmem_max).
34 _ = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_SNDBUF, 1<<20)
35 _ = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_RCVBUF, 4<<20)
36 }
37 f := os.NewFile(uintptr(fds[0]), "usernet-dgram")
38 defer f.Close()
39 ours, err = net.FileConn(f)
40 if err != nil {
41 syscall.Close(fds[1])
42 return nil, nil, err
43 }
44 return ours, os.NewFile(uintptr(fds[1]), "qemu-dgram"), nil
45}