()
| 379 | } |
| 380 | |
| 381 | func (w *WshRpc) runServer() { |
| 382 | defer func() { |
| 383 | panichandler.PanicHandler("wshrpc.runServer", recover()) |
| 384 | close(w.OutputCh) |
| 385 | w.setServerDone() |
| 386 | }() |
| 387 | outer: |
| 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) |
no test coverage detected