| 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 OnPacketSent(rtc::AsyncPacketSocket* socket, |
| 149 const rtc::SocketAddress& addr, |
| 150 const rtc::SentPacket& sent_packet); |
| 151 |
| 147 // Called when the socket is currently able to send. | 152 // Called when the socket is currently able to send. |
| 148 void OnReadyToSend(rtc::AsyncPacketSocket* socket); | 153 void OnReadyToSend(rtc::AsyncPacketSocket* socket); |
| 149 | 154 |
| 150 // Sends the given data on the socket to the server with no wrapping. This | 155 // 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. | 156 // returns the number of bytes written or -1 if an error occurred. |
| 152 int SendPacket(const void* data, size_t size, | 157 int SendPacket(const void* data, size_t size, |
| 153 const rtc::PacketOptions& options); | 158 const rtc::PacketOptions& options); |
| 154 }; | 159 }; |
| 155 | 160 |
| 156 // Handles an allocate request for a particular RelayEntry. | 161 // Handles an allocate request for a particular RelayEntry. |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 } | 499 } |
| 495 | 500 |
| 496 // If we failed to get a socket, move on to the next protocol. | 501 // If we failed to get a socket, move on to the next protocol. |
| 497 if (!socket) { | 502 if (!socket) { |
| 498 port()->thread()->Post(this, kMessageConnectTimeout); | 503 port()->thread()->Post(this, kMessageConnectTimeout); |
| 499 return; | 504 return; |
| 500 } | 505 } |
| 501 | 506 |
| 502 // Otherwise, create the new connection and configure any socket options. | 507 // Otherwise, create the new connection and configure any socket options. |
| 503 socket->SignalReadPacket.connect(this, &RelayEntry::OnReadPacket); | 508 socket->SignalReadPacket.connect(this, &RelayEntry::OnReadPacket); |
| 509 socket->SignalPacketSent.connect(this, &RelayEntry::OnPacketSent); |
| 504 socket->SignalReadyToSend.connect(this, &RelayEntry::OnReadyToSend); | 510 socket->SignalReadyToSend.connect(this, &RelayEntry::OnReadyToSend); |
| 505 current_connection_ = new RelayConnection(ra, socket, port()->thread()); | 511 current_connection_ = new RelayConnection(ra, socket, port()->thread()); |
| 506 for (size_t i = 0; i < port_->options().size(); ++i) { | 512 for (size_t i = 0; i < port_->options().size(); ++i) { |
| 507 current_connection_->SetSocketOption(port_->options()[i].first, | 513 current_connection_->SetSocketOption(port_->options()[i].first, |
| 508 port_->options()[i].second); | 514 port_->options()[i].second); |
| 509 } | 515 } |
| 510 | 516 |
| 511 // If we're trying UDP, start binding requests. | 517 // If we're trying UDP, start binding requests. |
| 512 // If we're trying TCP, wait for connection with a fixed timeout. | 518 // If we're trying TCP, wait for connection with a fixed timeout. |
| 513 if ((ra->proto == PROTO_TCP) || (ra->proto == PROTO_SSLTCP)) { | 519 if ((ra->proto == PROTO_TCP) || (ra->proto == PROTO_SSLTCP)) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 if (!data_attr) { | 739 if (!data_attr) { |
| 734 LOG(INFO) << "Data indication has no data"; | 740 LOG(INFO) << "Data indication has no data"; |
| 735 return; | 741 return; |
| 736 } | 742 } |
| 737 | 743 |
| 738 // Process the actual data and remote address in the normal manner. | 744 // Process the actual data and remote address in the normal manner. |
| 739 port_->OnReadPacket(data_attr->bytes(), data_attr->length(), remote_addr2, | 745 port_->OnReadPacket(data_attr->bytes(), data_attr->length(), remote_addr2, |
| 740 PROTO_UDP, packet_time); | 746 PROTO_UDP, packet_time); |
| 741 } | 747 } |
| 742 | 748 |
| 749 void RelayEntry::OnPacketSent(rtc::AsyncPacketSocket* socket, |
| 750 const rtc::SocketAddress& addr, |
| 751 const rtc::SentPacket& sent_packet) { |
| 752 port_->OnPacketSent(addr, sent_packet); |
| 753 } |
| 754 |
| 743 void RelayEntry::OnReadyToSend(rtc::AsyncPacketSocket* socket) { | 755 void RelayEntry::OnReadyToSend(rtc::AsyncPacketSocket* socket) { |
| 744 if (connected()) { | 756 if (connected()) { |
| 745 port_->OnReadyToSend(); | 757 port_->OnReadyToSend(); |
| 746 } | 758 } |
| 747 } | 759 } |
| 748 | 760 |
| 749 int RelayEntry::SendPacket(const void* data, size_t size, | 761 int RelayEntry::SendPacket(const void* data, size_t size, |
| 750 const rtc::PacketOptions& options) { | 762 const rtc::PacketOptions& options) { |
| 751 int sent = 0; | 763 int sent = 0; |
| 752 if (current_connection_) { | 764 if (current_connection_) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 if (rtc::TimeSince(start_time_) <= kRetryTimeout) | 832 if (rtc::TimeSince(start_time_) <= kRetryTimeout) |
| 821 entry_->ScheduleKeepAlive(); | 833 entry_->ScheduleKeepAlive(); |
| 822 } | 834 } |
| 823 | 835 |
| 824 void AllocateRequest::OnTimeout() { | 836 void AllocateRequest::OnTimeout() { |
| 825 LOG(INFO) << "Allocate request timed out"; | 837 LOG(INFO) << "Allocate request timed out"; |
| 826 entry_->HandleConnectFailure(connection_->socket()); | 838 entry_->HandleConnectFailure(connection_->socket()); |
| 827 } | 839 } |
| 828 | 840 |
| 829 } // namespace cricket | 841 } // namespace cricket |
| OLD | NEW |