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/fuzzed_socket.h" | 5 #include "net/socket/fuzzed_socket.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 result = net_error_; | 56 result = net_error_; |
57 sync = !error_pending_; | 57 sync = !error_pending_; |
58 } else { | 58 } else { |
59 // Otherwise, use |data_provider_|. | 59 // Otherwise, use |data_provider_|. |
60 sync = data_provider_->ConsumeBool(); | 60 sync = data_provider_->ConsumeBool(); |
61 result = data_provider_->ConsumeUint8(); | 61 result = data_provider_->ConsumeUint8(); |
62 if (result > buf_len) | 62 if (result > buf_len) |
63 result = buf_len; | 63 result = buf_len; |
64 | 64 |
65 if (result > 0) { | 65 if (result > 0) { |
66 base::StringPiece data = data_provider_->ConsumeBytes(result); | 66 std::string data = data_provider_->ConsumeBytes(result); |
67 result = data.length(); | 67 result = data.size(); |
68 std::copy(data.data(), data.data() + result, buf->data()); | 68 std::copy(data.data(), data.data() + result, buf->data()); |
69 } | 69 } |
70 | 70 |
71 if (result == 0) { | 71 if (result == 0) { |
72 net_error_ = ConsumeReadWriteErrorFromData(); | 72 net_error_ = ConsumeReadWriteErrorFromData(); |
73 result = net_error_; | 73 result = net_error_; |
74 if (!sync) | 74 if (!sync) |
75 error_pending_ = true; | 75 error_pending_ = true; |
76 } | 76 } |
77 } | 77 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 void FuzzedSocket::OnConnectComplete(const CompletionCallback& callback, | 276 void FuzzedSocket::OnConnectComplete(const CompletionCallback& callback, |
277 int result) { | 277 int result) { |
278 CHECK(connect_pending_); | 278 CHECK(connect_pending_); |
279 connect_pending_ = false; | 279 connect_pending_ = false; |
280 if (result < 0) | 280 if (result < 0) |
281 error_pending_ = false; | 281 error_pending_ = false; |
282 callback.Run(result); | 282 callback.Run(result); |
283 } | 283 } |
284 | 284 |
285 } // namespace net | 285 } // namespace net |
OLD | NEW |