| 5818 | } |
| 5819 | |
| 5820 | void StreamingListener::SocketWriter::MakeConnection() { |
| 5821 | GTEST_CHECK_(sockfd_ == -1) |
| 5822 | << "MakeConnection() can't be called when there is already a connection."; |
| 5823 | |
| 5824 | addrinfo hints; |
| 5825 | memset(&hints, 0, sizeof(hints)); |
| 5826 | hints.ai_family = AF_UNSPEC; // To allow both IPv4 and IPv6 addresses. |
| 5827 | hints.ai_socktype = SOCK_STREAM; |
| 5828 | addrinfo* servinfo = nullptr; |
| 5829 | |
| 5830 | // Use the getaddrinfo() to get a linked list of IP addresses for |
| 5831 | // the given host name. |
| 5832 | const int error_num = getaddrinfo( |
| 5833 | host_name_.c_str(), port_num_.c_str(), &hints, &servinfo); |
| 5834 | if (error_num != 0) { |
| 5835 | GTEST_LOG_(WARNING) << "stream_result_to: getaddrinfo() failed: " |
| 5836 | << gai_strerror(error_num); |
| 5837 | } |
| 5838 | |
| 5839 | // Loop through all the results and connect to the first we can. |
| 5840 | for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != nullptr; |
| 5841 | cur_addr = cur_addr->ai_next) { |
| 5842 | sockfd_ = socket( |
| 5843 | cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol); |
| 5844 | if (sockfd_ != -1) { |
| 5845 | // Connect the client socket to the server socket. |
| 5846 | if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) { |
| 5847 | close(sockfd_); |
| 5848 | sockfd_ = -1; |
| 5849 | } |
| 5850 | } |
| 5851 | } |
| 5852 | |
| 5853 | freeaddrinfo(servinfo); // all done with this structure |
| 5854 | |
| 5855 | if (sockfd_ == -1) { |
| 5856 | GTEST_LOG_(WARNING) << "stream_result_to: failed to connect to " |
| 5857 | << host_name_ << ":" << port_num_; |
| 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | // End of class Streaming Listener |
| 5862 | #endif // GTEST_CAN_STREAM_RESULTS__ |
nothing calls this directly
no outgoing calls
no test coverage detected