| 1 |
// Copyright 2015 CoreOS, Inc. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
package activation |
| 16 |
|
| 17 |
import ( |
| 18 |
"net" |
| 19 |
) |
| 20 |
|
| 21 |
// PacketConns returns a slice containing a net.PacketConn for each matching socket type |
| 22 |
// passed to this process. |
| 23 |
// |
| 24 |
// The order of the file descriptors is preserved in the returned slice. |
| 25 |
// Nil values are used to fill any gaps. For example if systemd were to return file descriptors |
| 26 |
// corresponding with "udp, tcp, udp", then the slice would contain {net.PacketConn, nil, net.PacketConn} |
| 27 |
func PacketConns() ([]net.PacketConn, error) { |
| 28 |
files := Files(true) |
| 29 |
conns := make([]net.PacketConn, len(files)) |
| 30 |
|
| 31 |
for i, f := range files { |
| 32 |
if pc, err := net.FilePacketConn(f); err == nil { |
| 33 |
conns[i] = pc |
| 34 |
f.Close() |
| 35 |
} |
| 36 |
} |
| 37 |
return conns, nil |
| 38 |
} |