Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_SOCKET_FUZZED_SERVER_SOCKET_H_ | |
| 6 #define NET_SOCKET_FUZZED_SERVER_SOCKET_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
|
mmenke
2017/01/24 16:29:16
I don't think this is being used in this header?
| |
| 9 | |
| 10 #include <memory> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "net/base/ip_endpoint.h" | |
| 16 #include "net/socket/server_socket.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class FuzzedDataProvider; | |
| 20 } | |
| 21 | |
| 22 namespace net { | |
| 23 | |
| 24 class NetLog; | |
| 25 class StreamSocket; | |
| 26 | |
| 27 // A ServerSocket that uses a FuzzedDataProvider to generate the input the | |
| 28 // server receives. It succeeds in Accept()ing, asynchronously, a single | |
| 29 // connection with that input; later calls to Accept will just return | |
| 30 // ERR_IO_PENDING but will not invoke the callback. | |
| 31 class FuzzedServerSocket : public ServerSocket { | |
| 32 public: | |
| 33 // |data_provider| is used as to determine behavior of the socket. It | |
| 34 // must remain valid until after both this object and the StreamSocket | |
| 35 // produced by Accept are destroyed. | |
| 36 FuzzedServerSocket(base::FuzzedDataProvider* data_provider, | |
| 37 net::NetLog* net_log); | |
| 38 ~FuzzedServerSocket() override; | |
| 39 | |
| 40 int Listen(const IPEndPoint& address, int backlog) override; | |
| 41 int GetLocalAddress(IPEndPoint* address) const override; | |
| 42 | |
| 43 int Accept(std::unique_ptr<StreamSocket>* socket, | |
| 44 const CompletionCallback& callback) override; | |
| 45 | |
| 46 private: | |
| 47 void DispatchAccept(std::unique_ptr<StreamSocket>* socket, | |
| 48 const CompletionCallback& callback); | |
| 49 | |
| 50 base::FuzzedDataProvider* data_provider_; | |
| 51 net::NetLog* net_log_; | |
| 52 | |
| 53 IPEndPoint listening_on_; | |
| 54 bool first_accept_; | |
| 55 bool listen_called_; | |
| 56 | |
| 57 base::WeakPtrFactory<FuzzedServerSocket> weak_factory_; | |
| 58 DISALLOW_COPY_AND_ASSIGN(FuzzedServerSocket); | |
|
mmenke
2017/01/24 16:29:16
nit: Blank line before DISALLOW_COPY_AND_ASSIGN
| |
| 59 }; | |
| 60 | |
| 61 } // namespace net | |
| 62 | |
| 63 #endif // NET_SOCKET_FUZZED_SERVER_SOCKET_H_ | |
| OLD | NEW |