-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove origin TcpBufReader/TcpBufWriter
- Loading branch information
Showing
4 changed files
with
18 additions
and
92 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#pragma once | ||
|
||
#include "uvio/net/tcp_listener.hpp" | ||
#include "uvio/net/tcp_reader.hpp" | ||
#include "uvio/net/tcp_stream.hpp" | ||
#include "uvio/net/tcp_writer.hpp" |
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 |
---|---|---|
@@ -1,46 +1,12 @@ | ||
#pragma once | ||
|
||
#include "uvio/io/buffer.hpp" | ||
#include "uvio/io/impl/buf_reader.hpp" | ||
#include "uvio/io/reader.hpp" | ||
#include "uvio/io/split.hpp" | ||
#include "uvio/net/tcp_stream.hpp" | ||
|
||
namespace uvio::io { | ||
namespace uvio::net { | ||
|
||
template <typename IO, int RBUF_SIZE> | ||
requires requires(IO io, std::span<char> buf) { | ||
{ io.read(buf) }; | ||
} | ||
// class TcpBufReader : public detail::ImplBufRead<IO> { // wrong | ||
class TcpBufReader : public detail::ImplBufRead<TcpBufReader<IO, RBUF_SIZE>> { | ||
friend class detail::ImplBufRead<TcpBufReader>; | ||
template <int RBUF_SIZE> | ||
using TcpReader = io::BufReader<io::OwnedReadHalf<TcpStream>, RBUF_SIZE>; | ||
|
||
public: | ||
TcpBufReader(IO &&io) | ||
: io_{std::move(io)} {} | ||
|
||
TcpBufReader(TcpBufReader &&other) noexcept | ||
: io_{std::move(other.io_)} | ||
, r_stream_{std::move(other.r_stream_)} {} | ||
|
||
auto operator=(TcpBufReader &&other) noexcept -> TcpBufReader & { | ||
if (std::addressof(other) != this) { | ||
io_ = std::move(other.io_); | ||
r_stream_ = std::move(other.r_stream_); | ||
} | ||
return *this; | ||
} | ||
|
||
public: | ||
auto inner() noexcept -> IO & { | ||
return io_; | ||
} | ||
|
||
auto into_inner() noexcept -> IO { | ||
r_stream_.disable(); | ||
return std::move(io_); | ||
} | ||
|
||
private: | ||
IO io_; | ||
detail::StreamBuffer<RBUF_SIZE> r_stream_; | ||
}; | ||
} // namespace uvio::io | ||
} // namespace uvio::net |
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 |
---|---|---|
@@ -1,48 +1,11 @@ | ||
#pragma once | ||
#include "uvio/io/split.hpp" | ||
#include "uvio/io/writer.hpp" | ||
#include "uvio/net/tcp_stream.hpp" | ||
|
||
#include "uvio/io/buffer.hpp" | ||
#include "uvio/io/impl/buf_writer.hpp" | ||
namespace uvio::net { | ||
|
||
namespace uvio::io { | ||
template <int WBUF_SIZE> | ||
using TcpWriter = io::BufWriter<io::OwnedWriteHalf<TcpStream>, WBUF_SIZE>; | ||
|
||
template <class IO, int WBUF_SIZE> | ||
requires requires(IO io, std::span<const char> buf) { | ||
{ io.write(buf) }; | ||
} | ||
class TcpBufWriter : public detail::ImplBufWrite<TcpBufWriter<IO, WBUF_SIZE>> { | ||
friend class detail::ImplBufWrite<TcpBufWriter<IO, WBUF_SIZE>>; | ||
|
||
public: | ||
TcpBufWriter(IO &&io) | ||
: io_{std::move(io)} {} | ||
|
||
TcpBufWriter(TcpBufWriter &&other) noexcept | ||
: io_{std::move(other.io_)} | ||
, w_stream_{std::move(other.w_stream_)} {} | ||
|
||
auto operator=(TcpBufWriter &&other) noexcept -> TcpBufWriter & { | ||
if (std::addressof(other) != this) { | ||
io_ = std::move(other.io_); | ||
w_stream_ = std::move(other.w_stream_); | ||
} | ||
return *this; | ||
} | ||
|
||
public: | ||
[[nodiscard]] | ||
auto inner() noexcept -> IO & { | ||
return io_; | ||
} | ||
|
||
[[nodiscard]] | ||
auto into_inner() noexcept -> IO { | ||
w_stream_.disable(); | ||
return std::move(io_); | ||
} | ||
|
||
private: | ||
IO io_; | ||
detail::StreamBuffer<WBUF_SIZE> w_stream_; | ||
}; | ||
|
||
} // namespace uvio::io | ||
} // namespace uvio::net |