[Reform] Apply Coding Style
authorreview-bot <reviewbot@samsung.com>
Fri, 5 Feb 2021 05:51:53 +0000 (14:51 +0900)
committer최창규/Tizen Platform Lab(SR)/Engineer/삼성전자 <changyu.choi@samsung.com>
Fri, 5 Feb 2021 06:00:12 +0000 (15:00 +0900)
src/common/socket/abstract_socket.cc
src/common/socket/client_socket.cc
src/common/socket/data_socket.cc
src/common/socket/server_socket.cc

index 7e6a42a..b730cc1 100644 (file)
@@ -32,9 +32,7 @@ AbstractSocket::AbstractSocket(std::string path)
 
 AbstractSocket::AbstractSocket(int fd) : fd_(fd), addr_{} {}
 
-AbstractSocket::~AbstractSocket() {
-  Destroy();
-}
+AbstractSocket::~AbstractSocket() { Destroy(); }
 
 int AbstractSocket::SendData(const void* buf, unsigned int size) {
   auto buffer = static_cast<const unsigned char*>(buf);
@@ -55,8 +53,7 @@ int AbstractSocket::SendData(const void* buf, unsigned int size) {
 
 int AbstractSocket::ReceiveData(void* buf, unsigned int size) {
   bool is_blocking = true;
-  if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK)
-    is_blocking = false;
+  if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK) is_blocking = false;
 
   auto buffer = static_cast<unsigned char*>(buf);
   unsigned int left = size;
@@ -101,8 +98,7 @@ void AbstractSocket::SetOption() {
   }
 
   ret = setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
-  if (ret < 0)
-    LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+  if (ret < 0) LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
 }
 
 int AbstractSocket::Create() {
index a7d0019..656bcb0 100644 (file)
@@ -30,8 +30,7 @@ namespace socket {
 ClientSocket::ClientSocket(std::string path) : AbstractSocket(std::move(path)) {
   int retry_cnt = 2;
   int ret = Create();
-  if (ret < 0)
-    return;
+  if (ret < 0) return;
 
   do {
     ret = Connect();
@@ -39,29 +38,25 @@ ClientSocket::ClientSocket(std::string path) : AbstractSocket(std::move(path)) {
       break;
     } else if (ret < -1) {
       LOGE("Maybe peer not launched or peer dead. path(%s), fd(%d)",
-          GetPath().c_str(), GetFd());
+           GetPath().c_str(), GetFd());
       usleep(100 * 1000);
       --retry_cnt;
     } else if (ret < 0) {
-      LOGE("Failed to connect to socket(%s), fd(%d)",
-          GetPath().c_str(), GetFd());
+      LOGE("Failed to connect to socket(%s), fd(%d)", GetPath().c_str(),
+           GetFd());
       return;
     }
   } while (retry_cnt > 0);
 
-  if (retry_cnt == 0)
-    return;
+  if (retry_cnt == 0) return;
 
   SetTimeout(5);
 }
 
-ClientSocket::~ClientSocket() {
-  Destroy();
-}
+ClientSocket::~ClientSocket() { Destroy(); }
 
 void ClientSocket::SetTimeout(int timeout_msec) {
-  if (timeout_msec == -1)
-    timeout_msec = 5000;
+  if (timeout_msec == -1) timeout_msec = 5000;
 
   if (timeout_msec < 0) {
     LOGE("Invalid timeout_msec parameter");
@@ -69,24 +64,21 @@ void ClientSocket::SetTimeout(int timeout_msec) {
   }
 
   struct timeval timeout = {
-    .tv_sec = static_cast<time_t>(timeout_msec / 1000),
-    .tv_usec = static_cast<suseconds_t>((timeout_msec % 1000) * 1000)
-  };
+      .tv_sec = static_cast<time_t>(timeout_msec / 1000),
+      .tv_usec = static_cast<suseconds_t>((timeout_msec % 1000) * 1000)};
   int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
-  if (ret < 0)
-    LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+  if (ret < 0) LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
 }
 
 int ClientSocket::Connect() {
   int flags = fcntl(fd_, F_GETFL, 0);
   fcntl(fd_, F_SETFL, flags | O_NONBLOCK);
 
-  int ret = connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_),
-      sizeof(addr_));
+  int ret =
+      connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_), sizeof(addr_));
   fcntl(fd_, F_SETFL, flags);
   if (ret < 0) {
-    if (errno != EAGAIN && errno != EINPROGRESS)
-      return -2;
+    if (errno != EAGAIN && errno != EINPROGRESS) return -2;
   } else if (ret == 0) {
     SetOption();
     return 0;
@@ -96,7 +88,7 @@ int ClientSocket::Connect() {
   FD_ZERO(&readfds);
   FD_SET(fd_, &readfds);
   fd_set writefds = readfds;
-  struct timeval timeout = { 0, 100 * 1000 };
+  struct timeval timeout = {0, 100 * 1000};
   ret = select(fd_ + 1, &readfds, &writefds, NULL, &timeout);
   if (ret == 0) {
     errno = ETIMEDOUT;
@@ -106,8 +98,7 @@ int ClientSocket::Connect() {
   if (FD_ISSET(fd_, &readfds) || FD_ISSET(fd_, &writefds)) {
     int error = 0;
     socklen_t len = sizeof(error);
-    if (getsockopt(fd_, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
-      return -1;
+    if (getsockopt(fd_, SOL_SOCKET, SO_ERROR, &error, &len) < 0) return -1;
   }
 
   return -1;
index 113b31d..6877ab2 100644 (file)
@@ -21,9 +21,7 @@ namespace socket {
 
 DataSocket::DataSocket(int fd) : AbstractSocket(fd) {}
 
-DataSocket::~DataSocket() {
-  Destroy();
-}
+DataSocket::~DataSocket() { Destroy(); }
 
 }  // namespace socket
 }  // namespace pkgmgr_common
index f8b8c90..ee1d7b9 100644 (file)
@@ -64,17 +64,13 @@ ServerSocket::ServerSocket(std::string path) : AbstractSocket(std::move(path)) {
   LOGD("Server socket is created(%s)", path_.c_str());
 }
 
-ServerSocket::~ServerSocket() {
-  Destroy();
-}
+ServerSocket::~ServerSocket() { Destroy(); }
 
 int ServerSocket::Bind() {
   return bind(fd_, reinterpret_cast<struct sockaddr*>(&addr_), sizeof(addr_));
 }
 
-int ServerSocket::Listen() {
-  return listen(fd_, 128);
-}
+int ServerSocket::Listen() { return listen(fd_, 128); }
 
 int ServerSocket::Accept() {
   int client_fd = accept(fd_, nullptr, nullptr);