Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: jingle/glue/channel_socket_adapter.cc

Issue 450463002: Update webrtc&libjingle 6774:6825. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « jingle/glue/channel_socket_adapter.h ('k') | jingle/glue/channel_socket_adapter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "jingle/glue/channel_socket_adapter.h" 5 #include "jingle/glue/channel_socket_adapter.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 DCHECK(buffer); 69 DCHECK(buffer);
70 DCHECK(!callback.is_null()); 70 DCHECK(!callback.is_null());
71 CHECK(write_callback_.is_null()); 71 CHECK(write_callback_.is_null());
72 72
73 if (!channel_) { 73 if (!channel_) {
74 DCHECK(closed_error_code_ != net::OK); 74 DCHECK(closed_error_code_ != net::OK);
75 return closed_error_code_; 75 return closed_error_code_;
76 } 76 }
77 77
78 int result; 78 int result;
79 talk_base::PacketOptions options; 79 rtc::PacketOptions options;
80 if (channel_->writable()) { 80 if (channel_->writable()) {
81 result = channel_->SendPacket(buffer->data(), buffer_size, options); 81 result = channel_->SendPacket(buffer->data(), buffer_size, options);
82 if (result < 0) { 82 if (result < 0) {
83 result = net::MapSystemError(channel_->GetError()); 83 result = net::MapSystemError(channel_->GetError());
84 84
85 // If the underlying socket returns IO pending where it shouldn't we 85 // If the underlying socket returns IO pending where it shouldn't we
86 // pretend the packet is dropped and return as succeeded because no 86 // pretend the packet is dropped and return as succeeded because no
87 // writeable callback will happen. 87 // writeable callback will happen.
88 if (result == net::ERR_IO_PENDING) 88 if (result == net::ERR_IO_PENDING)
89 result = net::OK; 89 result = net::OK;
90 } 90 }
91 } else { 91 } else {
92 // Channel is not writable yet. 92 // Channel is not writable yet.
93 result = net::ERR_IO_PENDING; 93 result = net::ERR_IO_PENDING;
94 write_callback_ = callback; 94 write_callback_ = callback;
95 write_buffer_ = buffer; 95 write_buffer_ = buffer;
96 write_buffer_size_ = buffer_size; 96 write_buffer_size_ = buffer_size;
97 } 97 }
98 98
99 return result; 99 return result;
100 } 100 }
101 101
102 int TransportChannelSocketAdapter::SetReceiveBufferSize(int32 size) { 102 int TransportChannelSocketAdapter::SetReceiveBufferSize(int32 size) {
103 DCHECK_EQ(base::MessageLoop::current(), message_loop_); 103 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
104 return (channel_->SetOption(talk_base::Socket::OPT_RCVBUF, size) == 0) ? 104 return (channel_->SetOption(rtc::Socket::OPT_RCVBUF, size) == 0) ?
105 net::OK : net::ERR_SOCKET_SET_RECEIVE_BUFFER_SIZE_ERROR; 105 net::OK : net::ERR_SOCKET_SET_RECEIVE_BUFFER_SIZE_ERROR;
106 } 106 }
107 107
108 int TransportChannelSocketAdapter::SetSendBufferSize(int32 size) { 108 int TransportChannelSocketAdapter::SetSendBufferSize(int32 size) {
109 DCHECK_EQ(base::MessageLoop::current(), message_loop_); 109 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
110 return (channel_->SetOption(talk_base::Socket::OPT_SNDBUF, size) == 0) ? 110 return (channel_->SetOption(rtc::Socket::OPT_SNDBUF, size) == 0) ?
111 net::OK : net::ERR_SOCKET_SET_SEND_BUFFER_SIZE_ERROR; 111 net::OK : net::ERR_SOCKET_SET_SEND_BUFFER_SIZE_ERROR;
112 } 112 }
113 113
114 void TransportChannelSocketAdapter::Close(int error_code) { 114 void TransportChannelSocketAdapter::Close(int error_code) {
115 DCHECK_EQ(base::MessageLoop::current(), message_loop_); 115 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
116 116
117 if (!channel_) // Already closed. 117 if (!channel_) // Already closed.
118 return; 118 return;
119 119
120 DCHECK(error_code != net::OK); 120 DCHECK(error_code != net::OK);
(...skipping 14 matching lines...) Expand all
135 write_callback_.Reset(); 135 write_callback_.Reset();
136 write_buffer_ = NULL; 136 write_buffer_ = NULL;
137 callback.Run(error_code); 137 callback.Run(error_code);
138 } 138 }
139 } 139 }
140 140
141 void TransportChannelSocketAdapter::OnNewPacket( 141 void TransportChannelSocketAdapter::OnNewPacket(
142 cricket::TransportChannel* channel, 142 cricket::TransportChannel* channel,
143 const char* data, 143 const char* data,
144 size_t data_size, 144 size_t data_size,
145 const talk_base::PacketTime& packet_time, 145 const rtc::PacketTime& packet_time,
146 int flags) { 146 int flags) {
147 DCHECK_EQ(base::MessageLoop::current(), message_loop_); 147 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
148 DCHECK_EQ(channel, channel_); 148 DCHECK_EQ(channel, channel_);
149 if (!read_callback_.is_null()) { 149 if (!read_callback_.is_null()) {
150 DCHECK(read_buffer_.get()); 150 DCHECK(read_buffer_.get());
151 CHECK_LT(data_size, static_cast<size_t>(std::numeric_limits<int>::max())); 151 CHECK_LT(data_size, static_cast<size_t>(std::numeric_limits<int>::max()));
152 152
153 if (read_buffer_size_ < static_cast<int>(data_size)) { 153 if (read_buffer_size_ < static_cast<int>(data_size)) {
154 LOG(WARNING) << "Data buffer is smaller than the received packet. " 154 LOG(WARNING) << "Data buffer is smaller than the received packet. "
155 << "Dropping the data that doesn't fit."; 155 << "Dropping the data that doesn't fit.";
(...skipping 11 matching lines...) Expand all
167 LOG(WARNING) 167 LOG(WARNING)
168 << "Data was received without a callback. Dropping the packet."; 168 << "Data was received without a callback. Dropping the packet.";
169 } 169 }
170 } 170 }
171 171
172 void TransportChannelSocketAdapter::OnWritableState( 172 void TransportChannelSocketAdapter::OnWritableState(
173 cricket::TransportChannel* channel) { 173 cricket::TransportChannel* channel) {
174 DCHECK_EQ(base::MessageLoop::current(), message_loop_); 174 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
175 // Try to send the packet if there is a pending write. 175 // Try to send the packet if there is a pending write.
176 if (!write_callback_.is_null()) { 176 if (!write_callback_.is_null()) {
177 talk_base::PacketOptions options; 177 rtc::PacketOptions options;
178 int result = channel_->SendPacket(write_buffer_->data(), 178 int result = channel_->SendPacket(write_buffer_->data(),
179 write_buffer_size_, 179 write_buffer_size_,
180 options); 180 options);
181 if (result < 0) 181 if (result < 0)
182 result = net::MapSystemError(channel_->GetError()); 182 result = net::MapSystemError(channel_->GetError());
183 183
184 if (result != net::ERR_IO_PENDING) { 184 if (result != net::ERR_IO_PENDING) {
185 net::CompletionCallback callback = write_callback_; 185 net::CompletionCallback callback = write_callback_;
186 write_callback_.Reset(); 186 write_callback_.Reset();
187 write_buffer_ = NULL; 187 write_buffer_ = NULL;
188 callback.Run(result); 188 callback.Run(result);
189 } 189 }
190 } 190 }
191 } 191 }
192 192
193 void TransportChannelSocketAdapter::OnChannelDestroyed( 193 void TransportChannelSocketAdapter::OnChannelDestroyed(
194 cricket::TransportChannel* channel) { 194 cricket::TransportChannel* channel) {
195 DCHECK_EQ(base::MessageLoop::current(), message_loop_); 195 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
196 DCHECK_EQ(channel, channel_); 196 DCHECK_EQ(channel, channel_);
197 Close(net::ERR_CONNECTION_ABORTED); 197 Close(net::ERR_CONNECTION_ABORTED);
198 } 198 }
199 199
200 } // namespace jingle_glue 200 } // namespace jingle_glue
OLDNEW
« no previous file with comments | « jingle/glue/channel_socket_adapter.h ('k') | jingle/glue/channel_socket_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698