-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#ifndef _NET_PROXY_UTIL_STREAM_WRAPPER_H | ||
#define _NET_PROXY_UTIL_STREAM_WRAPPER_H | ||
|
||
#include <utility> | ||
|
||
#include "absl/types/span.h" | ||
#include "net/asio.h" | ||
#include "net/proxy/stream.h" | ||
|
||
namespace net { | ||
namespace proxy { | ||
|
||
class StreamWrapper { | ||
public: | ||
using executor_type = any_io_executor; | ||
using lowest_layer_type = StreamWrapper; | ||
|
||
StreamWrapper(Stream &stream, const any_io_executor &executor) | ||
: stream_(stream), executor_(executor) {} | ||
|
||
template <typename BuffersT, typename CallbackT> | ||
void async_read_some(const BuffersT &buffers, CallbackT &&callback); | ||
|
||
template <typename BuffersT, typename CallbackT> | ||
void async_write_some(const BuffersT &buffers, CallbackT &&callback); | ||
|
||
Stream &stream() { return stream_; } | ||
const any_io_executor &get_executor() { return executor_; } | ||
|
||
StreamWrapper &lowest_layer() { return *this; } | ||
const StreamWrapper &lowest_layer() const { return *this; } | ||
|
||
private: | ||
Stream &stream_; | ||
any_io_executor executor_; | ||
}; | ||
|
||
template <typename BuffersT, typename CallbackT> | ||
void StreamWrapper::async_read_some( | ||
const BuffersT &buffers, CallbackT &&callback) { | ||
stream_.read( | ||
absl::Span<mutable_buffer const>( | ||
buffer_sequence_begin(buffers), | ||
buffer_sequence_end(buffers) - buffer_sequence_begin(buffers)), | ||
std::forward<CallbackT>(callback)); | ||
} | ||
|
||
template <typename BuffersT, typename CallbackT> | ||
void StreamWrapper::async_write_some( | ||
const BuffersT &buffers, CallbackT &&callback) { | ||
stream_.write( | ||
absl::Span<const_buffer const>( | ||
buffer_sequence_begin(buffers), | ||
buffer_sequence_end(buffers) - buffer_sequence_begin(buffers)), | ||
std::forward<CallbackT>(callback)); | ||
} | ||
|
||
} // namespace proxy | ||
} // namespace net | ||
|
||
#endif // _NET_PROXY_UTIL_STREAM_WRAPPER_H |