| 4920 | } |
| 4921 | |
| 4922 | void StreamingListener::SocketWriter::MakeConnection() { |
| 4923 | GTEST_CHECK_(sockfd_ == -1) |
| 4924 | << "MakeConnection() can't be called when there is already a connection."; |
| 4925 | |
| 4926 | addrinfo hints; |
| 4927 | memset(&hints, 0, sizeof(hints)); |
| 4928 | hints.ai_family = AF_UNSPEC; // To allow both IPv4 and IPv6 addresses. |
| 4929 | hints.ai_socktype = SOCK_STREAM; |
| 4930 | addrinfo* servinfo = NULL; |
| 4931 | |
| 4932 | // Use the getaddrinfo() to get a linked list of IP addresses for |
| 4933 | // the given host name. |
| 4934 | const int error_num = getaddrinfo( |
| 4935 | host_name_.c_str(), port_num_.c_str(), &hints, &servinfo); |
| 4936 | if (error_num != 0) { |
| 4937 | GTEST_LOG_(WARNING) << "stream_result_to: getaddrinfo() failed: " |
| 4938 | << gai_strerror(error_num); |
| 4939 | } |
| 4940 | |
| 4941 | // Loop through all the results and connect to the first we can. |
| 4942 | for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != NULL; |
| 4943 | cur_addr = cur_addr->ai_next) { |
| 4944 | sockfd_ = socket( |
| 4945 | cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol); |
| 4946 | if (sockfd_ != -1) { |
| 4947 | // Connect the client socket to the server socket. |
| 4948 | if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) { |
| 4949 | close(sockfd_); |
| 4950 | sockfd_ = -1; |
| 4951 | } |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | freeaddrinfo(servinfo); // all done with this structure |
| 4956 | |
| 4957 | if (sockfd_ == -1) { |
| 4958 | GTEST_LOG_(WARNING) << "stream_result_to: failed to connect to " |
| 4959 | << host_name_ << ":" << port_num_; |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | // End of class Streaming Listener |
| 4964 | #endif // GTEST_CAN_STREAM_RESULTS__ |
nothing calls this directly
no outgoing calls
no test coverage detected