OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 sequence_number_of_last_sent_packet_(0), | 228 sequence_number_of_last_sent_packet_(0), |
229 sent_packet_manager_( | 229 sent_packet_manager_( |
230 is_server, clock_, &stats_, kTCP, | 230 is_server, clock_, &stats_, kTCP, |
231 FLAGS_quic_use_time_loss_detection ? kTime : kNack), | 231 FLAGS_quic_use_time_loss_detection ? kTime : kNack), |
232 version_negotiation_state_(START_NEGOTIATION), | 232 version_negotiation_state_(START_NEGOTIATION), |
233 is_server_(is_server), | 233 is_server_(is_server), |
234 connected_(true), | 234 connected_(true), |
235 peer_ip_changed_(false), | 235 peer_ip_changed_(false), |
236 peer_port_changed_(false), | 236 peer_port_changed_(false), |
237 self_ip_changed_(false), | 237 self_ip_changed_(false), |
238 self_port_changed_(false) { | 238 self_port_changed_(false), |
| 239 weak_factory_(this) { |
239 if (!is_server_) { | 240 if (!is_server_) { |
240 // Pacing will be enabled if the client negotiates it. | 241 // Pacing will be enabled if the client negotiates it. |
241 sent_packet_manager_.MaybeEnablePacing(); | 242 sent_packet_manager_.MaybeEnablePacing(); |
242 } | 243 } |
243 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " | 244 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " |
244 << connection_id; | 245 << connection_id; |
245 timeout_alarm_->Set(clock_->ApproximateNow().Add(idle_network_timeout_)); | 246 timeout_alarm_->Set(clock_->ApproximateNow().Add(idle_network_timeout_)); |
246 framer_.set_visitor(this); | 247 framer_.set_visitor(this); |
247 framer_.set_received_entropy_calculator(&received_packet_manager_); | 248 framer_.set_received_entropy_calculator(&received_packet_manager_); |
248 stats_.connection_creation_time = clock_->ApproximateNow(); | 249 stats_.connection_creation_time = clock_->ApproximateNow(); |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 // TODO(alyssar): implement zero server state negotiation. | 964 // TODO(alyssar): implement zero server state negotiation. |
964 pending_version_negotiation_packet_ = true; | 965 pending_version_negotiation_packet_ = true; |
965 if (writer_->IsWriteBlocked()) { | 966 if (writer_->IsWriteBlocked()) { |
966 visitor_->OnWriteBlocked(); | 967 visitor_->OnWriteBlocked(); |
967 return; | 968 return; |
968 } | 969 } |
969 scoped_ptr<QuicEncryptedPacket> version_packet( | 970 scoped_ptr<QuicEncryptedPacket> version_packet( |
970 packet_generator_.SerializeVersionNegotiationPacket( | 971 packet_generator_.SerializeVersionNegotiationPacket( |
971 framer_.supported_versions())); | 972 framer_.supported_versions())); |
972 WriteResult result = writer_->WritePacket( | 973 WriteResult result = writer_->WritePacket( |
973 version_packet->data(), version_packet->length(), | 974 version_packet->data(), |
974 self_address().address(), peer_address()); | 975 version_packet->length(), |
| 976 self_address().address(), |
| 977 peer_address(), |
| 978 base::Callback<void(WriteResult wr)>()); |
975 | 979 |
976 if (result.status == WRITE_STATUS_ERROR) { | 980 if (result.status == WRITE_STATUS_ERROR) { |
977 // We can't send an error as the socket is presumably borked. | 981 // We can't send an error as the socket is presumably borked. |
978 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); | 982 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); |
979 return; | 983 return; |
980 } | 984 } |
981 if (result.status == WRITE_STATUS_BLOCKED) { | 985 if (result.status == WRITE_STATUS_BLOCKED) { |
982 visitor_->OnWriteBlocked(); | 986 visitor_->OnWriteBlocked(); |
983 if (writer_->IsWriteBlockedDataBuffered()) { | 987 if (writer_->IsWriteBlockedDataBuffered()) { |
984 pending_version_negotiation_packet_ = false; | 988 pending_version_negotiation_packet_ = false; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1387 |
1384 DCHECK(encrypted->length() <= kMaxPacketSize || | 1388 DCHECK(encrypted->length() <= kMaxPacketSize || |
1385 FLAGS_quic_allow_oversized_packets_for_test) | 1389 FLAGS_quic_allow_oversized_packets_for_test) |
1386 << "Packet " << sequence_number << " will not be read; too large: " | 1390 << "Packet " << sequence_number << " will not be read; too large: " |
1387 << packet.packet->length() << " " << encrypted->length() << " " | 1391 << packet.packet->length() << " " << encrypted->length() << " " |
1388 << " close: " << (packet.type == CONNECTION_CLOSE ? "yes" : "no"); | 1392 << " close: " << (packet.type == CONNECTION_CLOSE ? "yes" : "no"); |
1389 | 1393 |
1390 DCHECK(pending_write_.get() == NULL); | 1394 DCHECK(pending_write_.get() == NULL); |
1391 pending_write_.reset(new QueuedPacket(packet)); | 1395 pending_write_.reset(new QueuedPacket(packet)); |
1392 | 1396 |
1393 WriteResult result = writer_->WritePacket(encrypted->data(), | 1397 WriteResult result = writer_->WritePacket( |
1394 encrypted->length(), | 1398 encrypted->data(), |
1395 self_address().address(), | 1399 encrypted->length(), |
1396 peer_address()); | 1400 self_address().address(), |
| 1401 peer_address(), |
| 1402 base::Bind(base::IgnoreResult(&QuicConnection::OnPacketSent), |
| 1403 weak_factory_.GetWeakPtr())); |
1397 if (result.error_code == ERR_IO_PENDING) { | 1404 if (result.error_code == ERR_IO_PENDING) { |
1398 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1405 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
1399 } | 1406 } |
1400 if (debug_visitor_) { | 1407 if (debug_visitor_) { |
1401 // Pass the write result to the visitor. | 1408 // Pass the write result to the visitor. |
1402 debug_visitor_->OnPacketSent(sequence_number, | 1409 debug_visitor_->OnPacketSent(sequence_number, |
1403 packet.encryption_level, | 1410 packet.encryption_level, |
1404 packet.transmission_type, | 1411 packet.transmission_type, |
1405 *encrypted, | 1412 *encrypted, |
1406 result); | 1413 result); |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 // If we changed the generator's batch state, restore original batch state. | 1985 // If we changed the generator's batch state, restore original batch state. |
1979 if (!already_in_batch_mode_) { | 1986 if (!already_in_batch_mode_) { |
1980 DVLOG(1) << "Leaving Batch Mode."; | 1987 DVLOG(1) << "Leaving Batch Mode."; |
1981 connection_->packet_generator_.FinishBatchOperations(); | 1988 connection_->packet_generator_.FinishBatchOperations(); |
1982 } | 1989 } |
1983 DCHECK_EQ(already_in_batch_mode_, | 1990 DCHECK_EQ(already_in_batch_mode_, |
1984 connection_->packet_generator_.InBatchMode()); | 1991 connection_->packet_generator_.InBatchMode()); |
1985 } | 1992 } |
1986 | 1993 |
1987 } // namespace net | 1994 } // namespace net |
OLD | NEW |