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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/test/fuzzed_data_provider.h" | 12 #include "base/test/fuzzed_data_provider.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
| 15 #include "net/log/net_log_source_type.h" |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Some of the socket errors that can be returned by normal socket connection | 21 // Some of the socket errors that can be returned by normal socket connection |
21 // attempts. | 22 // attempts. |
22 const Error kConnectErrors[] = { | 23 const Error kConnectErrors[] = { |
23 ERR_CONNECTION_RESET, ERR_CONNECTION_CLOSED, ERR_FAILED, | 24 ERR_CONNECTION_RESET, ERR_CONNECTION_CLOSED, ERR_FAILED, |
24 ERR_CONNECTION_TIMED_OUT, ERR_ACCESS_DENIED, ERR_CONNECTION_REFUSED, | 25 ERR_CONNECTION_TIMED_OUT, ERR_ACCESS_DENIED, ERR_CONNECTION_REFUSED, |
25 ERR_ADDRESS_UNREACHABLE}; | 26 ERR_ADDRESS_UNREACHABLE}; |
26 | 27 |
27 // Some of the socket errors that can be returned by normal socket reads / | 28 // Some of the socket errors that can be returned by normal socket reads / |
28 // writes. The first one is returned when no more input data remains, so it's | 29 // writes. The first one is returned when no more input data remains, so it's |
29 // one of the most common ones. | 30 // one of the most common ones. |
30 const Error kReadWriteErrors[] = {ERR_CONNECTION_CLOSED, ERR_FAILED, | 31 const Error kReadWriteErrors[] = {ERR_CONNECTION_CLOSED, ERR_FAILED, |
31 ERR_TIMED_OUT, ERR_CONNECTION_RESET}; | 32 ERR_TIMED_OUT, ERR_CONNECTION_RESET}; |
32 | 33 |
33 } // namespace | 34 } // namespace |
34 | 35 |
35 FuzzedSocket::FuzzedSocket(base::FuzzedDataProvider* data_provider, | 36 FuzzedSocket::FuzzedSocket(base::FuzzedDataProvider* data_provider, |
36 net::NetLog* net_log) | 37 net::NetLog* net_log) |
37 : data_provider_(data_provider), | 38 : data_provider_(data_provider), |
38 bound_net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), | 39 bound_net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)), |
39 remote_address_(IPEndPoint(IPAddress::IPv4Localhost(), 80)), | 40 remote_address_(IPEndPoint(IPAddress::IPv4Localhost(), 80)), |
40 weak_factory_(this) {} | 41 weak_factory_(this) {} |
41 | 42 |
42 FuzzedSocket::~FuzzedSocket() {} | 43 FuzzedSocket::~FuzzedSocket() {} |
43 | 44 |
44 int FuzzedSocket::Read(IOBuffer* buf, | 45 int FuzzedSocket::Read(IOBuffer* buf, |
45 int buf_len, | 46 int buf_len, |
46 const CompletionCallback& callback) { | 47 const CompletionCallback& callback) { |
47 DCHECK(!connect_pending_); | 48 DCHECK(!connect_pending_); |
48 DCHECK(!read_pending_); | 49 DCHECK(!read_pending_); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 void FuzzedSocket::OnConnectComplete(const CompletionCallback& callback, | 276 void FuzzedSocket::OnConnectComplete(const CompletionCallback& callback, |
276 int result) { | 277 int result) { |
277 CHECK(connect_pending_); | 278 CHECK(connect_pending_); |
278 connect_pending_ = false; | 279 connect_pending_ = false; |
279 if (result < 0) | 280 if (result < 0) |
280 error_pending_ = false; | 281 error_pending_ = false; |
281 callback.Run(result); | 282 callback.Run(result); |
282 } | 283 } |
283 | 284 |
284 } // namespace net | 285 } // namespace net |
OLD | NEW |