4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "seqpacket_socket.h"
22 #include <sys/types.h>
23 #include <sys/socket.h>
25 #include "sensor_log.h"
29 seqpacket_socket::seqpacket_socket()
34 seqpacket_socket::~seqpacket_socket()
38 bool seqpacket_socket::create(const std::string &path)
40 return socket::create_by_type(path, SOCK_SEQPACKET);
43 ssize_t seqpacket_socket::on_send(const void *buffer, size_t size) const
48 len = ::send(socket::get_fd(),
49 reinterpret_cast<const char *>(buffer),
53 err = len < 0 ? errno : 0;
54 } while (err == EINTR);
57 _ERRNO(errno, _E, "Failed to send(%d, %#x, %d) = %d",
58 socket::get_fd(), buffer, size, len);
61 return err == 0 ? len : -err;
64 ssize_t seqpacket_socket::on_recv(void *buffer, size_t size) const
69 len = ::recv(socket::get_fd(),
70 reinterpret_cast<char *>(buffer),
76 } else if (len == 0) {
77 _E("Failed to recv(%d, %#p , %d) = %d, because the peer performed shutdown!",
78 socket::get_fd(), buffer, size, len);
83 } while (err == EINTR);
85 if ((err == EAGAIN) || (err == EWOULDBLOCK))
89 _ERRNO(errno, _E, "Failed to recv(%d, %#x, %d) = %d",
90 socket::get_fd(), buffer, size, len);
93 return err == 0 ? len : -err;