MCPcopy
hub / github.com/google/gvisor / createNullSocket

Function createNullSocket

test/uds/uds.go:151–184  ·  view source on GitHub ↗

createNullSocket creates a socket that reads anything received. Only works for dgram sockets.

(path string, protocol int)

Source from the content-addressed store, hash-verified

149//
150// Only works for dgram sockets.
151func createNullSocket(path string, protocol int) (cleanup func(), err error) {
152 fd, err := unix.Socket(unix.AF_UNIX, protocol, 0)
153 if err != nil {
154 return nil, fmt.Errorf("error creating null(%d) socket: %v", protocol, err)
155 }
156
157 if err := unix.Bind(fd, &unix.SockaddrUnix{Name: path}); err != nil {
158 return nil, fmt.Errorf("error binding null(%d) socket: %v", protocol, err)
159 }
160
161 s, err := unet.NewSocket(fd)
162 if err != nil {
163 return nil, fmt.Errorf("error creating null(%d) unet socket: %v", protocol, err)
164 }
165
166 go func() {
167 buf := make([]byte, 512)
168 for {
169 n, err := s.Read(buf)
170 if err != nil {
171 log.Warningf("failed to read: %d, %v", n, err)
172 return
173 }
174 }
175 }()
176
177 cleanup = func() {
178 if err := s.Close(); err != nil {
179 log.Warningf("Failed to close null(%d) socket: %v", protocol, err)
180 }
181 }
182
183 return cleanup, nil
184}
185
186// createPipeWriter creates a pipe that writes a sequence of bytes starting from
187// 0 to 256, wrapping it back to 0.

Callers

nothing calls this directly

Calls 7

ReadMethod · 0.95
CloseMethod · 0.95
NewSocketFunction · 0.92
WarningfFunction · 0.92
SocketMethod · 0.65
ErrorfMethod · 0.65
BindMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…