| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/cast_channel/cast_transport.h" | 5 #include "components/cast_channel/cast_transport.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/numerics/safe_conversions.h" | 16 #include "base/numerics/safe_conversions.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "components/cast_channel/cast_framer.h" | 20 #include "components/cast_channel/cast_framer.h" |
| 21 #include "components/cast_channel/cast_message_util.h" | 21 #include "components/cast_channel/cast_message_util.h" |
| 22 #include "components/cast_channel/logger.h" | 22 #include "components/cast_channel/logger.h" |
| 23 #include "components/cast_channel/proto/cast_channel.pb.h" | 23 #include "components/cast_channel/proto/cast_channel.pb.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/socket/socket.h" | 25 #include "net/socket/socket.h" |
| 26 | 26 |
| 27 #define VLOG_WITH_CONNECTION(level) \ | 27 #define VLOG_WITH_CONNECTION(level) \ |
| 28 VLOG(level) << "[" << ip_endpoint_.ToString() << ", auth=" \ | 28 VLOG(level) << "[" << ip_endpoint_.ToString() << ", auth=SSL_VERIFIED] " |
| 29 << ::cast_channel::ChannelAuthTypeToString(channel_auth_) \ | |
| 30 << "] " | |
| 31 | 29 |
| 32 namespace cast_channel { | 30 namespace cast_channel { |
| 33 | 31 |
| 34 CastTransportImpl::CastTransportImpl(net::Socket* socket, | 32 CastTransportImpl::CastTransportImpl(net::Socket* socket, |
| 35 int channel_id, | 33 int channel_id, |
| 36 const net::IPEndPoint& ip_endpoint, | 34 const net::IPEndPoint& ip_endpoint, |
| 37 ChannelAuthType channel_auth, | |
| 38 scoped_refptr<Logger> logger) | 35 scoped_refptr<Logger> logger) |
| 39 : started_(false), | 36 : started_(false), |
| 40 socket_(socket), | 37 socket_(socket), |
| 41 write_state_(WriteState::IDLE), | 38 write_state_(WriteState::IDLE), |
| 42 read_state_(ReadState::READ), | 39 read_state_(ReadState::READ), |
| 43 error_state_(ChannelError::NONE), | 40 error_state_(ChannelError::NONE), |
| 44 channel_id_(channel_id), | 41 channel_id_(channel_id), |
| 45 ip_endpoint_(ip_endpoint), | 42 ip_endpoint_(ip_endpoint), |
| 46 channel_auth_(channel_auth), | |
| 47 logger_(logger) { | 43 logger_(logger) { |
| 48 DCHECK(socket); | 44 DCHECK(socket); |
| 49 | 45 |
| 50 // Buffer is reused across messages to minimize unnecessary buffer | 46 // Buffer is reused across messages to minimize unnecessary buffer |
| 51 // [re]allocations. | 47 // [re]allocations. |
| 52 read_buffer_ = new net::GrowableIOBuffer(); | 48 read_buffer_ = new net::GrowableIOBuffer(); |
| 53 read_buffer_->SetCapacity(MessageFramer::MessageHeader::max_message_size()); | 49 read_buffer_->SetCapacity(MessageFramer::MessageHeader::max_message_size()); |
| 54 framer_.reset(new MessageFramer(read_buffer_)); | 50 framer_.reset(new MessageFramer(read_buffer_)); |
| 55 } | 51 } |
| 56 | 52 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 367 |
| 372 int CastTransportImpl::DoReadHandleError(int result) { | 368 int CastTransportImpl::DoReadHandleError(int result) { |
| 373 VLOG_WITH_CONNECTION(2) << "DoReadHandleError"; | 369 VLOG_WITH_CONNECTION(2) << "DoReadHandleError"; |
| 374 DCHECK_NE(ChannelError::NONE, error_state_); | 370 DCHECK_NE(ChannelError::NONE, error_state_); |
| 375 DCHECK_LE(result, 0); | 371 DCHECK_LE(result, 0); |
| 376 SetReadState(ReadState::READ_ERROR); | 372 SetReadState(ReadState::READ_ERROR); |
| 377 return net::ERR_FAILED; | 373 return net::ERR_FAILED; |
| 378 } | 374 } |
| 379 | 375 |
| 380 } // namespace cast_channel | 376 } // namespace cast_channel |
| OLD | NEW |