Skip to content

Commit db9c98c

Browse files
committed
Send $/start notification to the serial client upon startup.
1 parent 8cffcb8 commit db9c98c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

internal/msgpackrouter/router.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,17 @@ func (r *Router) SetSendMaxWorkers(size int) {
5656
}
5757

5858
func (r *Router) Accept(conn io.ReadWriteCloser) <-chan struct{} {
59+
return r.accept(conn, false)
60+
}
61+
62+
func (r *Router) AcceptAndSendNotification(conn io.ReadWriteCloser) <-chan struct{} {
63+
return r.accept(conn, true)
64+
}
65+
66+
func (r *Router) accept(conn io.ReadWriteCloser, sendStartNotification bool) <-chan struct{} {
5967
res := make(chan struct{})
6068
go func() {
61-
r.connectionLoop(conn)
69+
r.connectionLoop(conn, sendStartNotification)
6270
close(res)
6371
}()
6472
return res
@@ -79,7 +87,7 @@ func (r *Router) RegisterMethod(method string, handler RouterRequestHandler) err
7987
return nil
8088
}
8189

82-
func (r *Router) connectionLoop(conn io.ReadWriteCloser) {
90+
func (r *Router) connectionLoop(conn io.ReadWriteCloser, sendStartNotification bool) {
8391
defer conn.Close()
8492

8593
var msgpackconn *msgpackrpc.Connection
@@ -172,6 +180,14 @@ func (r *Router) connectionLoop(conn io.ReadWriteCloser) {
172180
r.sendMaxWorkers,
173181
)
174182

183+
if sendStartNotification {
184+
// Send the start notification to the client
185+
if err := msgpackconn.SendNotification("$/start"); err != nil {
186+
slog.Error("Failed to send $/start notification", "err", err)
187+
return
188+
}
189+
}
190+
175191
msgpackconn.Run()
176192

177193
// Unregister the methods when the connection is terminated

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func startRouter(cfg Config) error {
251251
wr := &MsgpackDebugStream{Name: cfg.SerialPortAddr, Upstream: serialPort}
252252

253253
// wait for the close command from RPC or for a failure of the serial port (routerExit)
254-
routerExit := router.Accept(wr)
254+
routerExit := router.AcceptAndSendNotification(wr)
255255
select {
256256
case <-routerExit:
257257
slog.Info("Serial port failed connection")

0 commit comments

Comments
 (0)