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

Side by Side Diff: webrtc/base/virtualsocketserver.cc

Issue 2915243002: Fixing SSL error that occurs when underlying socket is blocked. (Closed)
Patch Set: Send an additional message while socket is blocked. Created 3 years, 6 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
OLDNEW
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 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const uint32_t TCP_MSS = 1400; // Maximum segment size 49 const uint32_t TCP_MSS = 1400; // Maximum segment size
50 50
51 // Note: The current algorithm doesn't work for sample sizes smaller than this. 51 // Note: The current algorithm doesn't work for sample sizes smaller than this.
52 const int NUM_SAMPLES = 1000; 52 const int NUM_SAMPLES = 1000;
53 53
54 enum { 54 enum {
55 MSG_ID_PACKET, 55 MSG_ID_PACKET,
56 MSG_ID_ADDRESS_BOUND, 56 MSG_ID_ADDRESS_BOUND,
57 MSG_ID_CONNECT, 57 MSG_ID_CONNECT,
58 MSG_ID_DISCONNECT, 58 MSG_ID_DISCONNECT,
59 MSG_ID_SIGNALREADEVENT,
59 }; 60 };
60 61
61 // Packets are passed between sockets as messages. We copy the data just like 62 // Packets are passed between sockets as messages. We copy the data just like
62 // the kernel does. 63 // the kernel does.
63 class Packet : public MessageData { 64 class Packet : public MessageData {
64 public: 65 public:
65 Packet(const char* data, size_t size, const SocketAddress& from) 66 Packet(const char* data, size_t size, const SocketAddress& from)
66 : size_(size), consumed_(0), from_(from) { 67 : size_(size), consumed_(0), from_(from) {
67 RTC_DCHECK(nullptr != data); 68 RTC_DCHECK(nullptr != data);
68 data_ = new char[size_]; 69 data_ = new char[size_];
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 memcpy(pv, packet->data(), data_read); 297 memcpy(pv, packet->data(), data_read);
297 *paddr = packet->from(); 298 *paddr = packet->from();
298 299
299 if (data_read < packet->size()) { 300 if (data_read < packet->size()) {
300 packet->Consume(data_read); 301 packet->Consume(data_read);
301 } else { 302 } else {
302 recv_buffer_.pop_front(); 303 recv_buffer_.pop_front();
303 delete packet; 304 delete packet;
304 } 305 }
305 306
307 // To behave like a real socket, SignalReadEvent should fire in the next
308 // message loop pass if there's still data buffered.
309 if (!recv_buffer_.empty()) {
310 // Clear the message so it doesn't end up posted multiple times.
311 server_->msg_queue_->Clear(this, MSG_ID_SIGNALREADEVENT);
312 server_->msg_queue_->Post(RTC_FROM_HERE, this, MSG_ID_SIGNALREADEVENT);
313 }
314
306 if (SOCK_STREAM == type_) { 315 if (SOCK_STREAM == type_) {
307 bool was_full = (recv_buffer_size_ == server_->recv_buffer_capacity_); 316 bool was_full = (recv_buffer_size_ == server_->recv_buffer_capacity_);
308 recv_buffer_size_ -= data_read; 317 recv_buffer_size_ -= data_read;
309 if (was_full) { 318 if (was_full) {
310 VirtualSocket* sender = server_->LookupBinding(remote_addr_); 319 VirtualSocket* sender = server_->LookupBinding(remote_addr_);
311 RTC_DCHECK(nullptr != sender); 320 RTC_DCHECK(nullptr != sender);
312 server_->SendTcp(sender); 321 server_->SendTcp(sender);
313 } 322 }
314 } 323 }
315 324
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 if (CS_CLOSED != state_) { 423 if (CS_CLOSED != state_) {
415 int error = (CS_CONNECTING == state_) ? ECONNREFUSED : 0; 424 int error = (CS_CONNECTING == state_) ? ECONNREFUSED : 0;
416 state_ = CS_CLOSED; 425 state_ = CS_CLOSED;
417 remote_addr_.Clear(); 426 remote_addr_.Clear();
418 if (async_) { 427 if (async_) {
419 SignalCloseEvent(this, error); 428 SignalCloseEvent(this, error);
420 } 429 }
421 } 430 }
422 } else if (pmsg->message_id == MSG_ID_ADDRESS_BOUND) { 431 } else if (pmsg->message_id == MSG_ID_ADDRESS_BOUND) {
423 SignalAddressReady(this, GetLocalAddress()); 432 SignalAddressReady(this, GetLocalAddress());
433 } else if (pmsg->message_id == MSG_ID_SIGNALREADEVENT) {
434 if (!recv_buffer_.empty()) {
435 SignalReadEvent(this);
436 }
424 } else { 437 } else {
425 RTC_NOTREACHED(); 438 RTC_NOTREACHED();
426 } 439 }
427 } 440 }
428 441
429 int VirtualSocket::InitiateConnect(const SocketAddress& addr, bool use_delay) { 442 int VirtualSocket::InitiateConnect(const SocketAddress& addr, bool use_delay) {
430 if (!remote_addr_.IsNil()) { 443 if (!remote_addr_.IsNil()) {
431 error_ = (CS_CONNECTED == state_) ? EISCONN : EINPROGRESS; 444 error_ = (CS_CONNECTED == state_) ? EISCONN : EINPROGRESS;
432 return -1; 445 return -1;
433 } 446 }
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) { 1193 void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) {
1181 RTC_DCHECK(!IPIsAny(from_addr)); 1194 RTC_DCHECK(!IPIsAny(from_addr));
1182 if (from_addr.family() == AF_INET) { 1195 if (from_addr.family() == AF_INET) {
1183 default_route_v4_ = from_addr; 1196 default_route_v4_ = from_addr;
1184 } else if (from_addr.family() == AF_INET6) { 1197 } else if (from_addr.family() == AF_INET6) {
1185 default_route_v6_ = from_addr; 1198 default_route_v6_ = from_addr;
1186 } 1199 }
1187 } 1200 }
1188 1201
1189 } // namespace rtc 1202 } // namespace rtc
OLDNEW
« webrtc/base/openssladapter.cc ('K') | « webrtc/base/ssladapter_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698