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

Method write

fdbrpc/sim2.actor.cpp:288–323  ·  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) (or may throw an error if the connection dies)

Source from the content-addressed store, hash-verified

286 // Writes as many bytes as possible from the given SendBuffer chain into the write buffer and returns the number of
287 // bytes written (might be 0) (or may throw an error if the connection dies)
288 int write(SendBuffer const* buffer, int limit) override {
289 rollRandomClose();
290 ASSERT(limit > 0);
291
292 int toSend = 0;
293 if (BUGGIFY && !stableConnection) {
294 toSend = std::min(limit, buffer->bytes_written - buffer->bytes_sent);
295 } else {
296 for (auto p = buffer; p; p = p->next) {
297 toSend += p->bytes_written - p->bytes_sent;
298 if (toSend >= limit) {
299 if (toSend > limit)
300 toSend = limit;
301 break;
302 }
303 }
304 }
305 ASSERT(toSend);
306 if (BUGGIFY && !stableConnection)
307 toSend = std::min(toSend, deterministicRandom()->randomInt(0, 1000));
308
309 if (!peer)
310 return toSend;
311 toSend = std::min(toSend, peer->availableSendBufferForPeer());
312 ASSERT(toSend >= 0);
313
314 int leftToSend = toSend;
315 for (auto p = buffer; p && leftToSend > 0; p = p->next) {
316 int ts = std::min(leftToSend, p->bytes_written - p->bytes_sent);
317 peer->recvBuf.insert(peer->recvBuf.end(), p->data() + p->bytes_sent, p->data() + p->bytes_sent + ts);
318 leftToSend -= ts;
319 }
320 ASSERT(leftToSend == 0);
321 peer->writtenBytes.set(peer->writtenBytes.get() + toSend);
322 return toSend;
323 }
324
325 // Returns the network address and port of the other end of the connection. In the case of an incoming connection,
326 // this may not be an address we can connect to!

Callers 4

read_write_implMethod · 0.45
sendPacketFunction · 0.45
Response>> doRequestMethod · 0.45

Calls 9

rollRandomCloseFunction · 0.85
deterministicRandomFunction · 0.85
setMethod · 0.65
getMethod · 0.65
randomIntMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected