Google format
This commit is contained in:
151
.clang-format
Normal file
151
.clang-format
Normal file
@@ -0,0 +1,151 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Google
|
||||
AccessModifierOffset: -1
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: true
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^<ext/.*\.h>'
|
||||
Priority: 2
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 1
|
||||
- Regex: '^<.*'
|
||||
Priority: 2
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Never
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PointerAlignment: Left
|
||||
RawStringFormats:
|
||||
- Language: Cpp
|
||||
Delimiters:
|
||||
- cc
|
||||
- CC
|
||||
- cpp
|
||||
- Cpp
|
||||
- CPP
|
||||
- 'c++'
|
||||
- 'C++'
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
- Language: TextProto
|
||||
Delimiters:
|
||||
- pb
|
||||
- PB
|
||||
- proto
|
||||
- PROTO
|
||||
EnclosingFunctions:
|
||||
- EqualsProto
|
||||
- EquivToProto
|
||||
- PARSE_PARTIAL_TEXT_PROTO
|
||||
- PARSE_TEST_PROTO
|
||||
- PARSE_TEXT_PROTO
|
||||
- ParseTextOrDie
|
||||
- ParseTextProtoOrDie
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Auto
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include <atomic>
|
||||
#include <gflags/gflags.h>
|
||||
#include <glog/logging.h>
|
||||
#include <sys/time.h>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#include "server.h"
|
||||
|
||||
DEFINE_int32(port, 9000, "TCP port to bind");
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[]) {
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
|
||||
2
firecgi
2
firecgi
Submodule firecgi updated: a39ef8e25d...f9988beb88
4
index.cc
4
index.cc
@@ -47,7 +47,9 @@ void Index::Freshen(Stream* stream) {
|
||||
Add(stream);
|
||||
}
|
||||
|
||||
std::chrono::nanoseconds Index::WithStalest(std::function<void(Stream*)> callback, const std::chrono::nanoseconds& min_stale) {
|
||||
std::chrono::nanoseconds Index::WithStalest(
|
||||
std::function<void(Stream*)> callback,
|
||||
const std::chrono::nanoseconds& min_stale) {
|
||||
Stream* stalest = nullptr;
|
||||
std::chrono::nanoseconds ret;
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
|
||||
4
index.h
4
index.h
@@ -19,7 +19,9 @@ class Index {
|
||||
// Returns time to sleep until next stalest, or min_stale if none
|
||||
// Only calls callback if stalest is at least min_stale
|
||||
// Handles all locking and marks Stream as fresh after callback
|
||||
std::chrono::nanoseconds WithStalest(std::function<void(Stream*)> callback, const std::chrono::nanoseconds& min_stale);
|
||||
std::chrono::nanoseconds WithStalest(
|
||||
std::function<void(Stream*)> callback,
|
||||
const std::chrono::nanoseconds& min_stale);
|
||||
|
||||
private:
|
||||
std::recursive_mutex mu_;
|
||||
|
||||
16
keepalive.cc
16
keepalive.cc
@@ -6,15 +6,11 @@
|
||||
namespace firesse {
|
||||
|
||||
KeepAlive::KeepAlive(const std::chrono::nanoseconds& max_stale, Index* index)
|
||||
: max_stale_(max_stale),
|
||||
index_(index),
|
||||
shutdown_fd_(eventfd(0, 0)) {
|
||||
: max_stale_(max_stale), index_(index), shutdown_fd_(eventfd(0, 0)) {
|
||||
PCHECK(shutdown_fd_ >= 0) << "eventfd()";
|
||||
}
|
||||
|
||||
KeepAlive::~KeepAlive() {
|
||||
PCHECK(close(shutdown_fd_) == 0);
|
||||
}
|
||||
KeepAlive::~KeepAlive() { PCHECK(close(shutdown_fd_) == 0); }
|
||||
|
||||
void KeepAlive::Start() {
|
||||
thread_ = std::thread([this]() {
|
||||
@@ -27,10 +23,10 @@ void KeepAlive::Start() {
|
||||
},
|
||||
};
|
||||
while (running_ && (timeout == 0 || poll(fds, num_fds, timeout) <= 0)) {
|
||||
auto sleep = index_->WithStalest([](Stream* stream) {
|
||||
stream->WriteRaw(":\n");
|
||||
}, max_stale_);
|
||||
timeout = std::chrono::duration_cast<std::chrono::milliseconds>(sleep).count();
|
||||
auto sleep = index_->WithStalest(
|
||||
[](Stream* stream) { stream->WriteRaw(":\n"); }, max_stale_);
|
||||
timeout =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(sleep).count();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@ namespace firesse {
|
||||
Server::Server(int port, const std::function<void(Stream*)>& callback)
|
||||
: callback_(callback),
|
||||
keep_alive_(std::chrono::seconds(15), &index_),
|
||||
firecgi_server_(port,
|
||||
[this](firecgi::Request* request) { OnRequest(request); },
|
||||
1) {}
|
||||
firecgi_server_(
|
||||
port, [this](firecgi::Request* request) { OnRequest(request); }, 1) {}
|
||||
|
||||
void Server::Serve() {
|
||||
keep_alive_.Start();
|
||||
@@ -15,9 +14,7 @@ void Server::Serve() {
|
||||
keep_alive_.Stop();
|
||||
}
|
||||
|
||||
void Server::Shutdown() {
|
||||
firecgi_server_.Shutdown();
|
||||
}
|
||||
void Server::Shutdown() { firecgi_server_.Shutdown(); }
|
||||
|
||||
void Server::RegisterSignalHandlers() {
|
||||
firecgi_server_.RegisterSignalHandlers();
|
||||
|
||||
10
stream.cc
10
stream.cc
@@ -5,8 +5,7 @@
|
||||
namespace firesse {
|
||||
|
||||
Stream::Stream(firecgi::Request* request, Index* index)
|
||||
: request_(request),
|
||||
index_(index) {
|
||||
: request_(request), index_(index) {
|
||||
index_->Add(this);
|
||||
}
|
||||
|
||||
@@ -19,7 +18,8 @@ void Stream::OnClose(const std::function<void()>& callback) {
|
||||
on_close_ = callback;
|
||||
}
|
||||
|
||||
bool Stream::WriteEvent(const std::string_view& data, uint64_t id, const std::string& type) {
|
||||
bool Stream::WriteEvent(const std::string_view& data, uint64_t id,
|
||||
const std::string& type) {
|
||||
std::lock_guard l(mu_);
|
||||
|
||||
index_->Freshen(this);
|
||||
@@ -43,9 +43,7 @@ bool Stream::WriteRaw(const std::string_view& data) {
|
||||
return request_->Flush();
|
||||
}
|
||||
|
||||
bool Stream::End() {
|
||||
return request_->End();
|
||||
}
|
||||
bool Stream::End() { return request_->End(); }
|
||||
|
||||
void Stream::Close() {
|
||||
if (on_close_) {
|
||||
|
||||
3
stream.h
3
stream.h
@@ -15,7 +15,8 @@ class Stream {
|
||||
|
||||
void OnClose(const std::function<void()>& callback);
|
||||
|
||||
bool WriteEvent(const std::string_view& data, uint64_t id=0, const std::string& type="");
|
||||
bool WriteEvent(const std::string_view& data, uint64_t id = 0,
|
||||
const std::string& type = "");
|
||||
bool WriteRaw(const std::string_view& data);
|
||||
bool End();
|
||||
void Close();
|
||||
|
||||
Reference in New Issue
Block a user