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 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (data_len_ > 0) { | 74 if (data_len_ > 0) { |
75 memmove(buffer_, buffer_ + read, data_len_); | 75 memmove(buffer_, buffer_ + read, data_len_); |
76 } | 76 } |
77 pv = static_cast<char *>(pv) + read; | 77 pv = static_cast<char *>(pv) + read; |
78 cb -= read; | 78 cb -= read; |
79 } | 79 } |
80 | 80 |
81 // FIX: If cb == 0, we won't generate another read event | 81 // FIX: If cb == 0, we won't generate another read event |
82 | 82 |
83 int res = AsyncSocketAdapter::Recv(pv, cb); | 83 int res = AsyncSocketAdapter::Recv(pv, cb); |
84 if (res < 0) | 84 if (res >= 0) { |
85 return res; | 85 // Read from socket and possibly buffer; return combined length |
| 86 return res + static_cast<int>(read); |
| 87 } |
86 | 88 |
87 return res + static_cast<int>(read); | 89 if (read > 0) { |
| 90 // Failed to read from socket, but still read something from buffer |
| 91 return static_cast<int>(read); |
| 92 } |
| 93 |
| 94 // Didn't read anything; return error from socket |
| 95 return res; |
88 } | 96 } |
89 | 97 |
90 void BufferedReadAdapter::BufferInput(bool on) { | 98 void BufferedReadAdapter::BufferInput(bool on) { |
91 buffering_ = on; | 99 buffering_ = on; |
92 } | 100 } |
93 | 101 |
94 void BufferedReadAdapter::OnReadEvent(AsyncSocket * socket) { | 102 void BufferedReadAdapter::OnReadEvent(AsyncSocket * socket) { |
95 ASSERT(socket == socket_); | 103 ASSERT(socket == socket_); |
96 | 104 |
97 if (!buffering_) { | 105 if (!buffering_) { |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 void LoggingSocketAdapter::OnCloseEvent(AsyncSocket * socket, int err) { | 903 void LoggingSocketAdapter::OnCloseEvent(AsyncSocket * socket, int err) { |
896 LogMultiline(level_, label_.c_str(), false, NULL, 0, hex_mode_, &lms_); | 904 LogMultiline(level_, label_.c_str(), false, NULL, 0, hex_mode_, &lms_); |
897 LogMultiline(level_, label_.c_str(), true, NULL, 0, hex_mode_, &lms_); | 905 LogMultiline(level_, label_.c_str(), true, NULL, 0, hex_mode_, &lms_); |
898 LOG_V(level_) << label_ << " Closed with error: " << err; | 906 LOG_V(level_) << label_ << " Closed with error: " << err; |
899 AsyncSocketAdapter::OnCloseEvent(socket, err); | 907 AsyncSocketAdapter::OnCloseEvent(socket, err); |
900 } | 908 } |
901 | 909 |
902 /////////////////////////////////////////////////////////////////////////////// | 910 /////////////////////////////////////////////////////////////////////////////// |
903 | 911 |
904 } // namespace rtc | 912 } // namespace rtc |
OLD | NEW |