(protocol, hostAddr string)
| 422 | } |
| 423 | |
| 424 | func 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 |
| 459 | func portReserverPidFilePath(namespace, id string) string { |
no test coverage detected
searching dependent graphs…