30 bool isBufferMovable()
noexcept override {
33 void setMovable(
bool movable) {
37 void readBufferAvailable(
42 void readDataAvailable(
size_t len)
noexcept override {
43 readBuffer_.postallocate(len);
46 void getReadBuffer(
void** bufReturn,
size_t* lenReturn)
noexcept override {
47 auto res = readBuffer_.preallocate(4000, 65000);
48 *bufReturn = res.first;
49 *lenReturn = res.second;
59 auto buf = readBuffer_.move();
61 return std::string((
char*)buf->data(), buf->length());
77 void writeSuccess()
noexcept override {
94 class AsyncPipeTest :
public Test {
96 void reset(
bool movable) {
98 readCallback_.reset();
100 writeCallback_.reset();
102 int rc =
pipe(pipeFds_);
105 EXPECT_EQ(::fcntl(pipeFds_[0], F_SETFL, O_NONBLOCK), 0);
106 EXPECT_EQ(::fcntl(pipeFds_[1], F_SETFL, O_NONBLOCK), 0);
110 readCallback_.setMovable(movable);
118 TestReadCallback readCallback_;
119 TestWriteCallback writeCallback_;
130 for (
int pass = 0; pass < 2; ++pass) {
131 reset(pass % 2 != 0);
132 reader_->setReadCB(&readCallback_);
133 writer_->write(getBuf(
"hello"), &writeCallback_);
134 writer_->closeOnEmpty();
136 EXPECT_EQ(readCallback_.getData(),
"hello");
144 for (
int pass = 0; pass < 2; ++pass) {
145 reset(pass % 2 != 0);
149 writer_->write(getBuf(
"hello"), &writeCallback_);
150 }
while (writeCallback_.writes_ == writeAttempts);
152 writer_->closeOnEmpty();
154 reader_->setReadCB(&readCallback_);
161 EXPECT_EQ(readCallback_.getData(), expected);
163 EXPECT_EQ(writeCallback_.writes_, writeAttempts);
169 for (
int pass = 0; pass < 2; ++pass) {
170 reset(pass % 2 != 0);
171 reader_->setReadCB(&readCallback_);
172 writer_->write(getBuf(
"hello"), &writeCallback_);
173 writer_->closeOnEmpty();
174 writer_->write(getBuf(
"hello"), &writeCallback_);
176 EXPECT_EQ(readCallback_.getData(),
"hello");
size_t readBuf(Buf &buf, folly::io::Cursor &cursor)
std::unique_ptr< AsyncPipeReader, folly::DelayedDestruction::Destructor > UniquePtr
static UniquePtr newReader(Args &&...args)
TEST_F(TestInfoTest, Names)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
requires E e noexcept(noexcept(s.error(std::move(e))))
std::unique_ptr< AsyncPipeWriter, folly::DelayedDestruction::Destructor > UniquePtr
static Options cacheChainLength()
#define EXPECT_TRUE(condition)
static UniquePtr newWriter(Args &&...args)
#define EXPECT_FALSE(condition)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
static constexpr uint64_t data[1]
void pipe(CPUExecutor cpu, IOExecutor io)