Skip to content

Commit

Permalink
Add an option which should enable setting a custom server ping status
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Jul 31, 2024
1 parent d82b4c9 commit 091e42b
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ type OnShutdownCallback func(err error)

type IprotoServer struct {
sync.Mutex
conn net.Conn
reader *bufio.Reader
writer *bufio.Writer
uuid string
salt []byte // base64-encoded salt
ctx context.Context
cancel context.CancelFunc
handler QueryHandler
onShutdown OnShutdownCallback
output chan *BinaryPacket
closeOnce sync.Once
firstError error
perf PerfCount
schemaID uint64
wg sync.WaitGroup
conn net.Conn
reader *bufio.Reader
writer *bufio.Writer
uuid string
salt []byte // base64-encoded salt
ctx context.Context
cancel context.CancelFunc
handler QueryHandler
onShutdown OnShutdownCallback
output chan *BinaryPacket
closeOnce sync.Once
firstError error
perf PerfCount
schemaID uint64
wg sync.WaitGroup
getPingStatus func(*IprotoServer) uint
}

type IprotoServerOptions struct {
Perf PerfCount
Perf PerfCount
GetPingStatus func(*IprotoServer) uint
}

func NewIprotoServer(uuid string, handler QueryHandler, onShutdown OnShutdownCallback) *IprotoServer {
Expand All @@ -56,6 +58,10 @@ func (s *IprotoServer) WithOptions(opts *IprotoServerOptions) *IprotoServer {
opts = &IprotoServerOptions{}
}
s.perf = opts.Perf
s.getPingStatus = opts.GetPingStatus
if s.getPingStatus == nil {
s.getPingStatus = func(*IprotoServer) uint { return 0 }
}
return s
}

Expand Down Expand Up @@ -223,6 +229,7 @@ READER_LOOP:
code := packet.Cmd
if code == PingCommand {
pr := packetPool.GetWithID(packet.requestID)
pr.packet.Cmd = s.getPingStatus(s)
pr.packet.SchemaID = packet.SchemaID

select {
Expand Down

0 comments on commit 091e42b

Please sign in to comment.