Skip to content

Commit

Permalink
sock: change Sock::SendComplete() to take Span
Browse files Browse the repository at this point in the history
This would make it easier to pass other than `std::string` types,
to be used in the `Socks5()` function.

Github-Pull: bitcoin#28649
Rebased-From: 1b19d11
  • Loading branch information
vasild authored and luke-jr committed Apr 24, 2024
1 parent 96ec3b6 commit 8ad7de4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/util/sock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ bool Sock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per
#endif /* USE_POLL */
}

void Sock::SendComplete(const std::string& data,
void Sock::SendComplete(Span<const unsigned char> data,
std::chrono::milliseconds timeout,
CThreadInterrupt& interrupt) const
{
Expand Down Expand Up @@ -283,6 +283,13 @@ void Sock::SendComplete(const std::string& data,
}
}

void Sock::SendComplete(Span<const char> data,
std::chrono::milliseconds timeout,
CThreadInterrupt& interrupt) const
{
SendComplete(MakeUCharSpan(data), timeout, interrupt);
}

std::string Sock::RecvUntilTerminator(uint8_t terminator,
std::chrono::milliseconds timeout,
CThreadInterrupt& interrupt,
Expand Down
9 changes: 8 additions & 1 deletion src/util/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,14 @@ class Sock
* @throws std::runtime_error if the operation cannot be completed. In this case only some of
* the data will be written to the socket.
*/
virtual void SendComplete(const std::string& data,
virtual void SendComplete(Span<const unsigned char> data,
std::chrono::milliseconds timeout,
CThreadInterrupt& interrupt) const;

/**
* Convenience method, equivalent to `SendComplete(MakeUCharSpan(data), timeout, interrupt)`.
*/
virtual void SendComplete(Span<const char> data,
std::chrono::milliseconds timeout,
CThreadInterrupt& interrupt) const;

Expand Down

0 comments on commit 8ad7de4

Please sign in to comment.