MCPcopy Create free account
hub / github.com/cloudwego/netpoll / waitReadWithTimeout

Method waitReadWithTimeout

connection_impl.go:484–523  ·  view source on GitHub ↗

waitReadWithTimeout will wait full n bytes or until timeout.

(n int, timeout time.Duration)

Source from the content-addressed store, hash-verified

482
483// waitReadWithTimeout will wait full n bytes or until timeout.
484func (c *connection) waitReadWithTimeout(n int, timeout time.Duration) (err error) {
485 if c.readTimer == nil {
486 c.readTimer = time.NewTimer(timeout)
487 } else {
488 c.readTimer.Reset(timeout)
489 }
490
491 for c.inputBuffer.Len() < n {
492 switch c.status(closing) {
493 case poller:
494 // cannot return directly, stop timer first!
495 err = Exception(ErrEOF, "wait read")
496 goto RET
497 case user:
498 // cannot return directly, stop timer first!
499 err = Exception(ErrConnClosed, "wait read")
500 goto RET
501 default:
502 select {
503 case <-c.readTimer.C:
504 // double check if there is enough data to be read
505 if c.inputBuffer.Len() >= n {
506 return nil
507 }
508 return Exception(ErrReadTimeout, c.remoteAddr.String())
509 case err = <-c.readTrigger:
510 if err != nil {
511 goto RET
512 }
513 continue
514 }
515 }
516 }
517RET:
518 // clean timer.C
519 if !c.readTimer.Stop() {
520 <-c.readTimer.C
521 }
522 return err
523}
524
525// flush writes data directly.
526func (c *connection) flush() error {

Callers 1

waitReadMethod · 0.95

Calls 4

ExceptionFunction · 0.85
statusMethod · 0.80
LenMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected