Skip to content

Commit 1b19d11

Browse files
committed
sock: change Sock::SendComplete() to take Span
This would make it easier to pass other than `std::string` types, to be used in the `Socks5()` function.
1 parent 73dfa6d commit 1b19d11

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/util/sock.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ bool Sock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per
242242
#endif /* USE_POLL */
243243
}
244244

245-
void Sock::SendComplete(const std::string& data,
245+
void Sock::SendComplete(Span<const unsigned char> data,
246246
std::chrono::milliseconds timeout,
247247
CThreadInterrupt& interrupt) const
248248
{
@@ -283,6 +283,13 @@ void Sock::SendComplete(const std::string& data,
283283
}
284284
}
285285

286+
void Sock::SendComplete(Span<const char> data,
287+
std::chrono::milliseconds timeout,
288+
CThreadInterrupt& interrupt) const
289+
{
290+
SendComplete(MakeUCharSpan(data), timeout, interrupt);
291+
}
292+
286293
std::string Sock::RecvUntilTerminator(uint8_t terminator,
287294
std::chrono::milliseconds timeout,
288295
CThreadInterrupt& interrupt,

src/util/sock.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,14 @@ class Sock
228228
* @throws std::runtime_error if the operation cannot be completed. In this case only some of
229229
* the data will be written to the socket.
230230
*/
231-
virtual void SendComplete(const std::string& data,
231+
virtual void SendComplete(Span<const unsigned char> data,
232+
std::chrono::milliseconds timeout,
233+
CThreadInterrupt& interrupt) const;
234+
235+
/**
236+
* Convenience method, equivalent to `SendComplete(MakeUCharSpan(data), timeout, interrupt)`.
237+
*/
238+
virtual void SendComplete(Span<const char> data,
232239
std::chrono::milliseconds timeout,
233240
CThreadInterrupt& interrupt) const;
234241

0 commit comments

Comments
 (0)