MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / recvLoop

Method recvLoop

internal/nodehub/hub_test.go:127–163  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

125}
126
127func (m *nodeMock) recvLoop() {
128 defer close(m.done)
129 for {
130 msg, err := m.stream.Recv()
131 if err != nil {
132 return
133 }
134 if msg.GetCancelId() != "" {
135 select {
136 case m.cancelIDs <- msg.GetCancelId():
137 default:
138 }
139 continue
140 }
141 if msg.GetMethod() == "ack" {
142 select {
143 case m.acks <- msg.GetBody():
144 default:
145 }
146 continue
147 }
148 // 普通请求
149 m.mu.Lock()
150 fn, ok := m.handlers[msg.GetMethod()]
151 m.mu.Unlock()
152 if m.silent.Load() {
153 continue
154 }
155 if !ok {
156 // 默认回 ok=true, body=null
157 m.sendNode(&nodev1.NodeMessage{Id: msg.GetId(), Ok: true})
158 continue
159 }
160 ok2, body, errStr := fn(msg.GetId(), msg.GetBody())
161 m.sendNode(&nodev1.NodeMessage{Id: msg.GetId(), Ok: ok2, Body: body, Error: errStr})
162 }
163}
164
165func (m *nodeMock) sendNode(msg *nodev1.NodeMessage) {
166 m.sendMu.Lock()

Callers 1

startNodeMockFunction · 0.95

Calls 5

sendNodeMethod · 0.95
GetCancelIdMethod · 0.80
GetMethodMethod · 0.80
GetBodyMethod · 0.45
GetIdMethod · 0.45

Tested by

no test coverage detected