Skip to content

Commit 737f456

Browse files
committed
test: improve coverage
1 parent d1c82ea commit 737f456

6 files changed

Lines changed: 3091 additions & 16 deletions

File tree

client4.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/asciimoth/bufpool"
1212
"github.com/asciimoth/gonnect"
13+
"github.com/asciimoth/gonnect/helpers"
1314
"github.com/asciimoth/socksgo/protocol"
1415
)
1516

@@ -135,41 +136,45 @@ func (w *tcpConnWrapper) ReadFrom(r io.Reader) (int64, error) {
135136
}
136137

137138
func (w *tcpConnWrapper) WriteTo(writer io.Writer) (int64, error) {
138-
return io.Copy(writer, w)
139+
buf := make([]byte, 32*1024)
140+
var total int64
141+
for {
142+
nr, er := w.Read(buf)
143+
if nr > 0 {
144+
nw, ew := writer.Write(buf[:nr])
145+
if nw > 0 {
146+
total += int64(nw)
147+
}
148+
if ew != nil {
149+
return total, ew
150+
}
151+
if nr != nw {
152+
return total, io.ErrShortWrite
153+
}
154+
}
155+
if er != nil {
156+
return total, helpers.ClosedNetworkErrToNil(er)
157+
}
158+
}
139159
}
140160

141161
func (w *tcpConnWrapper) SetKeepAlive(keepalive bool) error {
142-
if tc, ok := w.Conn.(gonnect.TCPConn); ok {
143-
return tc.SetKeepAlive(keepalive)
144-
}
145162
return nil
146163
}
147164

148165
func (w *tcpConnWrapper) SetKeepAliveConfig(config net.KeepAliveConfig) error {
149-
if tc, ok := w.Conn.(gonnect.TCPConn); ok {
150-
return tc.SetKeepAliveConfig(config)
151-
}
152166
return nil
153167
}
154168

155169
func (w *tcpConnWrapper) SetKeepAlivePeriod(d time.Duration) error {
156-
if tc, ok := w.Conn.(gonnect.TCPConn); ok {
157-
return tc.SetKeepAlivePeriod(d)
158-
}
159170
return nil
160171
}
161172

162173
func (w *tcpConnWrapper) SetLinger(sec int) error {
163-
if tc, ok := w.Conn.(gonnect.TCPConn); ok {
164-
return tc.SetLinger(sec)
165-
}
166174
return nil
167175
}
168176

169177
func (w *tcpConnWrapper) SetNoDelay(noDelay bool) error {
170-
if tc, ok := w.Conn.(gonnect.TCPConn); ok {
171-
return tc.SetNoDelay(noDelay)
172-
}
173178
return nil
174179
}
175180

0 commit comments

Comments
 (0)