mirror of
https://git.mills.io/kayos/bitraft.git
synced 2024-06-27 09:19:00 +00:00
added keepalives
This commit is contained in:
parent
530ad6db50
commit
4e4962694d
19
server.go
19
server.go
@ -7,11 +7,13 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
"github.com/syndtr/goleveldb/leveldb/filter"
|
||||
@ -22,6 +24,8 @@ import (
|
||||
"github.com/tidwall/redlog"
|
||||
)
|
||||
|
||||
const defaultTCPKeepAlive = time.Minute * 5
|
||||
|
||||
var (
|
||||
errSyntaxError = errors.New("syntax error")
|
||||
log = redlog.New(os.Stderr)
|
||||
@ -36,6 +40,21 @@ func ListenAndServe(addr, join, dir, logdir string, fastlog bool, consistency, d
|
||||
}
|
||||
opts.Consistency = consistency
|
||||
opts.Durability = durability
|
||||
opts.ConnAccept = func(conn redcon.Conn) bool {
|
||||
if tcp, ok := conn.NetConn().(*net.TCPConn); ok {
|
||||
if err := tcp.SetKeepAlive(true); err != nil {
|
||||
log.Warningf("could not set keepalive: %s",
|
||||
tcp.RemoteAddr().String())
|
||||
} else {
|
||||
err := tcp.SetKeepAlivePeriod(defaultTCPKeepAlive)
|
||||
if err != nil {
|
||||
log.Warningf("could not set keepalive period: %s",
|
||||
tcp.RemoteAddr().String())
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
m, err := NewMachine(dir, addr)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user