Skip to content

Commit 97c8507

Browse files
authored
Merge pull request #27 from an-tao/dev
Add .clang-format
2 parents 910a4f9 + 656808e commit 97c8507

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2725
-2009
lines changed

.clang-format

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: Google
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: Left
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllParametersOfDeclarationOnNextLine: false
12+
AllowShortBlocksOnASingleLine: false
13+
AllowShortCaseLabelsOnASingleLine: false
14+
AllowShortFunctionsOnASingleLine: None
15+
AllowShortIfStatementsOnASingleLine: false
16+
AllowShortLoopsOnASingleLine: false
17+
AlwaysBreakAfterDefinitionReturnType: None
18+
AlwaysBreakAfterReturnType: None
19+
AlwaysBreakBeforeMultilineStrings: true
20+
AlwaysBreakTemplateDeclarations: Yes
21+
BinPackArguments: false
22+
BinPackParameters: false
23+
BraceWrapping:
24+
AfterClass: false
25+
AfterControlStatement: false
26+
AfterEnum: false
27+
AfterFunction: false
28+
AfterNamespace: false
29+
AfterObjCDeclaration: false
30+
AfterStruct: false
31+
AfterUnion: false
32+
AfterExternBlock: false
33+
BeforeCatch: false
34+
BeforeElse: false
35+
IndentBraces: false
36+
SplitEmptyFunction: true
37+
SplitEmptyRecord: true
38+
SplitEmptyNamespace: true
39+
BreakBeforeBinaryOperators: None
40+
BreakBeforeBraces: Allman
41+
BreakBeforeInheritanceComma: false
42+
BreakInheritanceList: BeforeColon
43+
BreakBeforeTernaryOperators: true
44+
BreakConstructorInitializersBeforeComma: false
45+
BreakConstructorInitializers: BeforeColon
46+
BreakAfterJavaFieldAnnotations: false
47+
BreakStringLiterals: true
48+
ColumnLimit: 80
49+
CommentPragmas: '^ IWYU pragma:'
50+
CompactNamespaces: false
51+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
52+
ConstructorInitializerIndentWidth: 4
53+
ContinuationIndentWidth: 4
54+
Cpp11BracedListStyle: true
55+
DerivePointerAlignment: true
56+
DisableFormat: false
57+
FixNamespaceComments: true
58+
ForEachMacros:
59+
- foreach
60+
- Q_FOREACH
61+
- BOOST_FOREACH
62+
IncludeBlocks: Preserve
63+
IncludeCategories:
64+
- Regex: '^<ext/.*\.h>'
65+
Priority: 2
66+
- Regex: '^<.*\.h>'
67+
Priority: 1
68+
- Regex: '^<.*'
69+
Priority: 2
70+
- Regex: '.*'
71+
Priority: 3
72+
IncludeIsMainRegex: '([-_](test|unittest))?$'
73+
IndentCaseLabels: true
74+
IndentPPDirectives: None
75+
IndentWidth: 4
76+
IndentWrappedFunctionNames: false
77+
JavaScriptQuotes: Leave
78+
JavaScriptWrapImports: true
79+
KeepEmptyLinesAtTheStartOfBlocks: false
80+
MacroBlockBegin: ''
81+
MacroBlockEnd: ''
82+
MaxEmptyLinesToKeep: 1
83+
NamespaceIndentation: None
84+
ObjCBinPackProtocolList: Never
85+
ObjCBlockIndentWidth: 2
86+
ObjCSpaceAfterProperty: false
87+
ObjCSpaceBeforeProtocolList: true
88+
PenaltyBreakAssignment: 2
89+
PenaltyBreakBeforeFirstCallParameter: 10000
90+
PenaltyBreakComment: 300
91+
PenaltyBreakFirstLessLess: 120
92+
PenaltyBreakString: 1000
93+
PenaltyBreakTemplateDeclaration: 10
94+
PenaltyExcessCharacter: 10000
95+
PenaltyReturnTypeOnItsOwnLine: 200
96+
PointerAlignment: Left
97+
RawStringFormats:
98+
- Language: Cpp
99+
Delimiters:
100+
- cc
101+
- CC
102+
- cpp
103+
- Cpp
104+
- CPP
105+
- 'c++'
106+
- 'C++'
107+
CanonicalDelimiter: ''
108+
BasedOnStyle: google
109+
- Language: TextProto
110+
Delimiters:
111+
- pb
112+
- PB
113+
- proto
114+
- PROTO
115+
EnclosingFunctions:
116+
- EqualsProto
117+
- EquivToProto
118+
- PARSE_PARTIAL_TEXT_PROTO
119+
- PARSE_TEST_PROTO
120+
- PARSE_TEXT_PROTO
121+
- ParseTextOrDie
122+
- ParseTextProtoOrDie
123+
CanonicalDelimiter: ''
124+
BasedOnStyle: google
125+
ReflowComments: true
126+
SortIncludes: false
127+
SortUsingDeclarations: true
128+
SpaceAfterCStyleCast: false
129+
SpaceAfterTemplateKeyword: true
130+
SpaceBeforeAssignmentOperators: true
131+
SpaceBeforeCpp11BracedList: false
132+
SpaceBeforeCtorInitializerColon: true
133+
SpaceBeforeInheritanceColon: true
134+
SpaceBeforeParens: ControlStatements
135+
SpaceBeforeRangeBasedForLoopColon: true
136+
SpaceInEmptyParentheses: false
137+
SpacesBeforeTrailingComments: 2
138+
SpacesInAngles: false
139+
SpacesInContainerLiterals: true
140+
SpacesInCStyleCastParentheses: false
141+
SpacesInParentheses: false
142+
SpacesInSquareBrackets: false
143+
Standard: Auto
144+
StatementMacros:
145+
- Q_UNUSED
146+
- QT_REQUIRE_VERSION
147+
TabWidth: 8
148+
UseTab: Never
149+
...
150+

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
os:
22
- linux
33
- osx
4+
5+
osx_image: xcode10.1
6+
47
sudo: required
5-
dist: trusty
8+
9+
dist: xenial
610

711
language: cpp
8-
compiler:
9-
- gcc
10-
- clang
1112

1213
addons:
1314
apt:

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# TRANTOR
22

33
[![Build Status](https://travis-ci.org/an-tao/trantor.svg?branch=master)](https://travis-ci.org/an-tao/trantor)
4-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4bcc94325ba64c40b2172a0d44fd9406)](https://app.codacy.com/app/an-tao/trantor?utm_source=github.com&utm_medium=referral&utm_content=an-tao/trantor&utm_campaign=Badge_Grade_Dashboard)
54
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/an-tao/trantor.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/an-tao/trantor/context:cpp)
65

76
A non-blocking I/O TCP network library, using C++14/17,

build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,22 @@ function build_trantor() {
2525

2626
#If errors then exit
2727
if [ "$?" != "0" ]; then
28-
exit
28+
exit -1
2929
fi
3030

3131
make
3232

3333
#If errors then exit
3434
if [ "$?" != "0" ]; then
35-
exit
35+
exit -1
3636
fi
3737

3838
echo "Installing ..."
3939
sudo make install
4040

4141
#Reback current directory
4242
cd $current_dir
43+
exit 0
4344
#Ok!
4445
}
4546

format.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
clang-format --version
4+
find trantor -name *.h -o -name *.cc|xargs clang-format -i -style=file

trantor/net/EventLoop.cc

100755100644
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ EventLoop::EventLoop()
7777
assert(!r);
7878
fcntl(_wakeupFd[0], F_SETFL, O_NONBLOCK | O_CLOEXEC);
7979
fcntl(_wakeupFd[1], F_SETFL, O_NONBLOCK | O_CLOEXEC);
80-
_wakeupChannelPtr = std::unique_ptr<Channel>(new Channel(this, _wakeupFd[0]));
80+
_wakeupChannelPtr =
81+
std::unique_ptr<Channel>(new Channel(this, _wakeupFd[0]));
8182

8283
#endif
83-
_wakeupChannelPtr->setReadCallback(
84-
std::bind(&EventLoop::wakeupRead, this));
84+
_wakeupChannelPtr->setReadCallback(std::bind(&EventLoop::wakeupRead, this));
8585
_wakeupChannelPtr->enableReading();
8686
}
8787
#ifdef __linux__
@@ -124,7 +124,9 @@ void EventLoop::removeChannel(Channel *channel)
124124
if (_eventHandling)
125125
{
126126
assert(_currentActiveChannel == channel ||
127-
std::find(_activeChannels.begin(), _activeChannels.end(), channel) == _activeChannels.end());
127+
std::find(_activeChannels.begin(),
128+
_activeChannels.end(),
129+
channel) == _activeChannels.end());
128130
}
129131
_poller->removeChannel(channel);
130132
}
@@ -156,24 +158,25 @@ void EventLoop::loop()
156158
_timerQueue->processTimers();
157159
#endif
158160
// TODO sort channel by priority
159-
//std::cout<<"after ->poll()"<<std::endl;
161+
// std::cout<<"after ->poll()"<<std::endl;
160162
_eventHandling = true;
161-
for (auto it = _activeChannels.begin();
162-
it != _activeChannels.end(); ++it)
163+
for (auto it = _activeChannels.begin(); it != _activeChannels.end();
164+
++it)
163165
{
164166
_currentActiveChannel = *it;
165167
_currentActiveChannel->handleEvent();
166168
}
167169
_currentActiveChannel = NULL;
168170
_eventHandling = false;
169-
//std::cout << "looping" << endl;
171+
// std::cout << "looping" << endl;
170172
doRunInLoopFuncs();
171173
}
172174
_looping = false;
173175
}
174176
void EventLoop::abortNotInLoopThread()
175177
{
176-
LOG_FATAL << "It is forbidden to run loop on threads other than event-loop thread";
178+
LOG_FATAL << "It is forbidden to run loop on threads other than event-loop "
179+
"thread";
177180
exit(-1);
178181
}
179182
void EventLoop::runInLoop(const Func &cb)
@@ -237,7 +240,9 @@ TimerId EventLoop::runEvery(double interval, const Func &cb)
237240
}
238241
TimerId EventLoop::runEvery(double interval, Func &&cb)
239242
{
240-
return _timerQueue->addTimer(std::move(cb), Date::date().after(interval), interval);
243+
return _timerQueue->addTimer(std::move(cb),
244+
Date::date().after(interval),
245+
interval);
241246
}
242247
void EventLoop::invalidateTimer(TimerId id)
243248
{
@@ -268,7 +273,7 @@ void EventLoop::wakeup()
268273
#endif
269274
if (ret < 0)
270275
{
271-
//LOG_SYSERR << "wakeup error";
276+
// LOG_SYSERR << "wakeup error";
272277
}
273278
}
274279
void EventLoop::wakeupRead()
@@ -283,4 +288,4 @@ void EventLoop::wakeupRead()
283288
if (ret < 0)
284289
LOG_SYSERR << "wakeup read error";
285290
}
286-
} // namespace trantor
291+
} // namespace trantor

trantor/net/EventLoop.h

100755100644
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
namespace trantor
3131
{
32-
3332
class Poller;
3433
class TimerQueue;
3534
class Channel;
@@ -43,7 +42,7 @@ enum
4342

4443
class EventLoop : NonCopyable
4544
{
46-
public:
45+
public:
4746
EventLoop();
4847
~EventLoop();
4948
void loop();
@@ -75,8 +74,8 @@ class EventLoop : NonCopyable
7574
// template <typename T>
7675
// const std::shared_ptr<ObjectPool<T>> &getObjectPool()
7776
// {
78-
// static std::shared_ptr<ObjectPool<T>> pool=std::make_shared<ObjectPool<T>>();
79-
// return pool;
77+
// static std::shared_ptr<ObjectPool<T>>
78+
// pool=std::make_shared<ObjectPool<T>>(); return pool;
8079
// }
8180
///
8281
/// Runs callback at 'time'.
@@ -95,10 +94,11 @@ class EventLoop : NonCopyable
9594
/**
9695
* Users could use chrono literals to represent a time duration
9796
* For example:
98-
* runAfter(5s, task);
99-
* runAfter(10min, task);
97+
* runAfter(5s, task);
98+
* runAfter(10min, task);
10099
*/
101-
TimerId runAfter(const std::chrono::duration<long double> &delay, const Func &cb)
100+
TimerId runAfter(const std::chrono::duration<long double> &delay,
101+
const Func &cb)
102102
{
103103
return runAfter(delay.count(), cb);
104104
}
@@ -117,26 +117,34 @@ class EventLoop : NonCopyable
117117
/**
118118
* Users could use chrono literals to represent a time duration
119119
* For example:
120-
* runEvery(5s, task);
121-
* runEvery(10min, task);
120+
* runEvery(5s, task);
121+
* runEvery(10min, task);
122122
* runEvery(0.1h, task);
123123
*/
124-
TimerId runEvery(const std::chrono::duration<long double> &interval, const Func &cb)
124+
TimerId runEvery(const std::chrono::duration<long double> &interval,
125+
const Func &cb)
125126
{
126127
return runEvery(interval.count(), cb);
127128
}
128-
TimerId runEvery(const std::chrono::duration<long double> &interval, Func &&cb)
129+
TimerId runEvery(const std::chrono::duration<long double> &interval,
130+
Func &&cb)
129131
{
130132
return runEvery(interval.count(), std::move(cb));
131133
}
132-
//int getAioEventFd();
133-
//io_context_t getAioContext() {return ctx_;};
134+
// int getAioEventFd();
135+
// io_context_t getAioContext() {return ctx_;};
134136
void invalidateTimer(TimerId id);
135137

136-
bool isRunning() { return _looping && (!_quit); }
137-
bool isCallingFunctions() { return _callingFuncs; }
138+
bool isRunning()
139+
{
140+
return _looping && (!_quit);
141+
}
142+
bool isCallingFunctions()
143+
{
144+
return _callingFuncs;
145+
}
138146

139-
private:
147+
private:
140148
void abortNotInLoopThread();
141149
bool _looping;
142150
const std::thread::id _threadId;
@@ -148,7 +156,7 @@ class EventLoop : NonCopyable
148156

149157
bool _eventHandling;
150158

151-
//std::mutex _funcsMutex;
159+
// std::mutex _funcsMutex;
152160

153161
MpscQueue<Func> _funcs;
154162
std::unique_ptr<TimerQueue> _timerQueue;
@@ -163,4 +171,4 @@ class EventLoop : NonCopyable
163171
void doRunInLoopFuncs();
164172
};
165173

166-
} // namespace trantor
174+
} // namespace trantor

0 commit comments

Comments
 (0)