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.
| 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. |
| 603 | static 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 |
no test coverage detected