Skip to content

Commit de76b1a

Browse files
committed
Send $/start notification to the serial client upon startup.
1 parent 74fcdf0 commit de76b1a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

internal/msgpackrouter/router.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ func New() *Router {
4343
}
4444

4545
func (r *Router) Accept(conn io.ReadWriteCloser) <-chan struct{} {
46+
return r.AcceptAndSendNotification(conn, false)
47+
}
48+
49+
func (r *Router) AcceptAndSendNotification(conn io.ReadWriteCloser, sendStartNotification bool) <-chan struct{} {
4650
res := make(chan struct{})
4751
go func() {
48-
r.connectionLoop(conn)
52+
r.connectionLoop(conn, sendStartNotification)
4953
close(res)
5054
}()
5155
return res
@@ -66,7 +70,7 @@ func (r *Router) RegisterMethod(method string, handler RouterRequestHandler) err
6670
return nil
6771
}
6872

69-
func (r *Router) connectionLoop(conn io.ReadWriteCloser) {
73+
func (r *Router) connectionLoop(conn io.ReadWriteCloser, sendStartNotification bool) {
7074
defer conn.Close()
7175

7276
var msgpackconn *msgpackrpc.Connection
@@ -158,6 +162,14 @@ func (r *Router) connectionLoop(conn io.ReadWriteCloser) {
158162
},
159163
)
160164

165+
if sendStartNotification {
166+
// Send the start notification to the client
167+
if err := msgpackconn.SendNotification("$/start", nil); err != nil {
168+
slog.Error("Failed to send $/start notification", "err", err)
169+
return
170+
}
171+
}
172+
161173
msgpackconn.Run()
162174

163175
// Unregister the methods when the connection is terminated

main.go

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

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

0 commit comments

Comments
 (0)