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

Method waitRead

connection_impl.go:451–481  ·  view source on GitHub ↗

waitRead will wait full n bytes.

(n int)

Source from the content-addressed store, hash-verified

449
450// waitRead will wait full n bytes.
451func (c *connection) waitRead(n int) (err error) {
452 if n <= c.inputBuffer.Len() {
453 return nil
454 }
455 atomic.StoreInt64(&c.waitReadSize, int64(n))
456 defer atomic.StoreInt64(&c.waitReadSize, 0)
457 if dl := c.readDeadline; dl > 0 {
458 timeout := time.Duration(dl - time.Now().UnixNano())
459 if timeout <= 0 {
460 return Exception(ErrReadTimeout, c.remoteAddr.String())
461 }
462 return c.waitReadWithTimeout(n, timeout)
463 } else if c.readTimeout > 0 {
464 return c.waitReadWithTimeout(n, c.readTimeout)
465 }
466 // wait full n
467 for c.inputBuffer.Len() < n {
468 switch c.status(closing) {
469 case poller:
470 return Exception(ErrEOF, "wait read")
471 case user:
472 return Exception(ErrConnClosed, "wait read")
473 default:
474 err = <-c.readTrigger
475 if err != nil {
476 return err
477 }
478 }
479 }
480 return nil
481}
482
483// waitReadWithTimeout will wait full n bytes or until timeout.
484func (c *connection) waitReadWithTimeout(n int, timeout time.Duration) (err error) {

Callers 9

NextMethod · 0.95
PeekMethod · 0.95
SkipMethod · 0.95
SliceMethod · 0.95
UntilMethod · 0.95
ReadStringMethod · 0.95
ReadBinaryMethod · 0.95
ReadByteMethod · 0.95
ReadMethod · 0.95

Calls 4

waitReadWithTimeoutMethod · 0.95
ExceptionFunction · 0.85
statusMethod · 0.80
LenMethod · 0.65

Tested by

no test coverage detected