MCPcopy Create free account
hub / github.com/containerd/nerdctl / reserveSocket

Function reserveSocket

pkg/ocihook/ocihook.go:424–456  ·  view source on GitHub ↗
(protocol, hostAddr string)

Source from the content-addressed store, hash-verified

422}
423
424func reserveSocket(protocol, hostAddr string) (*os.File, error) {
425 type filer interface {
426 File() (*os.File, error)
427 }
428 var f filer
429 switch {
430 case strings.HasPrefix(protocol, "tcp"):
431 l, err := net.Listen(protocol, hostAddr)
432 if err != nil {
433 return nil, err
434 }
435 defer l.Close()
436 var ok bool
437 f, ok = l.(filer)
438 if !ok {
439 return nil, fmt.Errorf("cannot get file descriptor from the listener of type %T", l)
440 }
441 case strings.HasPrefix(protocol, "udp"):
442 l, err := net.ListenPacket(protocol, hostAddr)
443 if err != nil {
444 return nil, err
445 }
446 defer l.Close()
447 var ok bool
448 f, ok = l.(filer)
449 if !ok {
450 return nil, fmt.Errorf("cannot get file descriptor from the listener of type %T", l)
451 }
452 default:
453 return nil, fmt.Errorf("unsupported protocol %q", protocol)
454 }
455 return f.File()
456}
457
458// portReserverPidFilePath returns /run/nerdctl/<namespace>/<id>/port-reserver.pid
459func portReserverPidFilePath(namespace, id string) string {

Callers 1

applyNetworkSettingsFunction · 0.85

Calls 2

FileMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…