OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/quic/p2p/quic_p2p_session.h" | 5 #include "net/quic/p2p/quic_p2p_session.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/quic/p2p/quic_p2p_crypto_stream.h" | 10 #include "net/quic/p2p/quic_p2p_crypto_stream.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 QuicP2PStream* stream = new QuicP2PStream(GetNextStreamId(), this); | 60 QuicP2PStream* stream = new QuicP2PStream(GetNextStreamId(), this); |
61 if (stream) { | 61 if (stream) { |
62 ActivateStream(stream); | 62 ActivateStream(stream); |
63 } | 63 } |
64 return stream; | 64 return stream; |
65 } | 65 } |
66 | 66 |
67 void QuicP2PSession::OnConnectionClosed(QuicErrorCode error, bool from_peer) { | 67 void QuicP2PSession::OnConnectionClosed(QuicErrorCode error, bool from_peer) { |
68 QuicSession::OnConnectionClosed(error, from_peer); | 68 QuicSession::OnConnectionClosed(error, from_peer); |
69 | 69 |
| 70 socket_.reset(); |
| 71 |
70 if (delegate_) { | 72 if (delegate_) { |
71 Delegate* delegate = delegate_; | 73 Delegate* delegate = delegate_; |
72 delegate_ = nullptr; | 74 delegate_ = nullptr; |
73 delegate->OnConnectionClosed(error); | 75 delegate->OnConnectionClosed(error); |
74 } | 76 } |
75 } | 77 } |
76 | 78 |
77 void QuicP2PSession::DoReadLoop(int result) { | 79 void QuicP2PSession::DoReadLoop(int result) { |
78 while (error() == net::QUIC_NO_ERROR) { | 80 while (error() == net::QUIC_NO_ERROR) { |
79 switch (read_state_) { | 81 switch (read_state_) { |
(...skipping 11 matching lines...) Expand all Loading... |
91 | 93 |
92 if (result < 0) | 94 if (result < 0) |
93 break; | 95 break; |
94 } | 96 } |
95 } | 97 } |
96 | 98 |
97 int QuicP2PSession::DoRead() { | 99 int QuicP2PSession::DoRead() { |
98 DCHECK_EQ(read_state_, READ_STATE_DO_READ); | 100 DCHECK_EQ(read_state_, READ_STATE_DO_READ); |
99 read_state_ = READ_STATE_DO_READ_COMPLETE; | 101 read_state_ = READ_STATE_DO_READ_COMPLETE; |
100 | 102 |
| 103 if (!socket_) { |
| 104 return net::ERR_SOCKET_NOT_CONNECTED; |
| 105 } |
| 106 |
101 return socket_->Read( | 107 return socket_->Read( |
102 read_buffer_.get(), kMaxPacketSize, | 108 read_buffer_.get(), kMaxPacketSize, |
103 base::Bind(&QuicP2PSession::DoReadLoop, base::Unretained(this))); | 109 base::Bind(&QuicP2PSession::DoReadLoop, base::Unretained(this))); |
104 } | 110 } |
105 | 111 |
106 int QuicP2PSession::DoReadComplete(int result) { | 112 int QuicP2PSession::DoReadComplete(int result) { |
107 DCHECK_EQ(read_state_, READ_STATE_DO_READ_COMPLETE); | 113 DCHECK_EQ(read_state_, READ_STATE_DO_READ_COMPLETE); |
108 read_state_ = READ_STATE_DO_READ; | 114 read_state_ = READ_STATE_DO_READ; |
109 | 115 |
110 if (result <= 0) { | 116 if (result <= 0) { |
111 connection()->CloseConnection(net::QUIC_PACKET_READ_ERROR, false); | 117 connection()->CloseConnection(net::QUIC_PACKET_READ_ERROR, false); |
112 return result; | 118 return result; |
113 } | 119 } |
114 | 120 |
115 QuicEncryptedPacket packet(read_buffer_->data(), result); | 121 QuicEncryptedPacket packet(read_buffer_->data(), result); |
116 connection()->ProcessUdpPacket(connection()->self_address(), | 122 connection()->ProcessUdpPacket(connection()->self_address(), |
117 connection()->peer_address(), packet); | 123 connection()->peer_address(), packet); |
118 return OK; | 124 return OK; |
119 } | 125 } |
120 | 126 |
121 } // namespace net | 127 } // namespace net |
OLD | NEW |