-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathrw.go
51 lines (44 loc) · 1.07 KB
/
rw.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
package requests
import (
"errors"
"io"
"net"
)
type readWriteCloser struct {
body io.ReadCloser
conn *connecotr
isClosed bool
err error
}
func (obj *readWriteCloser) Conn() net.Conn {
return obj.conn.Conn.(net.Conn)
}
func (obj *readWriteCloser) Read(p []byte) (n int, err error) {
if obj.isClosed {
return 0, obj.err
}
i, err := obj.body.Read(p)
if err == io.EOF {
obj.Close()
}
obj.err = err
return i, err
}
func (obj *readWriteCloser) Proxys() []Address {
return obj.conn.proxys
}
var errGospiderBodyClose = errors.New("gospider body close error")
func (obj *readWriteCloser) Close() (err error) {
obj.isClosed = true
obj.conn.bodyCnl(errGospiderBodyClose)
return obj.body.Close() //reuse conn
}
// safe close conn
func (obj *readWriteCloser) CloseConn() {
obj.conn.bodyCnl(errors.New("readWriterCloser close conn"))
obj.conn.safeCnl(errors.New("readWriterCloser close conn"))
}
// force close conn
func (obj *readWriteCloser) ForceCloseConn() {
obj.conn.CloseWithError(errConnectionForceClosed)
}