MCPcopy Create free account
hub / github.com/apple/foundationdb / write

Method write

flow/Net2.actor.cpp:482–512  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

SendBufferIteratorClass · 0.85
onWriteErrorFunction · 0.85

Tested by

no test coverage detected