diff --git a/internal/msgpackrouter/router.go b/internal/msgpackrouter/router.go index e570095..d788dfb 100644 --- a/internal/msgpackrouter/router.go +++ b/internal/msgpackrouter/router.go @@ -43,9 +43,13 @@ func New() *Router { } func (r *Router) Accept(conn io.ReadWriteCloser) <-chan struct{} { + return r.AcceptAndSendNotification(conn, false) +} + +func (r *Router) AcceptAndSendNotification(conn io.ReadWriteCloser, sendStartNotification bool) <-chan struct{} { res := make(chan struct{}) go func() { - r.connectionLoop(conn) + r.connectionLoop(conn, sendStartNotification) close(res) }() return res @@ -66,7 +70,7 @@ func (r *Router) RegisterMethod(method string, handler RouterRequestHandler) err return nil } -func (r *Router) connectionLoop(conn io.ReadWriteCloser) { +func (r *Router) connectionLoop(conn io.ReadWriteCloser, sendStartNotification bool) { defer conn.Close() var msgpackconn *msgpackrpc.Connection @@ -158,6 +162,14 @@ func (r *Router) connectionLoop(conn io.ReadWriteCloser) { }, ) + if sendStartNotification { + // Send the start notification to the client + if err := msgpackconn.SendNotification("$/start", nil); err != nil { + slog.Error("Failed to send $/start notification", "err", err) + return + } + } + msgpackconn.Run() // Unregister the methods when the connection is terminated diff --git a/main.go b/main.go index afdbea4..d1da2f9 100644 --- a/main.go +++ b/main.go @@ -250,7 +250,7 @@ func startRouter(cfg Config) error { wr := &MsgpackDebugStream{Name: cfg.SerialPortAddr, Upstream: serialPort} // wait for the close command from RPC or for a failure of the serial port (routerExit) - routerExit := router.Accept(wr) + routerExit := router.AcceptAndSendNotification(wr, true) select { case <-routerExit: slog.Info("Serial port failed connection")