forked from googollee/go-engine.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ioutil.go
50 lines (43 loc) · 820 Bytes
/
ioutil.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
47
48
49
50
package engineio
import (
"github.com/googollee/go-engine.io/parser"
"io"
"sync"
)
type connReader struct {
*parser.PacketDecoder
closeChan chan struct{}
}
func newConnReader(d *parser.PacketDecoder, closeChan chan struct{}) *connReader {
return &connReader{
PacketDecoder: d,
closeChan: closeChan,
}
}
func (r *connReader) Close() error {
if r.closeChan == nil {
return nil
}
r.closeChan <- struct{}{}
r.closeChan = nil
return nil
}
type connWriter struct {
io.WriteCloser
locker *sync.Mutex
}
func newConnWriter(w io.WriteCloser, locker *sync.Mutex) *connWriter {
return &connWriter{
WriteCloser: w,
locker: locker,
}
}
func (w *connWriter) Close() error {
defer func() {
if w.locker != nil {
w.locker.Unlock()
w.locker = nil
}
}()
return w.WriteCloser.Close()
}