OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "net/socket/socket_bio_adapter.h" | 5 #include "net/socket/socket_bio_adapter.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 SocketBIOAdapter::~SocketBIOAdapter() { | 46 SocketBIOAdapter::~SocketBIOAdapter() { |
47 // BIOs are reference-counted and may outlive the adapter. Clear the pointer | 47 // BIOs are reference-counted and may outlive the adapter. Clear the pointer |
48 // so future operations fail. | 48 // so future operations fail. |
49 bio_->ptr = nullptr; | 49 bio_->ptr = nullptr; |
50 } | 50 } |
51 | 51 |
52 bool SocketBIOAdapter::HasPendingReadData() { | 52 bool SocketBIOAdapter::HasPendingReadData() { |
53 return read_result_ > 0; | 53 return read_result_ > 0; |
54 } | 54 } |
55 | 55 |
| 56 size_t SocketBIOAdapter::GetAllocationSize() const { |
| 57 size_t buffer_size = 0; |
| 58 if (read_buffer_) |
| 59 buffer_size += read_buffer_capacity_; |
| 60 |
| 61 if (write_buffer_) |
| 62 buffer_size += write_buffer_capacity_; |
| 63 return buffer_size; |
| 64 } |
| 65 |
56 int SocketBIOAdapter::BIORead(char* out, int len) { | 66 int SocketBIOAdapter::BIORead(char* out, int len) { |
57 if (len <= 0) | 67 if (len <= 0) |
58 return len; | 68 return len; |
59 | 69 |
60 // If there is no result available synchronously, report any Write() errors | 70 // If there is no result available synchronously, report any Write() errors |
61 // that were observed. Otherwise the application may have encountered a socket | 71 // that were observed. Otherwise the application may have encountered a socket |
62 // error while writing that would otherwise not be reported until the | 72 // error while writing that would otherwise not be reported until the |
63 // application attempted to write again - which it may never do. See | 73 // application attempted to write again - which it may never do. See |
64 // https://crbug.com/249848. | 74 // https://crbug.com/249848. |
65 if (write_error_ != OK && write_error_ != ERR_IO_PENDING && | 75 if (write_error_ != OK && write_error_ != ERR_IO_PENDING && |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 SocketBIOAdapter::BIOReadWrapper, | 341 SocketBIOAdapter::BIOReadWrapper, |
332 nullptr, // puts | 342 nullptr, // puts |
333 nullptr, // gets | 343 nullptr, // gets |
334 SocketBIOAdapter::BIOCtrlWrapper, | 344 SocketBIOAdapter::BIOCtrlWrapper, |
335 nullptr, // create | 345 nullptr, // create |
336 nullptr, // destroy | 346 nullptr, // destroy |
337 nullptr, // callback_ctrl | 347 nullptr, // callback_ctrl |
338 }; | 348 }; |
339 | 349 |
340 } // namespace net | 350 } // namespace net |
OLD | NEW |