Skip to content

Commit 091e42b

Browse files
committed
Add an option which should enable setting a custom server ping status
1 parent d82b4c9 commit 091e42b

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

server.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,27 @@ type OnShutdownCallback func(err error)
1818

1919
type IprotoServer struct {
2020
sync.Mutex
21-
conn net.Conn
22-
reader *bufio.Reader
23-
writer *bufio.Writer
24-
uuid string
25-
salt []byte // base64-encoded salt
26-
ctx context.Context
27-
cancel context.CancelFunc
28-
handler QueryHandler
29-
onShutdown OnShutdownCallback
30-
output chan *BinaryPacket
31-
closeOnce sync.Once
32-
firstError error
33-
perf PerfCount
34-
schemaID uint64
35-
wg sync.WaitGroup
21+
conn net.Conn
22+
reader *bufio.Reader
23+
writer *bufio.Writer
24+
uuid string
25+
salt []byte // base64-encoded salt
26+
ctx context.Context
27+
cancel context.CancelFunc
28+
handler QueryHandler
29+
onShutdown OnShutdownCallback
30+
output chan *BinaryPacket
31+
closeOnce sync.Once
32+
firstError error
33+
perf PerfCount
34+
schemaID uint64
35+
wg sync.WaitGroup
36+
getPingStatus func(*IprotoServer) uint
3637
}
3738

3839
type IprotoServerOptions struct {
39-
Perf PerfCount
40+
Perf PerfCount
41+
GetPingStatus func(*IprotoServer) uint
4042
}
4143

4244
func NewIprotoServer(uuid string, handler QueryHandler, onShutdown OnShutdownCallback) *IprotoServer {
@@ -56,6 +58,10 @@ func (s *IprotoServer) WithOptions(opts *IprotoServerOptions) *IprotoServer {
5658
opts = &IprotoServerOptions{}
5759
}
5860
s.perf = opts.Perf
61+
s.getPingStatus = opts.GetPingStatus
62+
if s.getPingStatus == nil {
63+
s.getPingStatus = func(*IprotoServer) uint { return 0 }
64+
}
5965
return s
6066
}
6167

@@ -223,6 +229,7 @@ READER_LOOP:
223229
code := packet.Cmd
224230
if code == PingCommand {
225231
pr := packetPool.GetWithID(packet.requestID)
232+
pr.packet.Cmd = s.getPingStatus(s)
226233
pr.packet.SchemaID = packet.SchemaID
227234

228235
select {

0 commit comments

Comments
 (0)