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