@@ -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
137138func (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
141161func (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
148165func (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
155169func (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
162173func (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
169177func (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