-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulticast.go
46 lines (37 loc) · 1.03 KB
/
multicast.go
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
40
41
42
43
44
45
46
package netx
import (
"io"
"github.com/simia-tech/netx/value"
)
type multicast struct {
listener io.ReadCloser
conn io.WriteCloser
}
// ListenAndDialMulticast listens to the provided readAddress and dials the provided writeAddress. The result is combined
// in the returned io.ReadWriteCloser interface.
func ListenAndDialMulticast(network, readAddress, writeAddress string, options ...value.Option) (io.ReadWriteCloser, error) {
listener, err := ListenMulticast(network, readAddress, options...)
if err != nil {
return nil, err
}
conn, err := DialMulticast(network, writeAddress, options...)
if err != nil {
return nil, err
}
return &multicast{listener: listener, conn: conn}, nil
}
func (m *multicast) Read(buffer []byte) (int, error) {
return m.listener.Read(buffer)
}
func (m *multicast) Write(buffer []byte) (int, error) {
return m.conn.Write(buffer)
}
func (m *multicast) Close() error {
if err := m.listener.Close(); err != nil {
return err
}
if err := m.conn.Close(); err != nil {
return err
}
return nil
}