Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions internal/msgpackrouter/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down