Skip to content

Commit ac76712

Browse files
authored
Modify some code styles (#59)
1 parent 828e46f commit ac76712

File tree

6 files changed

+67
-67
lines changed

6 files changed

+67
-67
lines changed

trantor/net/inner/NormalResolver.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ void NormalResolver::resolve(const std::string &hostname,
6666
if (ret == 0 && he != NULL)
6767
#else
6868
/// Multi-threads safety
69-
static std::mutex _mutex;
69+
static std::mutex mutex_;
7070
struct hostent *he = NULL;
7171
struct hostent hent;
7272
{
73-
std::lock_guard<std::mutex> guard(_mutex);
73+
std::lock_guard<std::mutex> guard(mutex_);
7474
auto result = gethostbyname(hostname.c_str());
7575
if (result != NULL)
7676
{

trantor/net/inner/NormalResolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace trantor
1616
{
17-
constexpr size_t kResolveBufferLength {16 * 1024};
17+
constexpr size_t kResolveBufferLength{16 * 1024};
1818
class NormalResolver : public Resolver,
1919
public NonCopyable,
2020
public std::enable_shared_from_this<NormalResolver>

trantor/net/inner/TimerQueue.cc

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ void readTimerfd(int timerfd, const Date &now)
7777

7878
void TimerQueue::handleRead()
7979
{
80-
_loop->assertInLoopThread();
80+
loop_->assertInLoopThread();
8181
const Date now = Date::date();
82-
readTimerfd(_timerfd, now);
82+
readTimerfd(timerfd_, now);
8383

8484
std::vector<TimerPtr> expired = getExpired(now);
8585

86-
_callingExpiredTimers = true;
86+
callingExpiredTimers_ = true;
8787
// cancelingTimers_.clear();
8888
// safe to callback outside critical section
8989
for (auto const &timerPtr : expired)
@@ -93,7 +93,7 @@ void TimerQueue::handleRead()
9393
timerPtr->run();
9494
}
9595
}
96-
_callingExpiredTimers = false;
96+
callingExpiredTimers_ = false;
9797

9898
reset(expired, now);
9999
}
@@ -110,12 +110,12 @@ int howMuchTimeFromNow(const Date &when)
110110
}
111111
void TimerQueue::processTimers()
112112
{
113-
_loop->assertInLoopThread();
113+
loop_->assertInLoopThread();
114114
const Date now = Date::date();
115115

116116
std::vector<TimerPtr> expired = getExpired(now);
117117

118-
_callingExpiredTimers = true;
118+
callingExpiredTimers_ = true;
119119
// cancelingTimers_.clear();
120120
// safe to callback outside critical section
121121
for (auto const &timerPtr : expired)
@@ -125,55 +125,55 @@ void TimerQueue::processTimers()
125125
timerPtr->run();
126126
}
127127
}
128-
_callingExpiredTimers = false;
128+
callingExpiredTimers_ = false;
129129

130130
reset(expired, now);
131131
}
132132
#endif
133133
///////////////////////////////////////
134134
TimerQueue::TimerQueue(EventLoop *loop)
135-
: _loop(loop),
135+
: loop_(loop),
136136
#ifdef __linux__
137-
_timerfd(createTimerfd()),
138-
_timerfdChannelPtr(new Channel(loop, _timerfd)),
137+
timerfd_(createTimerfd()),
138+
timerfdChannelPtr_(new Channel(loop, timerfd_)),
139139
#endif
140-
_timers(),
141-
_callingExpiredTimers(false)
140+
timers_(),
141+
callingExpiredTimers_(false)
142142
{
143143
#ifdef __linux__
144-
_timerfdChannelPtr->setReadCallback(
144+
timerfdChannelPtr_->setReadCallback(
145145
std::bind(&TimerQueue::handleRead, this));
146146
// we are always reading the timerfd, we disarm it with timerfd_settime.
147-
_timerfdChannelPtr->enableReading();
147+
timerfdChannelPtr_->enableReading();
148148
#endif
149149
}
150150
#ifdef __linux__
151151
void TimerQueue::reset()
152152
{
153-
_loop->runInLoop([this]() {
154-
_timerfdChannelPtr->disableAll();
155-
_timerfdChannelPtr->remove();
156-
close(_timerfd);
157-
_timerfd = createTimerfd();
158-
_timerfdChannelPtr = std::make_shared<Channel>(_loop, _timerfd);
159-
_timerfdChannelPtr->setReadCallback(
153+
loop_->runInLoop([this]() {
154+
timerfdChannelPtr_->disableAll();
155+
timerfdChannelPtr_->remove();
156+
close(timerfd_);
157+
timerfd_ = createTimerfd();
158+
timerfdChannelPtr_ = std::make_shared<Channel>(loop_, timerfd_);
159+
timerfdChannelPtr_->setReadCallback(
160160
std::bind(&TimerQueue::handleRead, this));
161161
// we are always reading the timerfd, we disarm it with timerfd_settime.
162-
_timerfdChannelPtr->enableReading();
163-
if (!_timers.empty())
162+
timerfdChannelPtr_->enableReading();
163+
if (!timers_.empty())
164164
{
165-
const Date nextExpire = _timers.top()->when();
166-
resetTimerfd(_timerfd, nextExpire);
165+
const Date nextExpire = timers_.top()->when();
166+
resetTimerfd(timerfd_, nextExpire);
167167
}
168168
});
169169
}
170170
#endif
171171
TimerQueue::~TimerQueue()
172172
{
173173
#ifdef __linux__
174-
auto chlPtr = _timerfdChannelPtr;
175-
auto fd = _timerfd;
176-
_loop->runInLoop([chlPtr, fd]() {
174+
auto chlPtr = timerfdChannelPtr_;
175+
auto fd = timerfd_;
176+
loop_->runInLoop([chlPtr, fd]() {
177177
chlPtr->disableAll();
178178
chlPtr->remove();
179179
::close(fd);
@@ -188,7 +188,7 @@ TimerId TimerQueue::addTimer(const TimerCallback &cb,
188188
std::shared_ptr<Timer> timerPtr =
189189
std::make_shared<Timer>(cb, when, interval);
190190

191-
_loop->runInLoop([=]() { addTimerInLoop(timerPtr); });
191+
loop_->runInLoop([=]() { addTimerInLoop(timerPtr); });
192192
return timerPtr->id();
193193
}
194194
TimerId TimerQueue::addTimer(TimerCallback &&cb,
@@ -198,64 +198,64 @@ TimerId TimerQueue::addTimer(TimerCallback &&cb,
198198
std::shared_ptr<Timer> timerPtr =
199199
std::make_shared<Timer>(std::move(cb), when, interval);
200200

201-
_loop->runInLoop([=]() { addTimerInLoop(timerPtr); });
201+
loop_->runInLoop([=]() { addTimerInLoop(timerPtr); });
202202
return timerPtr->id();
203203
}
204204
void TimerQueue::addTimerInLoop(const TimerPtr &timer)
205205
{
206-
_loop->assertInLoopThread();
206+
loop_->assertInLoopThread();
207207
timerIdSet_.insert(timer->id());
208208
if (insert(timer))
209209
{
210210
// the earliest timer changed
211211
#ifdef __linux__
212-
resetTimerfd(_timerfd, timer->when());
212+
resetTimerfd(timerfd_, timer->when());
213213
#endif
214214
}
215215
}
216216

217217
void TimerQueue::invalidateTimer(TimerId id)
218218
{
219-
_loop->runInLoop([=]() { timerIdSet_.erase(id); });
219+
loop_->runInLoop([=]() { timerIdSet_.erase(id); });
220220
}
221221

222222
bool TimerQueue::insert(const TimerPtr &timerPtr)
223223
{
224-
_loop->assertInLoopThread();
224+
loop_->assertInLoopThread();
225225
bool earliestChanged = false;
226-
if (_timers.size() == 0 || *timerPtr < *_timers.top())
226+
if (timers_.size() == 0 || *timerPtr < *timers_.top())
227227
{
228228
earliestChanged = true;
229229
}
230-
_timers.push(timerPtr);
230+
timers_.push(timerPtr);
231231
// std::cout<<"after push new
232232
// timer:"<<timerPtr->when().microSecondsSinceEpoch()/1000000<<std::endl;
233233
return earliestChanged;
234234
}
235235
#ifndef __linux__
236236
int TimerQueue::getTimeout() const
237237
{
238-
_loop->assertInLoopThread();
239-
if (_timers.empty())
238+
loop_->assertInLoopThread();
239+
if (timers_.empty())
240240
{
241241
return 10000;
242242
}
243243
else
244244
{
245-
return howMuchTimeFromNow(_timers.top()->when());
245+
return howMuchTimeFromNow(timers_.top()->when());
246246
}
247247
}
248248
#endif
249249

250250
std::vector<TimerPtr> TimerQueue::getExpired(const Date &now)
251251
{
252252
std::vector<TimerPtr> expired;
253-
while (!_timers.empty())
253+
while (!timers_.empty())
254254
{
255-
if (_timers.top()->when() < now)
255+
if (timers_.top()->when() < now)
256256
{
257-
expired.push_back(_timers.top());
258-
_timers.pop();
257+
expired.push_back(timers_.top());
258+
timers_.pop();
259259
}
260260
else
261261
break;
@@ -264,7 +264,7 @@ std::vector<TimerPtr> TimerQueue::getExpired(const Date &now)
264264
}
265265
void TimerQueue::reset(const std::vector<TimerPtr> &expired, const Date &now)
266266
{
267-
_loop->assertInLoopThread();
267+
loop_->assertInLoopThread();
268268
for (auto const &timerPtr : expired)
269269
{
270270
if (timerPtr->isRepeat() &&
@@ -275,10 +275,10 @@ void TimerQueue::reset(const std::vector<TimerPtr> &expired, const Date &now)
275275
}
276276
}
277277
#ifdef __linux__
278-
if (!_timers.empty())
278+
if (!timers_.empty())
279279
{
280-
const Date nextExpire = _timers.top()->when();
281-
resetTimerfd(_timerfd, nextExpire);
280+
const Date nextExpire = timers_.top()->when();
281+
resetTimerfd(timerfd_, nextExpire);
282282
}
283283
#endif
284284
}

trantor/net/inner/TimerQueue.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ class TimerQueue : NonCopyable
5454
void processTimers();
5555
#endif
5656
protected:
57-
EventLoop *_loop;
57+
EventLoop *loop_;
5858
#ifdef __linux__
59-
int _timerfd;
60-
std::shared_ptr<Channel> _timerfdChannelPtr;
59+
int timerfd_;
60+
std::shared_ptr<Channel> timerfdChannelPtr_;
6161
void handleRead();
6262
#endif
63-
std::priority_queue<TimerPtr, std::vector<TimerPtr>, comp> _timers;
63+
std::priority_queue<TimerPtr, std::vector<TimerPtr>, comp> timers_;
6464

65-
bool _callingExpiredTimers;
65+
bool callingExpiredTimers_;
6666
bool insert(const TimerPtr &timePtr);
6767
std::vector<TimerPtr> getExpired();
6868
void reset(const std::vector<TimerPtr> &expired, const Date &now);

trantor/net/ssl/SSLConnection.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,46 +44,46 @@ class SSLContext
4444
public:
4545
SSLContext()
4646
{
47-
_ctxPtr = SSL_CTX_new(SSLv23_method());
48-
// SSL_CTX_set_mode(_ctxPtr, SSL_MODE_ENABLE_PARTIAL_WRITE);
47+
ctxPtr_ = SSL_CTX_new(SSLv23_method());
48+
// SSL_CTX_set_mode(ctxPtr_, SSL_MODE_ENABLE_PARTIAL_WRITE);
4949
}
5050
~SSLContext()
5151
{
52-
if (_ctxPtr)
52+
if (ctxPtr_)
5353
{
54-
SSL_CTX_free(_ctxPtr);
54+
SSL_CTX_free(ctxPtr_);
5555
}
5656
}
5757

5858
SSL_CTX *get()
5959
{
60-
return _ctxPtr;
60+
return ctxPtr_;
6161
}
6262

6363
private:
64-
SSL_CTX *_ctxPtr;
64+
SSL_CTX *ctxPtr_;
6565
};
6666
class SSLConn
6767
{
6868
public:
6969
explicit SSLConn(SSL_CTX *ctx)
7070
{
71-
_SSL = SSL_new(ctx);
71+
SSL_ = SSL_new(ctx);
7272
}
7373
~SSLConn()
7474
{
75-
if (_SSL)
75+
if (SSL_)
7676
{
77-
SSL_free(_SSL);
77+
SSL_free(SSL_);
7878
}
7979
}
8080
SSL *get()
8181
{
82-
return _SSL;
82+
return SSL_;
8383
}
8484

8585
private:
86-
SSL *_SSL;
86+
SSL *SSL_;
8787
};
8888

8989
std::shared_ptr<SSLContext> newSSLContext()

trantor/utils/MsgBuffer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
using namespace trantor;
2424
namespace trantor
2525
{
26-
static constexpr size_t kBufferOffset {8};
26+
static constexpr size_t kBufferOffset{8};
2727
}
2828

2929
MsgBuffer::MsgBuffer(size_t len)

0 commit comments

Comments
 (0)