blob: 1a2d89eb6fe6f6dbfc2a184cdc5376b7f1e88455 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package soundbox
import (
"context"
"io"
"net"
"time"
)
const bufferSize = 20
const writeTimeout = 1 * time.Second
func streamContext(ctx context.Context, r io.Reader, targets []net.HardwareAddr) error {
conns := make([]net.Conn, 0)
for _, target := range targets {
conn, err := dialContext(ctx, target)
if err != nil {
return err
}
conns = append(conns, conn)
}
defer func() {
for _, conn := range conns {
conn.Close()
}
}()
writers := make([]io.Writer, 0)
for _, conn := range conns {
writers = append(writers, conn)
}
mw := io.MultiWriter(writers...)
_, err := io.Copy(mw, r)
return err
}
|