Writes as many bytes as possible from the given SendBuffer chain into the write buffer and returns the number of bytes written (might be 0)
| 480 | // Writes as many bytes as possible from the given SendBuffer chain into the write buffer and returns the number of |
| 481 | // bytes written (might be 0) |
| 482 | int write(SendBuffer const* data, int limit) override { |
| 483 | boost::system::error_code err; |
| 484 | ++g_net2->countWrites; |
| 485 | |
| 486 | size_t sent = socket.write_some( |
| 487 | boost::iterator_range<SendBufferIterator>(SendBufferIterator(data, limit), SendBufferIterator()), err); |
| 488 | |
| 489 | if (err) { |
| 490 | // Since there was an error, sent's value can't be used to infer that the buffer has data and the limit is |
| 491 | // positive so check explicitly. |
| 492 | ASSERT(limit > 0); |
| 493 | bool notEmpty = false; |
| 494 | for (auto p = data; p; p = p->next) |
| 495 | if (p->bytes_written - p->bytes_sent > 0) { |
| 496 | notEmpty = true; |
| 497 | break; |
| 498 | } |
| 499 | ASSERT(notEmpty); |
| 500 | |
| 501 | if (err == boost::asio::error::would_block) { |
| 502 | ++g_net2->countWouldBlock; |
| 503 | return 0; |
| 504 | } |
| 505 | onWriteError(err); |
| 506 | throw connection_failed(); |
| 507 | } |
| 508 | |
| 509 | ASSERT(sent); // Make sure data was sent, and also this check will fail if the buffer chain was empty or the |
| 510 | // limit was not > 0. |
| 511 | return sent; |
| 512 | } |
| 513 | |
| 514 | NetworkAddress getPeerAddress() const override { return peer_address; } |
| 515 |
nothing calls this directly
no test coverage detected