MCPcopy
hub / github.com/nirui/sshwifty / Handle

Method Handle

application/command/handler.go:280–333  ·  view source on GitHub ↗

Handle starts handling

()

Source from the content-addressed store, hash-verified

278
279// Handle starts handling
280func (e *Handler) Handle() error {
281 defer func() {
282 if e.senderPaused {
283 e.sender.lock.Unlock()
284 e.senderPaused = false
285 }
286
287 e.streams.shutdown()
288 }()
289
290 requests := 0
291
292 for {
293 time.Sleep(e.receiveDelay)
294
295 requests++
296
297 d, dErr := rw.FetchOneByte(e.receiver.Fetch)
298
299 if dErr != nil {
300 return dErr
301 }
302
303 h := Header(d[0])
304 l := e.log.Context("Request (%d)", requests).Context(h.String())
305
306 l.Debug("Received")
307
308 switch h.Type() {
309 case HeaderControl:
310 dErr = e.handleControl(h.Data(), l)
311
312 case HeaderStream:
313 dErr = e.handleStream(h, h.Data(), l)
314
315 case HeaderClose:
316 dErr = e.handleClose(h, h.Data(), l)
317
318 case HeaderCompleted:
319 dErr = e.handleCompleted(h.Data(), l)
320
321 default:
322 return ErrHandlerUnknownHeaderType
323 }
324
325 if dErr != nil {
326 l.Debug("Request failed: %s", dErr)
327
328 return dErr
329 }
330
331 l.Debug("Request successful")
332 }
333}

Callers 3

GetMethod · 0.80
TestHandlerHandleStreamFunction · 0.80
TestHandlerHandleEchoFunction · 0.80

Calls 12

handleControlMethod · 0.95
handleStreamMethod · 0.95
handleCloseMethod · 0.95
handleCompletedMethod · 0.95
FetchOneByteFunction · 0.92
shutdownMethod · 0.80
HeaderTypeAlias · 0.70
ContextMethod · 0.65
DebugMethod · 0.65
StringMethod · 0.45
TypeMethod · 0.45
DataMethod · 0.45

Tested by 2

TestHandlerHandleStreamFunction · 0.64
TestHandlerHandleEchoFunction · 0.64