-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconn.go
More file actions
45 lines (41 loc) · 770 Bytes
/
conn.go
File metadata and controls
45 lines (41 loc) · 770 Bytes
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
// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.
package plug
type conn struct {
iC chan *packet
oC chan *packet
doneC chan struct{}
}
func newConn(iC, oC chan *packet, doneC chan struct{}) *conn {
res := &conn{}
res.iC = iC
res.oC = oC
res.doneC = doneC
return res
}
func (c *conn) serve() {
iC := c.iC
oC := c.oC
doneC := c.doneC
var m int
var err error
for {
select {
case <-doneC:
return
case pkt := <-iC:
if pkt.snk == nil {
m, err = pkt.src.Receive(pkt.samples)
} else {
err = pkt.snk.Send(pkt.samples)
}
pkt.n = m
pkt.err = err
select {
case oC <- pkt:
case <-doneC:
return
}
}
}
}