forked from p9c/pod-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdconn.go
74 lines (62 loc) · 1.57 KB
/
stdconn.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package stdconn
import (
"fmt"
"io"
"net"
"runtime"
"time"
qu "github.com/l0k18/pod/pkg/util/quit"
)
type StdConn struct {
io.ReadCloser
io.WriteCloser
Quit qu.C
}
func New(in io.ReadCloser, out io.WriteCloser, quit qu.C) (s *StdConn) {
s = &StdConn{in, out, quit}
_, file, line, _ := runtime.Caller(1)
o := fmt.Sprintf("%s:%d", file, line)
Debug("new StdConn at", o)
// go func() {
// <-quit.Wait()
// Debug("!!!! closing StdConn", o)
// Debug(string(debug.Stack()))
// // time.Sleep(time.Second*2)
// if err := s.ReadCloser.Close(); Check(err) {
// }
// if err := s.WriteCloser.Close(); Check(err) {
// }
// // Debug(interrupt.GoroutineDump())
// }()
return
}
func (s *StdConn) Read(b []byte) (n int, err error) {
return s.ReadCloser.Read(b)
}
func (s *StdConn) Write(b []byte) (n int, err error) {
return s.WriteCloser.Write(b)
}
func (s *StdConn) Close() (err error) {
s.Quit.Q()
return
}
func (s *StdConn) LocalAddr() (addr net.Addr) {
// this is a no-op as it is not relevant to the type of connection
return
}
func (s *StdConn) RemoteAddr() (addr net.Addr) {
// this is a no-op as it is not relevant to the type of connection
return
}
func (s *StdConn) SetDeadline(t time.Time) (err error) {
// this is a no-op as it is not relevant to the type of connection
return
}
func (s *StdConn) SetReadDeadline(t time.Time) (err error) {
// this is a no-op as it is not relevant to the type of connection
return
}
func (s *StdConn) SetWriteDeadline(t time.Time) (err error) {
// this is a no-op as it is not relevant to the type of connection
return
}