![]() |
Bitcoin Core 31.0.0
P2P Digital Currency
|
#include <net.h>
Public Member Functions | |
| FuzzedSock (FuzzedDataProvider &fuzzed_data_provider) | |
| ~FuzzedSock () override | |
| FuzzedSock & | operator= (Sock &&other) override |
| Move assignment operator, grab the socket from another object and close ours (if set). | |
| ssize_t | Send (const void *data, size_t len, int flags) const override |
| send(2) wrapper. | |
| ssize_t | Recv (void *buf, size_t len, int flags) const override |
| recv(2) wrapper. | |
| int | Connect (const sockaddr *, socklen_t) const override |
| connect(2) wrapper. | |
| int | Bind (const sockaddr *, socklen_t) const override |
| bind(2) wrapper. | |
| int | Listen (int backlog) const override |
| listen(2) wrapper. | |
| std::unique_ptr< Sock > | Accept (sockaddr *addr, socklen_t *addr_len) const override |
| accept(2) wrapper. | |
| int | GetSockOpt (int level, int opt_name, void *opt_val, socklen_t *opt_len) const override |
| getsockopt(2) wrapper. | |
| int | SetSockOpt (int level, int opt_name, const void *opt_val, socklen_t opt_len) const override |
| setsockopt(2) wrapper. | |
| int | GetSockName (sockaddr *name, socklen_t *name_len) const override |
| getsockname(2) wrapper. | |
| bool | SetNonBlocking () const override |
| Set the non-blocking option on the socket. | |
| bool | IsSelectable () const override |
| Check if the underlying socket can be used for select(2) (or the Wait() method). | |
| bool | Wait (std::chrono::milliseconds timeout, Event requested, Event *occurred=nullptr) const override |
| Wait for readiness for input (recv) or output (send). | |
| bool | WaitMany (std::chrono::milliseconds timeout, EventsPerSock &events_per_sock) const override |
| Same as Wait(), but wait on many sockets within the same timeout. | |
| bool | IsConnected (std::string &errmsg) const override |
| Check if still connected. | |
| Public Member Functions inherited from Sock | |
| Sock ()=delete | |
| Sock (SOCKET s) | |
| Take ownership of an existent socket. | |
| Sock (const Sock &)=delete | |
| Copy constructor, disabled because closing the same socket twice is undesirable. | |
| Sock (Sock &&other) | |
| Move constructor, grab the socket from another object and close ours (if set). | |
| virtual | ~Sock () |
| Destructor, close the socket or do nothing if empty. | |
| Sock & | operator= (const Sock &)=delete |
| Copy assignment operator, disabled because closing the same socket twice is undesirable. | |
| virtual void | SendComplete (std::span< const unsigned char > data, std::chrono::milliseconds timeout, CThreadInterrupt &interrupt) const |
| Send the given data, retrying on transient errors. | |
| virtual void | SendComplete (std::span< const char > data, std::chrono::milliseconds timeout, CThreadInterrupt &interrupt) const |
| Convenience method, equivalent to SendComplete(MakeUCharSpan(data), timeout, interrupt). | |
| virtual std::string | RecvUntilTerminator (uint8_t terminator, std::chrono::milliseconds timeout, CThreadInterrupt &interrupt, size_t max_data) const |
| Read from socket until a terminator character is encountered. | |
| bool | operator== (SOCKET s) const |
| Check if the internal socket is equal to s. | |
Private Member Functions | |
| void | ElapseTime (std::chrono::milliseconds duration) const |
| Set the value of the mocked steady clock such as that many ms have passed. | |
Private Attributes | |
| FuzzedDataProvider & | m_fuzzed_data_provider |
| std::vector< uint8_t > | m_peek_data |
| Data to return when MSG_PEEK is used as a Recv() flag. | |
| const bool | m_selectable |
| Whether to pretend that the socket is select(2)-able. | |
| std::chrono::milliseconds | m_time |
| Used to mock the steady clock in methods waiting for a given duration. | |
Additional Inherited Members | |
| Public Types inherited from Sock | |
| using | Event = uint8_t |
| using | EventsPerSock = std::unordered_map<std::shared_ptr<const Sock>, Events, HashSharedPtrSock, EqualSharedPtrSock> |
| On which socket to wait for what events in WaitMany(). | |
| Static Public Attributes inherited from Sock | |
| static constexpr Event | RECV = 0b001 |
| If passed to Wait(), then it will wait for readiness to read from the socket. | |
| static constexpr Event | SEND = 0b010 |
| If passed to Wait(), then it will wait for readiness to send to the socket. | |
| static constexpr Event | ERR = 0b100 |
| Ignored if passed to Wait(), but could be set in the occurred events if an exceptional condition has occurred on the socket or if it has been disconnected. | |
| Protected Attributes inherited from Sock | |
| SOCKET | m_socket |
| Contained socket. | |
|
explicit |
|
overridevirtual |
accept(2) wrapper.
Equivalent to std::make_unique<Sock>(accept(m_socket, addr, addr_len)). Code that uses this wrapper can be unit tested if this method is overridden by a mock Sock implementation. The returned unique_ptr is empty if accept() failed in which case errno will be set.
Reimplemented from Sock.
Definition at line 305 of file net.cpp.
|
overridevirtual |
|
overridevirtual |
|
private |
|
overridevirtual |
|
overridevirtual |
getsockopt(2) wrapper.
Equivalent to getsockopt(m_socket, level, opt_name, opt_val, opt_len). Code that uses this wrapper can be unit tested if this method is overridden by a mock Sock implementation.
Reimplemented from Sock.
Definition at line 346 of file net.cpp.
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
setsockopt(2) wrapper.
Equivalent to setsockopt(m_socket, level, opt_name, opt_val, opt_len). Code that uses this wrapper can be unit tested if this method is overridden by a mock Sock implementation.
Reimplemented from Sock.
Definition at line 365 of file net.cpp.
|
overridevirtual |
Wait for readiness for input (recv) or output (send).
| [in] | timeout | Wait this much for at least one of the requested events to occur. |
| [in] | requested | Wait for those events, bitwise-or of RECV and SEND. |
| [out] | occurred | If not nullptr and the function returns true, then this indicates which of the requested events occurred (ERR will be added, even if not requested, if an exceptional event occurs on the socket). A timeout is indicated by return value of true and occurred being set to 0. |
Reimplemented from Sock.
Definition at line 414 of file net.cpp.
|
overridevirtual |
Same as Wait(), but wait on many sockets within the same timeout.
| [in] | timeout | Wait this long for at least one of the requested events to occur. |
| [in,out] | events_per_sock | Wait for the requested events on these sockets and set occurred for the events that actually occurred. |
Reimplemented from Sock.
Definition at line 435 of file net.cpp.
|
private |
|
mutableprivate |
|
private |
Whether to pretend that the socket is select(2)-able.
This is randomly set in the constructor. It should remain constant so that repeated calls to IsSelectable() return the same value.
|
mutableprivate |