21 #ifdef SPLICE_F_NONBLOCK 22 using namespace folly;
26 struct FileRegionTest :
public Test {
30 socket->connect(&ccb, server.getAddress(), 30);
33 acceptedSocket = server.acceptAsync(&evb);
34 acceptedSocket->setReadCB(&rcb);
37 char path[] =
"/tmp/AsyncSocketTest.WriteFile.XXXXXX";
38 fd = mkostemp(path, O_RDWR);
43 ~FileRegionTest()
override {
46 acceptedSocket->close();
52 std::shared_ptr<AsyncSocket>
socket;
53 std::shared_ptr<AsyncSocket> acceptedSocket;
59 TEST_F(FileRegionTest, Basic) {
60 const size_t count = 1000000000;
61 std::unique_ptr<uint8_t[]> zeroBuf = std::make_unique<uint8_t[]>(
count);
64 FileRegion fileRegion(fd, 0, count);
65 auto f = fileRegion.transferTo(
socket);
68 }
catch (std::exception& e) {
74 evb.loopIgnoreKeepAlive();
78 size_t receivedBytes = 0;
79 for (
auto& buf : rcb.buffers) {
80 receivedBytes += buf.length;
81 ASSERT_EQ(memcmp(buf.buffer, zeroBuf.get(), buf.length), 0);
86 TEST_F(FileRegionTest, Repeated) {
87 const size_t count = 1000000;
88 std::unique_ptr<uint8_t[]> zeroBuf = std::make_unique<uint8_t[]>(
count);
93 FileRegion fileRegion(fd, 0, count);
94 std::vector<Future<Unit>> fs;
95 for (
int i = 0;
i < sendCount;
i++) {
96 fs.push_back(fileRegion.transferTo(
socket));
103 evb.loopIgnoreKeepAlive();
107 size_t receivedBytes = 0;
108 for (
auto& buf : rcb.buffers) {
109 receivedBytes += buf.length;
111 ASSERT_EQ(receivedBytes, sendCount*count);
void write(const T &in, folly::io::Appender &appender)
#define ASSERT_EQ(val1, val2)
#define EXPECT_EQ(val1, val2)
fbstring exceptionStr(const std::exception &e)
—— Concurrent Priority Queue Implementation ——
NetworkSocket socket(int af, int type, int protocol)
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
#define EXPECT_TRUE(condition)
static std::shared_ptr< AsyncSocket > newSocket(EventBase *evb)
Future< std::vector< typename std::iterator_traits< InputIterator >::value_type::value_type > > collect(InputIterator first, InputIterator last)
#define ASSERT_NO_THROW(statement)
int close(NetworkSocket s)