proxygen
LogStream.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  */
17 
18 namespace folly {
19 
20 LogStreamBuffer::int_type LogStreamBuffer::overflow(int_type ch) {
21  auto currentSize = str_.size();
22  size_t newSize;
23  if (currentSize == 0) {
24  newSize = kInitialCapacity;
25  } else {
26  // Increase by 1.25 each time
27  newSize = currentSize + (currentSize >> 2);
28  }
29 
30  try {
31  str_.resize(newSize);
32 
33  if (ch == EOF) {
34  setp((&str_.front()) + currentSize, (&str_.front()) + newSize);
35  return 'x';
36  } else {
37  str_[currentSize] = static_cast<char>(ch);
38  setp((&str_.front()) + currentSize + 1, (&str_.front()) + newSize);
39  return ch;
40  }
41  } catch (const std::exception&) {
42  // Return EOF to indicate that the operation failed.
43  // In general the only exception we really expect to see here is
44  // std::bad_alloc() from the str_.resize() call.
45  return EOF;
46  }
47 }
48 
50  : std::ostream(nullptr), processor_{processor} {
51  rdbuf(&buffer_);
52 }
53 
55 } // namespace folly
std::string str_
Definition: LogStream.h:49
STL namespace.
int_type overflow(int_type ch) override
Definition: LogStream.cpp:20
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
#define nullptr
Definition: http_parser.c:41
LogStream(LogStreamProcessor *processor)
Definition: LogStream.cpp:49
auto ch
LogStreamBuffer buffer_
Definition: LogStream.h:83