MCPcopy Create free account
hub / github.com/apache/brpc / WriteAll

Function WriteAll

src/brpc/policy/rtmp_protocol.cpp:603–624  ·  view source on GitHub ↗

Write all data in *buf into fd. Returns 0 on success, -1 otherwise. Writing *all* is possible because we only call this fn during handshaking and connecting, the data in total is generally less than socket buffer.

Source from the content-addressed store, hash-verified

601// Writing *all* is possible because we only call this fn during handshaking
602// and connecting, the data in total is generally less than socket buffer.
603static int WriteAll(int fd, butil::IOBuf* buf) {
604 while (!buf->empty()) {
605 ssize_t nw = buf->cut_into_file_descriptor(fd);
606 if (nw < 0) {
607 if (errno == EINTR) {
608 continue;
609 }
610 if (errno == EAGAIN) {
611 // Almost impossible because we only call this fn during
612 // RTMP handshaking/connecting, the total size that we may
613 // write is less than buffer size of the fd. If the
614 // impossible really happens, just spin until the fd becomes
615 // writable.
616 LOG_EVERY_SECOND(ERROR) << "Impossible: meet EAGAIN!";
617 bthread_usleep(1000);
618 continue;
619 }
620 return -1;
621 }
622 }
623 return 0;
624}
625
626// Send C0 C1 to the socket.
627// Used in rtmp.cpp

Callers 4

SendC0C1Function · 0.85
SendConnectRequestMethod · 0.85
WaitForS0S1Method · 0.85

Calls 3

bthread_usleepFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected