Create a valid Socket for use in fuzz harnesses that need a non-NULL Socket*. Returns a raw Socket* that remains valid for the lifetime of the process (held by the static SocketUniquePtr).
| 25 | // Returns a raw Socket* that remains valid for the lifetime of the process |
| 26 | // (held by the static SocketUniquePtr). |
| 27 | inline brpc::Socket* get_fuzz_socket() { |
| 28 | static brpc::SocketId sid = 0; |
| 29 | static brpc::SocketUniquePtr sock_ptr; |
| 30 | static bool initialized = false; |
| 31 | |
| 32 | if (!initialized) { |
| 33 | brpc::SocketOptions options; |
| 34 | options.remote_side = butil::EndPoint(butil::IP_ANY, 7777); |
| 35 | if (brpc::Socket::Create(options, &sid) == 0) { |
| 36 | brpc::Socket::Address(sid, &sock_ptr); |
| 37 | } |
| 38 | initialized = true; |
| 39 | } |
| 40 | |
| 41 | return sock_ptr.get(); |
| 42 | } |
| 43 | |
| 44 | #endif // BRPC_TEST_FUZZING_FUZZ_COMMON_H |
no test coverage detected