waitRead will wait full n bytes.
(n int)
| 449 | |
| 450 | // waitRead will wait full n bytes. |
| 451 | func (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. |
| 484 | func (c *connection) waitReadWithTimeout(n int, timeout time.Duration) (err error) { |
no test coverage detected