| 658 | } |
| 659 | |
| 660 | uint32_t TSocket::write_partial(const uint8_t* buf, uint32_t len) { |
| 661 | if (socket_ == THRIFT_INVALID_SOCKET) { |
| 662 | throw TTransportException(TTransportException::NOT_OPEN, "Called write on non-open socket"); |
| 663 | } |
| 664 | |
| 665 | uint32_t sent = 0; |
| 666 | |
| 667 | int flags = 0; |
| 668 | #ifdef MSG_NOSIGNAL |
| 669 | // Note the use of MSG_NOSIGNAL to suppress SIGPIPE errors, instead we |
| 670 | // check for the THRIFT_EPIPE return condition and close the socket in that case |
| 671 | flags |= MSG_NOSIGNAL; |
| 672 | #endif // ifdef MSG_NOSIGNAL |
| 673 | |
| 674 | int b = static_cast<int>(send(socket_, const_cast_sockopt(buf + sent), len - sent, flags)); |
| 675 | |
| 676 | if (b < 0) { |
| 677 | if (THRIFT_GET_SOCKET_ERROR == THRIFT_EWOULDBLOCK || THRIFT_GET_SOCKET_ERROR == THRIFT_EAGAIN) { |
| 678 | return 0; |
| 679 | } |
| 680 | // Fail on a send error |
| 681 | int errno_copy = THRIFT_GET_SOCKET_ERROR; |
| 682 | TOutput::instance().perror("TSocket::write_partial() send() " + getSocketInfo(), errno_copy); |
| 683 | |
| 684 | if (errno_copy == THRIFT_EPIPE || errno_copy == THRIFT_ECONNRESET |
| 685 | || errno_copy == THRIFT_ENOTCONN) { |
| 686 | throw TTransportException(TTransportException::NOT_OPEN, "write() send()", errno_copy); |
| 687 | } |
| 688 | |
| 689 | throw TTransportException(TTransportException::UNKNOWN, "write() send()", errno_copy); |
| 690 | } |
| 691 | |
| 692 | // Fail on blocked send |
| 693 | if (b == 0) { |
| 694 | throw TTransportException(TTransportException::NOT_OPEN, "Socket send returned 0."); |
| 695 | } |
| 696 | return b; |
| 697 | } |
| 698 | |
| 699 | std::string TSocket::getHost() const { |
| 700 | return host_; |
no test coverage detected