Formatted the entire codebase and added a CI check for formatting

This commit is contained in:
AlexandreRouma
2021-12-19 22:11:44 +01:00
parent 8644957881
commit ea587db0cb
161 changed files with 3302 additions and 3393 deletions

View File

@ -15,7 +15,7 @@ namespace net {
readWorkerThread = std::thread(&ConnClass::readWorker, this);
writeWorkerThread = std::thread(&ConnClass::writeWorker, this);
}
ConnClass::~ConnClass() {
ConnClass::close();
}
@ -28,7 +28,7 @@ namespace net {
std::lock_guard lck2(writeQueueMtx);
stopWorkers = true;
}
// Notify the workers of the change
readQueueCnd.notify_all();
writeQueueCnd.notify_all();
@ -59,7 +59,7 @@ namespace net {
void ConnClass::waitForEnd() {
std::unique_lock lck(readQueueMtx);
connectionOpenCnd.wait(lck, [this](){ return !connectionOpen; });
connectionOpenCnd.wait(lck, [this]() { return !connectionOpen; });
}
int ConnClass::read(int count, uint8_t* buf) {
@ -148,7 +148,7 @@ namespace net {
while (true) {
// Wait for wakeup and exit if it's for terminating the thread
std::unique_lock lck(readQueueMtx);
readQueueCnd.wait(lck, [this](){ return (readQueue.size() > 0 || stopWorkers); });
readQueueCnd.wait(lck, [this]() { return (readQueue.size() > 0 || stopWorkers); });
if (stopWorkers || !connectionOpen) { return; }
// Pop first element off the list
@ -174,7 +174,7 @@ namespace net {
while (true) {
// Wait for wakeup and exit if it's for terminating the thread
std::unique_lock lck(writeQueueMtx);
writeQueueCnd.wait(lck, [this](){ return (writeQueue.size() > 0 || stopWorkers); });
writeQueueCnd.wait(lck, [this]() { return (writeQueue.size() > 0 || stopWorkers); });
if (stopWorkers || !connectionOpen) { return; }
// Pop first element off the list
@ -261,7 +261,6 @@ namespace net {
if (acceptWorkerThread.joinable()) { acceptWorkerThread.join(); }
listening = false;
}
@ -273,7 +272,7 @@ namespace net {
while (true) {
// Wait for wakeup and exit if it's for terminating the thread
std::unique_lock lck(acceptQueueMtx);
acceptQueueCnd.wait(lck, [this](){ return (acceptQueue.size() > 0 || stopWorker); });
acceptQueueCnd.wait(lck, [this]() { return (acceptQueue.size() > 0 || stopWorker); });
if (stopWorker || !listening) { return; }
// Pop first element off the list
@ -299,13 +298,13 @@ namespace net {
Conn connect(std::string host, uint16_t port) {
Socket sock;
Socket sock;
#ifdef _WIN32
// Initialize WinSock2
if (!winsock_init) {
WSADATA wsa;
if (WSAStartup(MAKEWORD(2,2),&wsa)) {
if (WSAStartup(MAKEWORD(2, 2), &wsa)) {
throw std::runtime_error("Could not initialize WinSock2");
return NULL;
}
@ -330,12 +329,12 @@ namespace net {
return NULL;
}
uint32_t* naddr = (uint32_t*)remoteHost->h_addr_list[0];
// Create host address
struct sockaddr_in addr;
addr.sin_addr.s_addr = *naddr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_port = htons(port);
// Connect to host
if (::connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
@ -353,7 +352,7 @@ namespace net {
// Initialize WinSock2
if (!winsock_init) {
WSADATA wsa;
if (WSAStartup(MAKEWORD(2,2),&wsa)) {
if (WSAStartup(MAKEWORD(2, 2), &wsa)) {
throw std::runtime_error("Could not initialize WinSock2");
return NULL;
}
@ -372,14 +371,14 @@ namespace net {
}
#ifndef _WIN32
// Allow port reusing if the app was killed or crashed
// Allow port reusing if the app was killed or crashed
// and the socket is stuck in TIME_WAIT state.
// This option has a different meaning on Windows,
// This option has a different meaning on Windows,
// so we use it only for non-Windows systems
int enable = 1;
if (setsockopt(listenSock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof (int)) < 0) {
if (setsockopt(listenSock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
throw std::runtime_error("Could not configure socket");
return NULL;
return NULL;
}
#endif
@ -395,7 +394,7 @@ namespace net {
struct sockaddr_in addr;
addr.sin_addr.s_addr = *naddr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_port = htons(port);
// Bind socket
if (bind(listenSock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
@ -419,7 +418,7 @@ namespace net {
// Initialize WinSock2
if (!winsock_init) {
WSADATA wsa;
if (WSAStartup(MAKEWORD(2,2),&wsa)) {
if (WSAStartup(MAKEWORD(2, 2), &wsa)) {
throw std::runtime_error("Could not initialize WinSock2");
return NULL;
}
@ -455,15 +454,15 @@ namespace net {
// Create host address
struct sockaddr_in addr;
addr.sin_addr.s_addr = INADDR_ANY;//*naddr;
addr.sin_addr.s_addr = INADDR_ANY; //*naddr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_port = htons(port);
// Create remote host address
struct sockaddr_in raddr;
raddr.sin_addr.s_addr = *rnaddr;
raddr.sin_family = AF_INET;
raddr.sin_port = htons(remotePort);
raddr.sin_port = htons(remotePort);
// Bind socket
if (bindSocket) {
@ -473,7 +472,7 @@ namespace net {
return NULL;
}
}
return Conn(new ConnClass(sock, raddr, true));
}
}