MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / runServer

Method runServer

pkg/wshutil/wshrpc.go:381–447  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

379}
380
381func (w *WshRpc) runServer() {
382 defer func() {
383 panichandler.PanicHandler("wshrpc.runServer", recover())
384 close(w.OutputCh)
385 w.setServerDone()
386 }()
387outer:
388 for {
389 var inputVal baseds.RpcInputChType
390 var inputChMore bool
391 var resIdTimeout string
392
393 select {
394 case inputVal, inputChMore = <-w.InputCh:
395 if !inputChMore {
396 break outer
397 }
398 if w.Debug {
399 log.Printf("[%s] received message: %s\n", w.DebugName, string(inputVal.MsgBytes))
400 }
401 case resIdTimeout = <-w.CtxDoneCh:
402 if w.Debug {
403 log.Printf("[%s] received request timeout: %s\n", w.DebugName, resIdTimeout)
404 }
405 w.unregisterRpc(resIdTimeout, fmt.Errorf("EC-TIME: timeout waiting for response"))
406 continue
407 }
408
409 var msg RpcMessage
410 err := json.Unmarshal(inputVal.MsgBytes, &msg)
411 if err != nil {
412 log.Printf("wshrpc received bad message: %v\n", err)
413 continue
414 }
415 if msg.Cancel {
416 if msg.ReqId != "" {
417 w.cancelRequest(msg.ReqId)
418 }
419 continue
420 }
421 if msg.IsRpcRequest() {
422 // Handle stream commands synchronously since the broker is designed to be non-blocking.
423 // RecvData/RecvAck just enqueue to work queues, so there's no risk of blocking the main loop.
424 if msg.Command == wshrpc.Command_StreamData {
425 w.handleStreamData(&msg)
426 continue
427 }
428 if msg.Command == wshrpc.Command_StreamDataAck {
429 w.handleStreamAck(&msg)
430 continue
431 }
432
433 ingressLinkId := inputVal.IngressLinkId
434 go func() {
435 defer func() {
436 panichandler.PanicHandler("handleRequest:goroutine", recover())
437 }()
438 w.handleRequest(&msg, ingressLinkId)

Callers 1

MakeWshRpcWithChannelsFunction · 0.95

Calls 9

setServerDoneMethod · 0.95
unregisterRpcMethod · 0.95
cancelRequestMethod · 0.95
IsRpcRequestMethod · 0.95
handleStreamDataMethod · 0.95
handleStreamAckMethod · 0.95
handleRequestMethod · 0.95
PanicHandlerFunction · 0.92

Tested by

no test coverage detected