flush writes data directly.
()
| 524 | |
| 525 | // flush writes data directly. |
| 526 | func (c *connection) flush() error { |
| 527 | if c.outputBuffer.IsEmpty() { |
| 528 | return nil |
| 529 | } |
| 530 | bs := c.outputBuffer.GetBytes(c.outputBarrier.bs) |
| 531 | n, err := sendmsg(c.fd, bs, c.outputBarrier.ivs, false) |
| 532 | if err != nil && err != syscall.EAGAIN { |
| 533 | return Exception(err, "when flush") |
| 534 | } |
| 535 | if n > 0 { |
| 536 | err = c.outputBuffer.Skip(n) |
| 537 | c.outputBuffer.Release() |
| 538 | if err != nil { |
| 539 | return Exception(err, "when flush") |
| 540 | } |
| 541 | } |
| 542 | // return if write all buffer. |
| 543 | if c.outputBuffer.IsEmpty() { |
| 544 | return nil |
| 545 | } |
| 546 | err = c.operator.Control(PollR2RW) |
| 547 | if err != nil { |
| 548 | return Exception(err, "when flush") |
| 549 | } |
| 550 | |
| 551 | return c.waitFlush() |
| 552 | } |
| 553 | |
| 554 | func (c *connection) waitFlush() (err error) { |
| 555 | timeout := c.writeTimeout |