Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251* Read from socket until a terminator character is encountered. Will never consume bytes past252* the terminator from the socket.253* @param[in] terminator Character up to which to read from the socket.254* @param[in] timeout Timeout for the entire operation.255* @param[in] interrupt If this is signaled then the operation is canceled.256* @param[in] max_data The maximum amount of data (in bytes) to receive. If this many bytes257* are received and there is still no terminator, then this method will throw an exception.258* @return The data that has been read, without the terminating character.259* @throws std::runtime_error if the operation cannot be completed. In this case some bytes may260* have been consumed from the socket.261*/262[[nodiscard]] virtual std::string RecvUntilTerminator(uint8_t terminator,263std::chrono::milliseconds timeout,264CThreadInterrupt& interrupt,265size_t max_data) const;267/**268* Check if still connected.269* @param[out] errmsg The error string, if the socket has been disconnected.270* @return true if connected271*/272[[nodiscard]] virtual bool IsConnected(std::string& errmsg) const;274/**275* Check if the internal socket is equal to `s`. Use only in tests.276*/277bool operator==(SOCKET s) const;279protected:280/**281* Contained socket. `INVALID_SOCKET` designates the object is empty.282*/283SOCKET m_socket;285private:286/**287* Close `m_socket` if it is not `INVALID_SOCKET`.288*/289void Close();290};292/** Return readable error string for a network error code */293std::string NetworkErrorString(int err);295#endif // BITCOIN_UTIL_SOCK_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.