Skip to content

Commit

Permalink
process accept error
Browse files Browse the repository at this point in the history
  • Loading branch information
name5566 committed Oct 18, 2015
1 parent d125311 commit 85027ce
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions network/tcp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/name5566/leaf/log"
"net"
"sync"
"time"
)

type TCPServer struct {
Expand Down Expand Up @@ -62,11 +63,26 @@ func (server *TCPServer) run() {
server.wgLn.Add(1)
defer server.wgLn.Done()

var tempDelay time.Duration
for {
conn, err := server.ln.Accept()
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
if tempDelay == 0 {
tempDelay = 5 * time.Millisecond
} else {
tempDelay *= 2
}
if max := 1 * time.Second; tempDelay > max {
tempDelay = max
}
log.Release("accept error: %v; retrying in %v", err, tempDelay)
time.Sleep(tempDelay)
continue
}
return
}
tempDelay = 0

server.mutexConns.Lock()
if len(server.conns) >= server.MaxConnNum {
Expand Down

0 comments on commit 85027ce

Please sign in to comment.