Skip to content

Commit e42d6d3

Browse files
committed
Using clang-tidy tool to auto fix style of C++ code
1 parent 07289e3 commit e42d6d3

File tree

11 files changed

+87
-94
lines changed

11 files changed

+87
-94
lines changed

include/swoole_server.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ class Server {
11571157

11581158
uint32_t get_idle_worker_num();
11591159
int get_idle_task_worker_num();
1160-
int get_tasking_num();
1160+
int get_tasking_num() const;
11611161

11621162
TaskId get_task_id(EventData *task) {
11631163
return gs->task_workers.get_task_id(task);
@@ -1600,7 +1600,7 @@ class Server {
16001600
void worker_start_callback(Worker *worker);
16011601
void worker_stop_callback(Worker *worker);
16021602
void worker_accept_event(DataHead *info);
1603-
void worker_signal_init(void);
1603+
void worker_signal_init();
16041604

16051605
std::function<void(std::shared_ptr<Thread>, const WorkerFn &fn)> worker_thread_start;
16061606

src/server/base.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ namespace swoole {
2020

2121
Factory *Server::create_base_factory() {
2222
reactor_num = worker_num;
23-
connection_list = (Connection *) sw_calloc(max_connection, sizeof(Connection));
23+
connection_list = static_cast<Connection *>(sw_calloc(max_connection, sizeof(Connection)));
2424
if (connection_list == nullptr) {
2525
swoole_sys_warning("calloc[2](%d) failed", (int) (max_connection * sizeof(Connection)));
2626
return nullptr;
2727
}
28-
gs->connection_nums = (sw_atomic_t *) sw_shm_calloc(worker_num, sizeof(sw_atomic_t));
28+
gs->connection_nums = static_cast<sw_atomic_t *>(sw_shm_calloc(worker_num, sizeof(sw_atomic_t)));
2929
if (gs->connection_nums == nullptr) {
3030
swoole_error("sw_shm_calloc(%ld) for gs->connection_nums failed", worker_num * sizeof(sw_atomic_t));
3131
return nullptr;
3232
}
3333

3434
for (auto port : ports) {
35-
port->gs->connection_nums = (sw_atomic_t *) sw_shm_calloc(worker_num, sizeof(sw_atomic_t));
35+
port->gs->connection_nums = static_cast<sw_atomic_t *>(sw_shm_calloc(worker_num, sizeof(sw_atomic_t)));
3636
if (port->gs->connection_nums == nullptr) {
3737
swoole_error("sw_shm_calloc(%ld) for port->connection_nums failed", worker_num * sizeof(sw_atomic_t));
3838
return nullptr;
@@ -53,7 +53,7 @@ void Server::destroy_base_factory() {
5353

5454
BaseFactory::BaseFactory(Server *server) : Factory(server) {}
5555

56-
BaseFactory::~BaseFactory() {}
56+
BaseFactory::~BaseFactory() = default;
5757

5858
bool BaseFactory::start() {
5959
return true;
@@ -101,7 +101,7 @@ bool BaseFactory::dispatch(SendData *task) {
101101
* only stream fd
102102
*/
103103
bool BaseFactory::notify(DataHead *info) {
104-
Connection *conn = server_->get_connection(info->fd);
104+
auto conn = server_->get_connection(info->fd);
105105
if (conn == nullptr || conn->active == 0) {
106106
swoole_warning("dispatch[type=%d] failed, socket#%ld is not active", info->type, info->fd);
107107
return false;

src/server/manager.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ struct Manager {
3636
std::vector<pid_t> kill_workers;
3737

3838
void wait(Server *_server);
39-
void add_timeout_killer(Worker *workers, int n);
4039
void terminate_all_worker();
4140

4241
static void signal_handler(int sig);
4342
static void timer_callback(Timer *timer, TimerNode *tnode);
4443
};
4544

4645
void Manager::timer_callback(Timer *timer, TimerNode *tnode) {
47-
Server *serv = (Server *) tnode->data;
46+
auto *serv = (Server *) tnode->data;
4847
if (serv->isset_hook(Server::HOOK_MANAGER_TIMER)) {
4948
serv->call_hook(Server::HOOK_MANAGER_TIMER, serv);
5049
}
@@ -63,7 +62,7 @@ int Server::start_manager_process() {
6362
return SW_ERR;
6463
}
6564

66-
auto fn = [this](void) {
65+
auto fn = [this]() {
6766
gs->manager_pid = SwooleG.pid = getpid();
6867

6968
if (task_worker_num > 0) {
@@ -251,7 +250,7 @@ void Manager::wait(Server *_server) {
251250
SW_START_SLEEP;
252251
continue;
253252
}
254-
} while (0);
253+
} while (false);
255254
}
256255

257256
// task worker
@@ -330,8 +329,8 @@ void Manager::wait(Server *_server) {
330329
void Manager::terminate_all_worker() {
331330
// clear the timer
332331
alarm(0);
333-
for (auto i = kill_workers.begin(); i != kill_workers.end(); i++) {
334-
swoole_kill(*i, SIGKILL);
332+
for (int & kill_worker : kill_workers) {
333+
swoole_kill(kill_worker, SIGKILL);
335334
}
336335
}
337336

@@ -374,7 +373,7 @@ void Manager::signal_handler(int signo) {
374373
* @return: success returns pid, failure returns SW_ERR.
375374
*/
376375
int Server::wait_other_worker(ProcessPool *pool, const ExitStatus &exit_status) {
377-
Server *serv = (Server *) pool->ptr;
376+
auto serv = (Server *) pool->ptr;
378377
Worker *exit_worker = nullptr;
379378
int worker_type;
380379

@@ -396,7 +395,7 @@ int Server::wait_other_worker(ProcessPool *pool, const ExitStatus &exit_status)
396395
}
397396
}
398397
return SW_ERR;
399-
} while (0);
398+
} while (false);
400399

401400
serv->factory->check_worker_exit_status(exit_worker, exit_status);
402401

@@ -426,15 +425,15 @@ void Server::read_worker_message(ProcessPool *pool, EventData *msg) {
426425
return;
427426
}
428427

429-
Server *serv = (Server *) pool->ptr;
428+
auto serv = (Server *) pool->ptr;
430429
int command_id = msg->info.server_fd;
431430
auto iter = serv->command_handlers.find(command_id);
432431
if (iter == serv->command_handlers.end()) {
433432
swoole_error_log(SW_LOG_ERROR, SW_ERROR_SERVER_INVALID_COMMAND, "Unknown command[command_id=%d]", command_id);
434433
return;
435434
}
436435

437-
Server::Command::Handler handler = iter->second;
436+
Command::Handler handler = iter->second;
438437
auto result = handler(serv, std::string(msg->data, msg->info.len));
439438

440439
SendData task{};

src/server/master.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "swoole_lock.h"
2020
#include "swoole_util.h"
2121

22-
#include <assert.h>
22+
#include <cassert>
2323

2424
using swoole::network::Address;
2525
using swoole::network::SendfileTask;
@@ -143,8 +143,8 @@ int Server::accept_command_result(Reactor *reactor, Event *event) {
143143
}
144144

145145
int Server::accept_connection(Reactor *reactor, Event *event) {
146-
Server *serv = (Server *) reactor->ptr;
147-
ListenPort *listen_host = (ListenPort *) event->socket->object;
146+
auto serv = static_cast<Server *>(reactor->ptr);
147+
auto listen_host = static_cast<ListenPort *>(event->socket->object);
148148

149149
for (int i = 0; i < SW_ACCEPT_MAX_COUNT; i++) {
150150
Socket *sock = event->socket->accept();
@@ -708,7 +708,7 @@ Server::Server(enum Mode _mode) {
708708
mode_ = _mode;
709709

710710
// http server
711-
http_compression = 1;
711+
http_compression = true;
712712
http_compression_level = SW_Z_BEST_SPEED;
713713
compression_min_length = SW_COMPRESSION_MIN_LENGTH_DEFAULT;
714714

@@ -1063,7 +1063,7 @@ void Server::destroy() {
10631063

10641064
SW_LOOP_N(SW_MAX_HOOK_TYPE) {
10651065
if (hooks[i]) {
1066-
std::list<Callback> *l = reinterpret_cast<std::list<Callback> *>(hooks[i]);
1066+
auto l = static_cast<std::list<Callback> *>(hooks[i]);
10671067
hooks[i] = nullptr;
10681068
delete l;
10691069
}
@@ -1106,7 +1106,8 @@ bool Server::feedback(Connection *conn, enum ServerEventType event) {
11061106
_send.info.reactor_id = conn->reactor_id;
11071107

11081108
if (is_process_mode()) {
1109-
return send_to_reactor_thread((EventData *) &_send.info, sizeof(_send.info), conn->session_id) > 0;
1109+
return send_to_reactor_thread(
1110+
reinterpret_cast<EventData *>(&_send.info), sizeof(_send.info), conn->session_id) > 0;
11101111
} else {
11111112
return send_to_connection(&_send) == SW_OK;
11121113
}
@@ -1501,7 +1502,6 @@ int Server::send_to_connection(SendData *_send) {
15011502
_socket->out_buffer->append(_send_data, _send_length);
15021503
conn->send_queued_bytes = _socket->out_buffer->length();
15031504

1504-
ListenPort *port = get_port_by_fd(fd);
15051505
if (onBufferFull && conn->high_watermark == 0 && _socket->out_buffer->length() >= port->buffer_high_watermark) {
15061506
notify(conn, SW_SERVER_EVENT_BUFFER_FULL);
15071507
conn->high_watermark = 1;
@@ -1988,7 +1988,7 @@ Connection *Server::add_connection(ListenPort *ls, Socket *_socket, int server_f
19881988

19891989
connection->fd = fd;
19901990
connection->reactor_id = reactor_id;
1991-
connection->server_fd = (sw_atomic_t) server_fd;
1991+
connection->server_fd = server_fd;
19921992
connection->last_recv_time = connection->connect_time = microtime();
19931993
connection->active = 1;
19941994
connection->worker_id = -1;
@@ -2044,7 +2044,7 @@ void Server::init_pipe_sockets(MessageBus *mb) {
20442044
size_t n = get_core_worker_num();
20452045

20462046
SW_LOOP_N(n) {
2047-
Worker *worker = get_worker(i);
2047+
const auto worker = get_worker(i);
20482048
if (i >= worker_num && task_ipc_mode != TASK_IPC_UNIXSOCK) {
20492049
continue;
20502050
}
@@ -2091,7 +2091,7 @@ int Server::get_idle_task_worker_num() {
20912091
return idle_worker_num;
20922092
}
20932093

2094-
int Server::get_tasking_num() {
2094+
int Server::get_tasking_num() const {
20952095
// TODO Why need to reset ?
20962096
int tasking_num = gs->tasking_num;
20972097
if (tasking_num < 0) {

src/server/port.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,15 @@ int ListenPort::readable_callback_http(Reactor *reactor, ListenPort *port, Event
455455
}
456456

457457
if (n == 0) {
458-
if (0) {
458+
if (false) {
459459
_bad_request:
460460
_socket->send(SW_STRL(SW_HTTP_BAD_REQUEST_PACKET), 0);
461461
}
462-
if (0) {
462+
if (false) {
463463
_too_large:
464464
_socket->send(SW_STRL(SW_HTTP_REQUEST_ENTITY_TOO_LARGE_PACKET), 0);
465465
}
466-
if (0) {
466+
if (false) {
467467
_unavailable:
468468
_socket->send(SW_STRL(SW_HTTP_SERVICE_UNAVAILABLE_PACKET), 0);
469469
}

src/server/process.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Factory *Server::create_process_factory() {
2828
/**
2929
* alloc the memory for connection_list
3030
*/
31-
connection_list = (Connection *) sw_shm_calloc(max_connection, sizeof(Connection));
31+
connection_list = static_cast<Connection *>(sw_shm_calloc(max_connection, sizeof(Connection)));
3232
if (connection_list == nullptr) {
3333
swoole_error("calloc[1] failed");
3434
return nullptr;
@@ -381,7 +381,6 @@ bool ProcessFactory::end(SessionId session_id, int flags) {
381381

382382
swoole_trace_log(SW_TRACE_CLOSE, "session_id=%ld, fd=%d", session_id, conn->fd);
383383

384-
Worker *worker;
385384
DataHead ev = {};
386385

387386
/**
@@ -390,6 +389,7 @@ bool ProcessFactory::end(SessionId session_id, int flags) {
390389
* MUST forward to the correct worker process
391390
*/
392391
if (conn->close_actively) {
392+
Worker *worker;
393393
bool hash = server_->is_hash_dispatch_mode();
394394
int worker_id = hash ? server_->schedule_worker(conn->fd, nullptr) : conn->fd % server_->worker_num;
395395
if (server_->is_worker() && (!hash || worker_id == (int) swoole_get_process_id())) {

src/server/reactor_process.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
#include "swoole_server.h"
18-
#include "swoole_memory.h"
1918

2019
namespace swoole {
2120
using network::Socket;

0 commit comments

Comments
 (0)