OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // Called when a TCP connection is established or fails | 137 // Called when a TCP connection is established or fails |
138 void OnSocketConnect(rtc::AsyncPacketSocket* socket); | 138 void OnSocketConnect(rtc::AsyncPacketSocket* socket); |
139 void OnSocketClose(rtc::AsyncPacketSocket* socket, int error); | 139 void OnSocketClose(rtc::AsyncPacketSocket* socket, int error); |
140 | 140 |
141 // Called when a packet is received on this socket. | 141 // Called when a packet is received on this socket. |
142 void OnReadPacket( | 142 void OnReadPacket( |
143 rtc::AsyncPacketSocket* socket, | 143 rtc::AsyncPacketSocket* socket, |
144 const char* data, size_t size, | 144 const char* data, size_t size, |
145 const rtc::SocketAddress& remote_addr, | 145 const rtc::SocketAddress& remote_addr, |
146 const rtc::PacketTime& packet_time); | 146 const rtc::PacketTime& packet_time); |
| 147 |
| 148 void OnSentPacket(rtc::AsyncPacketSocket* socket, |
| 149 const rtc::SentPacket& sent_packet); |
| 150 |
147 // Called when the socket is currently able to send. | 151 // Called when the socket is currently able to send. |
148 void OnReadyToSend(rtc::AsyncPacketSocket* socket); | 152 void OnReadyToSend(rtc::AsyncPacketSocket* socket); |
149 | 153 |
150 // Sends the given data on the socket to the server with no wrapping. This | 154 // Sends the given data on the socket to the server with no wrapping. This |
151 // returns the number of bytes written or -1 if an error occurred. | 155 // returns the number of bytes written or -1 if an error occurred. |
152 int SendPacket(const void* data, size_t size, | 156 int SendPacket(const void* data, size_t size, |
153 const rtc::PacketOptions& options); | 157 const rtc::PacketOptions& options); |
154 }; | 158 }; |
155 | 159 |
156 // Handles an allocate request for a particular RelayEntry. | 160 // Handles an allocate request for a particular RelayEntry. |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 } | 505 } |
502 | 506 |
503 // If we failed to get a socket, move on to the next protocol. | 507 // If we failed to get a socket, move on to the next protocol. |
504 if (!socket) { | 508 if (!socket) { |
505 port()->thread()->Post(this, kMessageConnectTimeout); | 509 port()->thread()->Post(this, kMessageConnectTimeout); |
506 return; | 510 return; |
507 } | 511 } |
508 | 512 |
509 // Otherwise, create the new connection and configure any socket options. | 513 // Otherwise, create the new connection and configure any socket options. |
510 socket->SignalReadPacket.connect(this, &RelayEntry::OnReadPacket); | 514 socket->SignalReadPacket.connect(this, &RelayEntry::OnReadPacket); |
| 515 socket->SignalSentPacket.connect(this, &RelayEntry::OnSentPacket); |
511 socket->SignalReadyToSend.connect(this, &RelayEntry::OnReadyToSend); | 516 socket->SignalReadyToSend.connect(this, &RelayEntry::OnReadyToSend); |
512 current_connection_ = new RelayConnection(ra, socket, port()->thread()); | 517 current_connection_ = new RelayConnection(ra, socket, port()->thread()); |
513 for (size_t i = 0; i < port_->options().size(); ++i) { | 518 for (size_t i = 0; i < port_->options().size(); ++i) { |
514 current_connection_->SetSocketOption(port_->options()[i].first, | 519 current_connection_->SetSocketOption(port_->options()[i].first, |
515 port_->options()[i].second); | 520 port_->options()[i].second); |
516 } | 521 } |
517 | 522 |
518 // If we're trying UDP, start binding requests. | 523 // If we're trying UDP, start binding requests. |
519 // If we're trying TCP, wait for connection with a fixed timeout. | 524 // If we're trying TCP, wait for connection with a fixed timeout. |
520 if ((ra->proto == PROTO_TCP) || (ra->proto == PROTO_SSLTCP)) { | 525 if ((ra->proto == PROTO_TCP) || (ra->proto == PROTO_SSLTCP)) { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 if (!data_attr) { | 745 if (!data_attr) { |
741 LOG(INFO) << "Data indication has no data"; | 746 LOG(INFO) << "Data indication has no data"; |
742 return; | 747 return; |
743 } | 748 } |
744 | 749 |
745 // Process the actual data and remote address in the normal manner. | 750 // Process the actual data and remote address in the normal manner. |
746 port_->OnReadPacket(data_attr->bytes(), data_attr->length(), remote_addr2, | 751 port_->OnReadPacket(data_attr->bytes(), data_attr->length(), remote_addr2, |
747 PROTO_UDP, packet_time); | 752 PROTO_UDP, packet_time); |
748 } | 753 } |
749 | 754 |
| 755 void RelayEntry::OnSentPacket(rtc::AsyncPacketSocket* socket, |
| 756 const rtc::SentPacket& sent_packet) { |
| 757 port_->OnSentPacket(sent_packet); |
| 758 } |
| 759 |
750 void RelayEntry::OnReadyToSend(rtc::AsyncPacketSocket* socket) { | 760 void RelayEntry::OnReadyToSend(rtc::AsyncPacketSocket* socket) { |
751 if (connected()) { | 761 if (connected()) { |
752 port_->OnReadyToSend(); | 762 port_->OnReadyToSend(); |
753 } | 763 } |
754 } | 764 } |
755 | 765 |
756 int RelayEntry::SendPacket(const void* data, size_t size, | 766 int RelayEntry::SendPacket(const void* data, size_t size, |
757 const rtc::PacketOptions& options) { | 767 const rtc::PacketOptions& options) { |
758 int sent = 0; | 768 int sent = 0; |
759 if (current_connection_) { | 769 if (current_connection_) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 if (rtc::TimeSince(start_time_) <= kRetryTimeout) | 837 if (rtc::TimeSince(start_time_) <= kRetryTimeout) |
828 entry_->ScheduleKeepAlive(); | 838 entry_->ScheduleKeepAlive(); |
829 } | 839 } |
830 | 840 |
831 void AllocateRequest::OnTimeout() { | 841 void AllocateRequest::OnTimeout() { |
832 LOG(INFO) << "Allocate request timed out"; | 842 LOG(INFO) << "Allocate request timed out"; |
833 entry_->HandleConnectFailure(connection_->socket()); | 843 entry_->HandleConnectFailure(connection_->socket()); |
834 } | 844 } |
835 | 845 |
836 } // namespace cricket | 846 } // namespace cricket |
OLD | NEW |