@@ -89,10 +89,10 @@ func (rl *Relay) dialContext(ctx context.Context, metadata *M.Metadata) (rc *rel
8989
9090 if rl .noDelay {
9191 if _ , err = req .WriteTo (c ); err != nil {
92- return
92+ return rc , err
9393 }
9494 if err = readRelayResponse (c ); err != nil {
95- return
95+ return rc , err
9696 }
9797 }
9898
@@ -101,22 +101,22 @@ func (rl *Relay) dialContext(ctx context.Context, metadata *M.Metadata) (rc *rel
101101 rc = newRelayConn (c , metadata .Addr (), rl .noDelay , false )
102102 if ! rl .noDelay {
103103 if _ , err = req .WriteTo (rc .wbuf ); err != nil {
104- return
104+ return rc , err
105105 }
106106 }
107107 case M .UDP :
108108 rc = newRelayConn (c , metadata .Addr (), rl .noDelay , true )
109109 if ! rl .noDelay {
110110 if _ , err = req .WriteTo (rc .wbuf ); err != nil {
111- return
111+ return rc , err
112112 }
113113 }
114114 default :
115115 err = fmt .Errorf ("network %s is unsupported" , metadata .Network )
116- return
116+ return rc , err
117117 }
118118
119- return
119+ return rc , err
120120}
121121
122122type relayConn struct {
@@ -151,7 +151,7 @@ func (rc *relayConn) Read(b []byte) (n int, err error) {
151151 }
152152 })
153153 if err != nil {
154- return
154+ return n , err
155155 }
156156
157157 if ! rc .udp {
@@ -161,7 +161,7 @@ func (rc *relayConn) Read(b []byte) (n int, err error) {
161161 var bb [2 ]byte
162162 _ , err = io .ReadFull (rc .Conn , bb [:])
163163 if err != nil {
164- return
164+ return n , err
165165 }
166166
167167 dLen := int (binary .BigEndian .Uint16 (bb [:]))
@@ -174,7 +174,7 @@ func (rc *relayConn) Read(b []byte) (n int, err error) {
174174 _ , err = io .ReadFull (rc .Conn , buf )
175175 n = copy (b , buf )
176176
177- return
177+ return n , err
178178}
179179
180180func (rc * relayConn ) WriteTo (b []byte , _ net.Addr ) (int , error ) {
@@ -194,15 +194,15 @@ func (rc *relayConn) tcpWrite(b []byte) (n int, err error) {
194194 rc .wbuf .Write (b )
195195 _ , err = rc .Conn .Write (rc .wbuf .Bytes ())
196196 rc .wbuf .Reset ()
197- return
197+ return n , err
198198 }
199199 return rc .Conn .Write (b )
200200}
201201
202202func (rc * relayConn ) udpWrite (b []byte ) (n int , err error ) {
203203 if len (b ) > math .MaxUint16 {
204204 err = errors .New ("write: data maximum exceeded" )
205- return
205+ return n , err
206206 }
207207
208208 n = len (b )
@@ -212,14 +212,14 @@ func (rc *relayConn) udpWrite(b []byte) (n int, err error) {
212212 rc .wbuf .Write (bb [:])
213213 rc .wbuf .Write (b )
214214 _ , err = rc .wbuf .WriteTo (rc .Conn )
215- return
215+ return n , err
216216 }
217217
218218 var bb [2 ]byte
219219 binary .BigEndian .PutUint16 (bb [:], uint16 (len (b )))
220220 _ , err = rc .Conn .Write (bb [:])
221221 if err != nil {
222- return
222+ return n , err
223223 }
224224 return rc .Conn .Write (b )
225225}
0 commit comments