| 52 | } |
| 53 | |
| 54 | func HandleNylonIPC(n *Nylon, rw *bufio.ReadWriter) error { |
| 55 | req, err := readRequest(rw) |
| 56 | if err != nil { |
| 57 | if err := writeResponse(rw, errResponse(err.Error())); err != nil { |
| 58 | return err |
| 59 | } |
| 60 | return device.ErrIPCStatusHandled |
| 61 | } |
| 62 | |
| 63 | // trace is blocking, so we dont dispatch |
| 64 | if _, ok := req.Request.(*protocol.IpcRequest_Trace); ok { |
| 65 | return handleTrace(n, rw) |
| 66 | } |
| 67 | |
| 68 | done := make(chan *protocol.IpcResponse, 1) |
| 69 | n.Dispatch(func() error { |
| 70 | var resp *protocol.IpcResponse |
| 71 | switch req.Request.(type) { |
| 72 | case *protocol.IpcRequest_Status: |
| 73 | resp = handleStatus(n, req.GetStatus()) |
| 74 | case *protocol.IpcRequest_Probe: |
| 75 | resp = handleIPCProbe(n, req.GetProbe()) |
| 76 | case *protocol.IpcRequest_Reload: |
| 77 | resp = handleIPCReload(n, req.GetReload()) |
| 78 | default: |
| 79 | resp = errResponse("unknown method") |
| 80 | } |
| 81 | done <- resp |
| 82 | return nil |
| 83 | }) |
| 84 | |
| 85 | var resp *protocol.IpcResponse |
| 86 | select { |
| 87 | case resp = <-done: |
| 88 | case <-n.Context.Done(): |
| 89 | resp = errResponse("nylon shutting down") |
| 90 | case <-time.After(1 * time.Second): |
| 91 | // nylon is too busy to handle IPC requests |
| 92 | resp = errResponse("timed out waiting for dispatch") |
| 93 | } |
| 94 | if err := writeResponse(rw, resp); err != nil { |
| 95 | return err |
| 96 | } |
| 97 | return device.ErrIPCStatusHandled |
| 98 | } |
| 99 | |
| 100 | func handleStatus(n *Nylon, req *protocol.StatusRequest) *protocol.IpcResponse { |
| 101 | activeEps := 0 |