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...) buf := make([]byte, bufferSize) _, err := io.CopyBuffer(mw, r, buf) return err }