@@ -195,6 +195,7 @@ func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn
195
195
196
196
// Read implements net.Conn
197
197
func (s * UDPSession ) Read (b []byte ) (n int , err error ) {
198
+ RESET_TIMER:
198
199
var timeout * time.Timer
199
200
// deadline for current reading operation
200
201
var c <- chan time.Time
@@ -243,6 +244,10 @@ func (s *UDPSession) Read(b []byte) (n int, err error) {
243
244
// wait for read event or timeout or error
244
245
select {
245
246
case <- s .chReadEvent :
247
+ if timeout != nil {
248
+ timeout .Stop ()
249
+ goto RESET_TIMER
250
+ }
246
251
case <- c :
247
252
return 0 , errors .WithStack (errTimeout )
248
253
case <- s .chSocketReadError :
@@ -258,6 +263,7 @@ func (s *UDPSession) Write(b []byte) (n int, err error) { return s.WriteBuffers(
258
263
259
264
// WriteBuffers write a vector of byte slices to the underlying connection
260
265
func (s * UDPSession ) WriteBuffers (v [][]byte ) (n int , err error ) {
266
+ RESET_TIMER:
261
267
var timeout * time.Timer
262
268
var c <- chan time.Time
263
269
if ! s .wd .IsZero () {
@@ -308,6 +314,10 @@ func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error) {
308
314
309
315
select {
310
316
case <- s .chWriteEvent :
317
+ if timeout != nil {
318
+ timeout .Stop ()
319
+ goto RESET_TIMER
320
+ }
311
321
case <- c :
312
322
return 0 , errors .WithStack (errTimeout )
313
323
case <- s .chSocketWriteError :
@@ -375,9 +385,9 @@ func (s *UDPSession) RemoteAddr() net.Addr { return s.remote }
375
385
// SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.
376
386
func (s * UDPSession ) SetDeadline (t time.Time ) error {
377
387
s .mu .Lock ()
378
- defer s .mu .Unlock ()
379
388
s .rd = t
380
389
s .wd = t
390
+ s .mu .Unlock ()
381
391
s .notifyReadEvent ()
382
392
s .notifyWriteEvent ()
383
393
return nil
@@ -386,17 +396,17 @@ func (s *UDPSession) SetDeadline(t time.Time) error {
386
396
// SetReadDeadline implements the Conn SetReadDeadline method.
387
397
func (s * UDPSession ) SetReadDeadline (t time.Time ) error {
388
398
s .mu .Lock ()
389
- defer s .mu .Unlock ()
390
399
s .rd = t
400
+ s .mu .Unlock ()
391
401
s .notifyReadEvent ()
392
402
return nil
393
403
}
394
404
395
405
// SetWriteDeadline implements the Conn SetWriteDeadline method.
396
406
func (s * UDPSession ) SetWriteDeadline (t time.Time ) error {
397
407
s .mu .Lock ()
398
- defer s .mu .Unlock ()
399
408
s .wd = t
409
+ s .mu .Unlock ()
400
410
s .notifyWriteEvent ()
401
411
return nil
402
412
}
0 commit comments