proxygen
ZeroCopy.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 namespace folly {
20 
21 // ZeroCopyTest
23  size_t numClients,
24  int numLoops,
25  bool zeroCopy,
26  size_t bufferSize)
27  : numClients_(numClients),
28  counter_(numClients),
29  numLoops_(numLoops),
30  zeroCopy_(zeroCopy),
31  bufferSize_(bufferSize),
32  listenSock_(new folly::AsyncServerSocket(&evb_)),
33  server_(&evb_, numLoops_, bufferSize_, zeroCopy) {
34  clients_.reserve(numClients_);
35 
36  for (size_t i = 0; i < numClients_; i++) {
37  clients_.emplace_back(std::make_unique<ZeroCopyTestAsyncSocket>(
38  &counter_, &evb_, numLoops_, bufferSize_, zeroCopy));
39  }
40  if (listenSock_) {
42  }
43 }
44 
46  evb_.runInEventBaseThread([this]() {
47  if (listenSock_) {
48  listenSock_->bind(0);
49  listenSock_->setZeroCopy(zeroCopy_);
50  listenSock_->listen(10);
51  listenSock_->startAccepting();
52 
53  connectAll();
54  }
55  });
56 
57  evb_.loopForever();
58 
59  for (auto& client : clients_) {
60  if (client->isZeroCopyWriteInProgress()) {
61  return false;
62  }
63  }
64 
65  return true;
66 }
67 
68 } // namespace folly
const size_t bufferSize_
Definition: Random.cpp:104
void addCallbackToServerSocket(folly::AsyncServerSocket &sock)
Definition: ZeroCopy.h:225
ZeroCopyTestServer server_
Definition: ZeroCopy.h:277
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
EventBase * evb_
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
std::vector< std::unique_ptr< ZeroCopyTestAsyncSocket > > clients_
Definition: ZeroCopy.h:275
ZeroCopyTest(size_t numClients, int numLoops, bool zeroCopy, size_t bufferSize)
Definition: ZeroCopy.cpp:22
folly::detail::CompressionCounter * counter_
EventBase evb_
Definition: ZeroCopy.h:274
folly::AsyncServerSocket::UniquePtr listenSock_
Definition: ZeroCopy.h:276