Skip to content

Commit

Permalink
Remove custom timeout timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Dec 23, 2019
1 parent 164c995 commit 00f4817
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ require (
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a
)

// replace github.com/SkycoinProject/dmsg => ../dmsg
replace github.com/SkycoinProject/dmsg => ../dmsg
13 changes: 0 additions & 13 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

const (
defaultRouteGroupKeepAliveInterval = 1 * time.Minute
defaultRouteGroupIOTimeout = 3 * time.Second
defaultReadChBufSize = 1024
)

Expand All @@ -46,15 +45,13 @@ func (timeoutError) Temporary() bool { return true }
type RouteGroupConfig struct {
ReadChBufSize int
KeepAliveInterval time.Duration
IOTimeout time.Duration
}

// DefaultRouteGroupConfig returns default RouteGroup config.
// Used by default if config is nil.
func DefaultRouteGroupConfig() *RouteGroupConfig {
return &RouteGroupConfig{
KeepAliveInterval: defaultRouteGroupKeepAliveInterval,
IOTimeout: defaultRouteGroupIOTimeout,
ReadChBufSize: defaultReadChBufSize,
}
}
Expand Down Expand Up @@ -149,15 +146,10 @@ func (rg *RouteGroup) Read(p []byte) (n int, err error) {
}
rg.mu.Unlock()

timeout := time.NewTimer(rg.cfg.IOTimeout)
defer timeout.Stop()

var data []byte
select {
case <-rg.readDeadline.Wait():
return 0, timeoutError{}
case <-timeout.C:
return 0, io.EOF
case data = <-rg.readCh:
}

Expand Down Expand Up @@ -200,14 +192,9 @@ func (rg *RouteGroup) Write(p []byte) (n int, err error) {
errCh, cancel := rg.writePacketAsync(tp, packet)
defer cancel()

timeout := time.NewTimer(rg.cfg.IOTimeout)
defer timeout.Stop()

select {
case <-rg.writeDeadline.Wait():
return 0, timeoutError{}
case <-timeout.C:
return 0, io.EOF
case err := <-errCh:
if err != nil {
return 0, err
Expand Down

0 comments on commit 00f4817

Please sign in to comment.