| 846 | } |
| 847 | |
| 848 | Status DebugGrpcIO::GetOrCreateDebugGrpcChannel( |
| 849 | const string& grpc_stream_url, DebugGrpcChannel** debug_grpc_channel) { |
| 850 | const string addr_with_path = |
| 851 | absl::StartsWith(grpc_stream_url, DebugIO::kGrpcURLScheme) |
| 852 | ? grpc_stream_url.substr(strlen(DebugIO::kGrpcURLScheme)) |
| 853 | : grpc_stream_url; |
| 854 | const string server_stream_addr = |
| 855 | addr_with_path.substr(0, addr_with_path.find('/')); |
| 856 | { |
| 857 | mutex_lock l(streams_mu_); |
| 858 | std::unordered_map<string, std::unique_ptr<DebugGrpcChannel>>* |
| 859 | stream_channels = GetStreamChannels(); |
| 860 | if (stream_channels->find(grpc_stream_url) == stream_channels->end()) { |
| 861 | std::unique_ptr<DebugGrpcChannel> channel( |
| 862 | new DebugGrpcChannel(server_stream_addr)); |
| 863 | TF_RETURN_IF_ERROR(channel->Connect(channel_connection_timeout_micros_)); |
| 864 | stream_channels->insert( |
| 865 | std::make_pair(grpc_stream_url, std::move(channel))); |
| 866 | } |
| 867 | *debug_grpc_channel = (*stream_channels)[grpc_stream_url].get(); |
| 868 | } |
| 869 | return Status::OK(); |
| 870 | } |
| 871 | |
| 872 | Status DebugGrpcIO::SendEventProtoThroughGrpcStream( |
| 873 | const Event& event_proto, const string& grpc_stream_url, |