2 * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "launchpad-common/socket.hh"
22 #include <sys/socket.h>
23 #include <sys/types.h>
27 #include "launchpad-common/log_private.hh"
32 constexpr const int MAX_RETRY_CNT = 2;
36 Socket::Socket(int fd) : fd_(fd) {}
42 void Socket::Close() {
49 int Socket::Write(const void* buf, size_t size) {
50 const unsigned char* buffer = static_cast<const unsigned char*>(buf);
54 ssize_t bytes = write(fd_, buffer, left);
57 _E("Write() is failed. fd(%d), errno(%d)", fd_, errno);
68 int Socket::Read(void* buf, size_t size) {
69 unsigned char* buffer = static_cast<unsigned char*>(buf);
73 ssize_t bytes = read(fd_, buffer, left);
75 _W("EOF. fd(%d)", fd_);
89 bool Socket::IsClosed() const {
93 int Socket::GetFd() const {
97 int Socket::RemoveFd() {
103 } // namespace launchpad