Skip to content

Commit d26364a

Browse files
committed
fix for issue: #259
1 parent 16b0610 commit d26364a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

sess.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn
195195

196196
// Read implements net.Conn
197197
func (s *UDPSession) Read(b []byte) (n int, err error) {
198+
RESET_TIMER:
198199
var timeout *time.Timer
199200
// deadline for current reading operation
200201
var c <-chan time.Time
@@ -243,6 +244,10 @@ func (s *UDPSession) Read(b []byte) (n int, err error) {
243244
// wait for read event or timeout or error
244245
select {
245246
case <-s.chReadEvent:
247+
if timeout != nil {
248+
timeout.Stop()
249+
goto RESET_TIMER
250+
}
246251
case <-c:
247252
return 0, errors.WithStack(errTimeout)
248253
case <-s.chSocketReadError:
@@ -258,6 +263,7 @@ func (s *UDPSession) Write(b []byte) (n int, err error) { return s.WriteBuffers(
258263

259264
// WriteBuffers write a vector of byte slices to the underlying connection
260265
func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error) {
266+
RESET_TIMER:
261267
var timeout *time.Timer
262268
var c <-chan time.Time
263269
if !s.wd.IsZero() {
@@ -308,6 +314,10 @@ func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error) {
308314

309315
select {
310316
case <-s.chWriteEvent:
317+
if timeout != nil {
318+
timeout.Stop()
319+
goto RESET_TIMER
320+
}
311321
case <-c:
312322
return 0, errors.WithStack(errTimeout)
313323
case <-s.chSocketWriteError:
@@ -375,9 +385,9 @@ func (s *UDPSession) RemoteAddr() net.Addr { return s.remote }
375385
// SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.
376386
func (s *UDPSession) SetDeadline(t time.Time) error {
377387
s.mu.Lock()
378-
defer s.mu.Unlock()
379388
s.rd = t
380389
s.wd = t
390+
s.mu.Unlock()
381391
s.notifyReadEvent()
382392
s.notifyWriteEvent()
383393
return nil
@@ -386,17 +396,17 @@ func (s *UDPSession) SetDeadline(t time.Time) error {
386396
// SetReadDeadline implements the Conn SetReadDeadline method.
387397
func (s *UDPSession) SetReadDeadline(t time.Time) error {
388398
s.mu.Lock()
389-
defer s.mu.Unlock()
390399
s.rd = t
400+
s.mu.Unlock()
391401
s.notifyReadEvent()
392402
return nil
393403
}
394404

395405
// SetWriteDeadline implements the Conn SetWriteDeadline method.
396406
func (s *UDPSession) SetWriteDeadline(t time.Time) error {
397407
s.mu.Lock()
398-
defer s.mu.Unlock()
399408
s.wd = t
409+
s.mu.Unlock()
400410
s.notifyWriteEvent()
401411
return nil
402412
}

0 commit comments

Comments
 (0)