#include <sensor-log-private.h>
#include <sensor-types-private.h>
#include <command_types.h>
-#include <ipc_client.h>
using namespace sensor;
sensor_listener::sensor_listener(sensor_t sensor)
: m_id(0)
, m_sensor(reinterpret_cast<sensor_info *>(sensor))
-, m_client(NULL)
, m_cmd_channel(NULL)
, m_evt_channel(NULL)
, m_handler(NULL)
sensor_listener::sensor_listener(sensor_t sensor, ipc::event_loop *loop)
: m_id(0)
, m_sensor(reinterpret_cast<sensor_info *>(sensor))
-, m_client(NULL)
, m_cmd_channel(NULL)
, m_evt_channel(NULL)
, m_handler(NULL)
bool sensor_listener::init(void)
{
- m_client = new(std::nothrow) ipc::ipc_client(SENSOR_CHANNEL_PATH);
- retvm_if(!m_client, false, "Failed to allocate memory");
-
m_handler = new(std::nothrow) listener_handler(this);
if (!m_handler) {
_E("Failed to allocate memory");
- delete m_client;
return false;
}
if (!connect()) {
delete m_handler;
- delete m_client;
m_handler = NULL;
- m_client = NULL;
return false;
}
m_loop->add_channel_handler_release_list(m_handler);
m_handler = NULL;
- delete m_client;
- m_client = NULL;
-
m_attributes_int.clear();
m_attributes_str.clear();
_D("Deinitialized..");
bool sensor_listener::connect(void)
{
- m_cmd_channel = m_client->connect(NULL);
- retvm_if(!m_cmd_channel, false, "Failed to connect to server");
+ m_cmd_channel = new(std::nothrow) ipc::channel();
+ retvm_if(!m_cmd_channel, false, "Failed to allocate memory");
+ m_cmd_channel->connect(NULL, NULL, true);
- m_evt_channel = m_client->connect(m_handler, m_loop, false);
- retvm_if(!m_evt_channel, false, "Failed to connect to server");
+ m_evt_channel = new(std::nothrow) ipc::channel();
+ retvm_if(!m_evt_channel, false, "Failed to allocate memory");
+ m_evt_channel->connect(m_handler, m_loop, false);
ipc::message msg;
ipc::message reply;
#ifndef __SENSOR_LISTENER_H__
#define __SENSOR_LISTENER_H__
-#include <ipc_client.h>
#include <channel.h>
#include <channel_handler.h>
#include <event_loop.h>
int m_id;
sensor_info *m_sensor;
- ipc::ipc_client *m_client;
ipc::channel *m_cmd_channel;
ipc::channel *m_evt_channel;
ipc::channel_handler *m_handler;
#include <sensor_info.h>
#include <sensor_utils.h>
#include <command_types.h>
-#include <ipc_client.h>
#include <message.h>
#include <channel.h>
using namespace sensor;
sensor_manager::sensor_manager()
-: m_client(NULL)
-, m_cmd_channel(NULL)
+: m_cmd_channel(NULL)
, m_mon_channel(NULL)
, m_connected(false)
, m_handler(NULL)
bool sensor_manager::init(void)
{
- m_client = new(std::nothrow) ipc::ipc_client(SENSOR_CHANNEL_PATH);
- retvm_if(!m_client, false, "Failed to allocate memory");
-
m_handler = new(std::nothrow) channel_handler(this);
if (!m_handler) {
- delete m_client;
- m_client = NULL;
return false;
}
delete m_handler;
m_handler = NULL;
-
- delete m_client;
- m_client = NULL;
}
bool sensor_manager::connect_channel(void)
{
ipc::message msg;
- m_cmd_channel = m_client->connect(NULL);
- retvm_if(!m_cmd_channel, false, "Failed to connect to server");
+ m_cmd_channel = new(std::nothrow) ipc::channel();
+ retvm_if(!m_cmd_channel, false, "Failed to allocate memory");
+ m_cmd_channel->connect(NULL, NULL, true);
- m_mon_channel = m_client->connect(m_handler, &m_loop);
- retvm_if(!m_mon_channel, false, "Failed to connect to server");
+ m_mon_channel = new(std::nothrow) ipc::channel();
+ retvm_if(!m_mon_channel, false, "Failed to allocate memory");
+ m_mon_channel->connect(m_handler, &m_loop, true);
msg.set_type(CMD_MANAGER_CONNECT);
m_mon_channel->send_sync(msg);
#include <channel.h>
#include <sensor_info.h>
-#include <ipc_client.h>
#include <event_loop.h>
#include <list>
#include <atomic>
sensor_info *get_info(const char *uri);
std::vector<sensor_info *> get_infos(const char *uri);
- ipc::ipc_client *m_client;
ipc::channel *m_cmd_channel; /* get sensor information */
ipc::channel *m_mon_channel; /* monitor sensors dinamically added/removed */
ipc::event_loop m_loop;
#include <sensor-log-private.h>
#include <sensor-types-private.h>
#include <sensor_utils.h>
-#include <ipc_client.h>
#include <command_types.h>
#include <cfloat>
#include <cmath>
using namespace sensor;
sensor_provider::sensor_provider(const char *uri)
-: m_client(NULL)
-, m_channel(NULL)
+: m_channel(NULL)
, m_handler(NULL)
, m_connected(false)
{
bool sensor_provider::init(const char *uri)
{
- m_client = new(std::nothrow) ipc::ipc_client(SENSOR_CHANNEL_PATH);
- retvm_if(!m_client, false, "Failed to allocate memory");
-
m_handler = new(std::nothrow) channel_handler(this);
if (!m_handler) {
- delete m_client;
return false;
}
delete m_handler;
m_handler = NULL;
-
- delete m_client;
- m_client = NULL;
}
const char *sensor_provider::get_uri(void)
int sensor_provider::connect(void)
{
- m_channel = m_client->connect(m_handler, &m_loop);
- retvm_if(!m_channel, -EIO, "Failed to connect to server");
+ m_channel = new(std::nothrow) ipc::channel();
+ retvm_if(!m_channel, -EIO, "Failed to allocate memory");
+ m_channel->connect(m_handler, &m_loop, true);
/* serialize and send sensor info */
send_sensor_info(get_sensor_info());
#ifndef __SENSOR_PROVIDER_INTERNAL_H__
#define __SENSOR_PROVIDER_INTERNAL_H__
-#include <ipc_client.h>
#include <channel.h>
#include <channel_handler.h>
#include <event_loop.h>
sensor_info m_sensor;
- ipc::ipc_client *m_client;
ipc::channel *m_channel;
ipc::event_loop m_loop;
channel_handler *m_handler;
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "accept_event_handler.h"
-
-#include "sensor-log-private.h"
-#include "ipc_server.h"
-
-using namespace ipc;
-
-accept_event_handler::accept_event_handler(ipc_server *server)
-: m_server(server)
-{
-}
-
-bool accept_event_handler::handle(int fd, event_condition condition, void **data)
-{
- retv_if((condition & (EVENT_HUP)), false);
-
- stream_socket *cli_sock = new(std::nothrow) stream_socket();
- retvm_if(!cli_sock, false, "Failed to allocate memory");
-
- m_server->accept(*cli_sock);
-
- channel *_ch = new(std::nothrow) channel(cli_sock);
- if (!_ch) {
- delete cli_sock;
- _E("Failed to allocate memory");
- return false;
- }
-
- m_server->register_channel(cli_sock->get_fd(), _ch);
-
- return true;
-}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __ACCEPT_EVENT_HANDLER__
-#define __ACCEPT_EVENT_HANDLER__
-
-#include "event_handler.h"
-
-namespace ipc {
-
-class ipc_server;
-
-class accept_event_handler : public event_handler
-{
-public:
- accept_event_handler(ipc_server *server);
-
- bool handle(int fd, event_condition condition, void **data);
-
-private:
- ipc_server *m_server;
-};
-
-}
-
-#endif /* __ACCEPT_EVENT_HANDLER__ */
#include "sensor-log-private.h"
#include "channel_event_handler.h"
+#include "command_types.h"
#define SYSTEMD_SOCK_BUF_SIZE (128*1024)
channel *m_ch;
};
-channel::channel(socket *sock)
-: m_fd(sock->get_fd())
+channel::channel(void)
+: m_fd(-1)
, m_event_id(0)
-, m_socket(sock)
+, m_socket(NULL)
, m_handler(NULL)
, m_loop(NULL)
, m_connected(false)
return m_event_id;
}
-uint64_t channel::bind(channel_handler *handler, event_loop *loop, bool loop_bind)
+uint64_t channel::bind(event_loop *loop, bool loop_bind)
{
- m_handler = handler;
m_loop = loop;
m_connected.store(true);
uint64_t channel::connect(channel_handler *handler, event_loop *loop, bool loop_bind)
{
+ m_socket = new(std::nothrow) socket();
+ retvm_if(!m_socket, NULL, "Failed to allocate memory");
+
+ if (!m_socket->create(SENSOR_CHANNEL_PATH)) {
+ delete m_socket;
+ return 0;
+ }
+
if (!m_socket->connect())
- return false;
+ return 0;
+
+ m_handler = new(std::nothrow) channel_event_handler(this, handler);
+ retvm_if(!m_handler, NULL, "Failed to allocate memory");
- if (handler)
- bind(handler, loop, loop_bind);
+ bind(loop, loop_bind);
_D("Connect channel[%p] : event id[%llu]", this, m_event_id);
return m_event_id;
class channel {
public:
/* move owernership of the socket to the channel */
- channel(socket *sock);
+ channel();
~channel();
uint64_t bind(void);
- uint64_t bind(channel_handler *handler, event_loop *loop, bool loop_bind);
+ uint64_t bind(event_loop *loop, bool loop_bind);
uint64_t connect(channel_handler *handler, event_loop *loop, bool loop_bind);
void disconnect(void);
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "ipc_client.h"
-
-#include "sensor-log-private.h"
-#include "stream_socket.h"
-#include "event_handler.h"
-#include "channel_event_handler.h"
-
-using namespace ipc;
-
-ipc_client::ipc_client(const std::string &path)
-{
- m_path = path;
-}
-
-ipc_client::~ipc_client()
-{
-}
-
-bool ipc_client::set_option(int option, int value)
-{
- return true;
-}
-
-bool ipc_client::set_option(const std::string &option, int value)
-{
- return true;
-}
-
-channel *ipc_client::connect(channel_handler *handler)
-{
- return connect(handler, NULL);
-}
-
-channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bind)
-{
- socket *sock = NULL;
- channel *ch = NULL;
- channel_event_handler *ev_handler = NULL;
-
- sock = new(std::nothrow) stream_socket();
- retvm_if(!sock, NULL, "Failed to allocate memory");
-
- if (!sock->create(m_path)) {
- delete sock;
- return NULL;
- }
-
- ch = new(std::nothrow) channel(sock);
- if (!ch) {
- delete sock;
- _E("Failed to allocate memory");
- return NULL;
- }
-
- ev_handler = new(std::nothrow) channel_event_handler(ch, handler);
- if (!ev_handler) {
- delete ch;
- _E("Failed to allocate memory");
- return NULL;
- }
-
- uint64_t id = ch->connect(ev_handler, loop, bind);
-
- _D("Connected[%llu]", id);
-
- return ch;
-}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __IPC_CLIENT_H__
-#define __IPC_CLIENT_H__
-
-#include <string>
-
-#include "channel.h"
-#include "channel_handler.h"
-#include "event_loop.h"
-
-namespace ipc {
-
-class ipc_client {
-public:
- ipc_client(const std::string &path);
- ~ipc_client();
-
- bool set_option(int option, int value);
- bool set_option(const std::string &option, int value);
-
- /* call channel->disconnect() after you have used it */
- channel *connect(channel_handler *handler);
- /* TODO: remove bind parameter */
- channel *connect(channel_handler *handler, event_loop *loop, bool bind = true);
-
-private:
- std::string m_path;
-};
-
-}
-
-#endif /* __IPC_CLIENT_H__ */
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "ipc_server.h"
-
-#include "channel.h"
-#include "sensor-log-private.h"
-#include "event_loop.h"
-#include "channel_event_handler.h"
-#include "accept_event_handler.h"
-
-using namespace ipc;
-
-#define MAX_CONNECTIONS 1000
-
-ipc_server::ipc_server(const std::string &path)
-: m_event_loop(NULL)
-, m_handler(NULL)
-, m_accept_handler(NULL)
-{
- m_accept_sock.create(path);
-}
-
-ipc_server::~ipc_server()
-{
-}
-
-bool ipc_server::set_option(int option, int value)
-{
- /* TODO */
- return true;
-}
-
-bool ipc_server::set_option(const std::string &option, int value)
-{
- /* TODO */
- return true;
-}
-
-void ipc_server::accept(ipc::socket &cli_sock)
-{
- m_accept_sock.accept(cli_sock);
-
- _D("Accepted[%d]", cli_sock.get_fd());
-}
-
-bool ipc_server::bind(channel_handler *handler, event_loop *loop)
-{
- m_handler = handler;
- m_event_loop = loop;
-
- m_accept_sock.bind();
- m_accept_sock.listen(MAX_CONNECTIONS);
-
- register_acceptor();
-
- _D("Bound[%d]", m_accept_sock.get_fd());
- return true;
-}
-
-void ipc_server::register_channel(int fd, channel *ch)
-{
- channel_event_handler *ev_handler = new(std::nothrow) channel_event_handler(ch, m_handler);
- retm_if(!ev_handler, "Failed to allocate memory");
-
- uint64_t id = ch->bind(ev_handler, m_event_loop, true);
-
- if (id == 0) {
- _E("Failed to register channel");
- delete ev_handler;
- return;
- }
-
- _D("Register channel[%p] : event_id[%llu]", ch, id);
-}
-
-void ipc_server::register_acceptor(void)
-{
- int fd = m_accept_sock.get_fd();
-
- m_accept_handler = new(std::nothrow) accept_event_handler(this);
- retm_if(!m_accept_handler, "Failed to allocate memory");
-
- uint64_t id = m_event_loop->add_event(fd,
- (event_condition)(EVENT_IN | EVENT_HUP | EVENT_NVAL), m_accept_handler);
-
- if (id == 0) {
- _D("Failed to add accept event handler");
- delete m_accept_handler;
- m_accept_handler = NULL;
- }
-}
-
-bool ipc_server::close(void)
-{
- m_accept_sock.close();
-
- m_handler = NULL;
-
- return true;
-}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __IPC_SERVER_H__
-#define __IPC_SERVER_H__
-
-#include <string>
-
-#include "stream_socket.h"
-#include "channel.h"
-#include "channel_handler.h"
-#include "accept_event_handler.h"
-#include "event_loop.h"
-
-namespace ipc {
-
-class ipc_server {
-public:
- ipc_server(const std::string &path);
- ~ipc_server();
-
- bool set_option(int option, int value);
- bool set_option(const std::string &option, int value);
-
- bool bind(channel_handler *handler, event_loop *loop);
- bool close(void);
-
- /* TODO: only accept_handler should use these functions */
- void accept(ipc::socket &cli_sock);
- void register_channel(int fd, channel *ch);
- void register_acceptor(void);
-
-private:
- stream_socket m_accept_sock;
-
- event_loop *m_event_loop;
- channel_handler *m_handler;
- accept_event_handler *m_accept_handler;
-};
-
-}
-
-#endif /* __IPC_SERVER_H__ */
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "seqpacket_socket.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include "sensor-log-private.h"
-
-using namespace ipc;
-
-seqpacket_socket::seqpacket_socket()
-: socket()
-{
-}
-
-seqpacket_socket::~seqpacket_socket()
-{
-}
-
-bool seqpacket_socket::create(const std::string &path)
-{
- return socket::create_by_type(path, SOCK_SEQPACKET);
-}
-
-ssize_t seqpacket_socket::on_send(const void *buffer, size_t size) const
-{
- ssize_t err, len;
-
- do {
- len = ::send(socket::get_fd(),
- reinterpret_cast<const char *>(buffer),
- size,
- socket::get_mode());
-
- err = len < 0 ? errno : 0;
- } while (err == EINTR);
-
- if (err) {
- _ERRNO(errno, _E, "Failed to send(%d, %p, %u) = %d",
- socket::get_fd(), buffer, size, len);
- }
-
- return err == 0 ? len : -err;
-}
-
-ssize_t seqpacket_socket::on_recv(void *buffer, size_t size) const
-{
- ssize_t err, len;
-
- do {
- len = ::recv(socket::get_fd(),
- reinterpret_cast<char *>(buffer),
- size,
- socket::get_mode());
-
- if (len > 0) {
- err = 0;
- } else if (len == 0) {
- _E("Failed to recv(%d, %p , %u) = %d, because the peer performed shutdown!",
- socket::get_fd(), buffer, size, len);
- err = 1;
- } else {
- err = errno;
- }
- } while (err == EINTR);
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK))
- return 0;
-
- if (err) {
- _ERRNO(errno, _E, "Failed to recv(%d, %p, %u) = %d",
- socket::get_fd(), buffer, size, len);
- }
-
- return err == 0 ? len : -err;
-}
-
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __SEQPACKET_SOCKET_H__
-#define __SEQPACKET_SOCKET_H__
-
-#include "socket.h"
-
-namespace ipc {
-
-class seqpacket_socket : public socket {
-public:
- seqpacket_socket();
- ~seqpacket_socket();
-
- bool create(const std::string &path);
-
-private:
- ssize_t on_send(const void *buffer, size_t size) const;
- ssize_t on_recv(void *buffer, size_t size) const;
-};
-
-}
-
-#endif /* __SEQPACKET_SOCKET_H__ */
#include "sensor-log-private.h"
#define SOCK_TIMEOUT 10
+#define SLEEP_10_MS usleep(10000)
using namespace ipc;
bool socket::create(const std::string &path)
{
- return false;
+ m_sock_fd = ::create_systemd_socket(path, SOCK_STREAM);
+ if (m_sock_fd < 0)
+ m_sock_fd = create_unix_socket(SOCK_STREAM);
+ else
+ m_listening.store(true);
+
+ retvm_if((m_sock_fd < 0), false, "Failed to create socket");
+
+ /* non-blocking mode */
+ retvm_if(!set_blocking_mode(false), false, "Failed to set non-blocking mode");
+ /* recv timeout */
+ retvm_if(!set_recv_timeout(1), false, "Failed to set timeout");
+ /* TODO */
+ /*retvm_if(!set_reuse_addr(), false, "Failed to reuse address"); */
+
+ m_path = path;
+
+ return true;
}
ssize_t socket::send(const void *buffer, size_t size, bool select) const
return on_recv(buffer, size);
}
-bool socket::create_by_type(const std::string &path, int type)
-{
- m_sock_fd = ::create_systemd_socket(path, type);
- if (m_sock_fd < 0)
- m_sock_fd = create_unix_socket(type);
- else
- m_listening.store(true);
-
- retvm_if((m_sock_fd < 0), false, "Failed to create socket");
-
- /* non-blocking mode */
- retvm_if(!set_blocking_mode(false), false, "Failed to set non-blocking mode");
- /* recv timeout */
- retvm_if(!set_recv_timeout(1), false, "Failed to set timeout");
- /* TODO */
- /*retvm_if(!set_reuse_addr(), false, "Failed to reuse address"); */
-
- m_path = path;
-
- return true;
-}
-
int socket::get_sock_type(void)
{
socklen_t opt_len;
return queue_size;
}
+ssize_t socket::on_send(const void *buffer, size_t size) const
+{
+ ssize_t len = 0;
+ size_t total_size = 0;
+
+ do {
+ len = ::send(get_fd(),
+ reinterpret_cast<const char *>(buffer) + total_size,
+ size - total_size, get_mode());
+
+ if (len < 0) {
+ if ((errno == EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK)) {
+ SLEEP_10_MS;
+ continue;
+ }
+
+ _ERRNO(errno, _E, "Failed to send(%d, %p, %u, %u) = %d",
+ get_fd(), buffer, total_size, size - total_size, len);
+ return -errno;
+ }
+
+ total_size += len;
+ } while (total_size < size);
+
+ return total_size;
+}
+
+ssize_t socket::on_recv(void *buffer, size_t size) const
+{
+ ssize_t len = 0;
+ size_t total_size = 0;
+
+ do {
+ len = ::recv(get_fd(),
+ reinterpret_cast<char *>(buffer) + total_size,
+ size - total_size,
+ socket::get_mode());
+
+ if (len == 0) {
+ _E("Failed to recv(%d, %p + %x, %u) = %d, because the peer performed shutdown",
+ get_fd(), buffer, total_size, size - total_size, len);
+ return -1;
+ }
+
+ if (len < 0) {
+ if ((errno == EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK)) {
+ SLEEP_10_MS;
+ continue;
+ }
+
+ _ERRNO(errno, _E, "Failed to recv(%d, %p, %u, %u) = %d",
+ get_fd(), buffer, total_size, size - total_size, len);
+ return -errno;
+ }
+
+ total_size += len;
+ } while (total_size < size);
+
+ return total_size;
+}
ssize_t send(const void *buffer, size_t size, bool select = false) const;
ssize_t recv(void* buffer, size_t size, bool select = false) const;
-protected:
- bool create_by_type(const std::string &path, int type);
-
private:
- virtual ssize_t on_send(const void *buffer, size_t size) const = 0;
- virtual ssize_t on_recv(void* buffer, size_t size) const = 0;
+ ssize_t on_send(const void *buffer, size_t size) const;
+ ssize_t on_recv(void* buffer, size_t size) const;
int get_sock_type(void);
bool set_sock_type(int type);
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "stream_socket.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include "sensor-log-private.h"
-
-#define SLEEP_10_MS usleep(10000)
-
-using namespace ipc;
-
-stream_socket::stream_socket()
-: socket()
-{
-}
-
-stream_socket::~stream_socket()
-{
-}
-
-bool stream_socket::create(const std::string &path)
-{
- return socket::create_by_type(path, SOCK_STREAM);
-}
-
-ssize_t stream_socket::on_send(const void *buffer, size_t size) const
-{
- ssize_t len = 0;
- size_t total_size = 0;
-
- do {
- len = ::send(get_fd(),
- reinterpret_cast<const char *>(buffer) + total_size,
- size - total_size, get_mode());
-
- if (len < 0) {
- if ((errno == EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK)) {
- SLEEP_10_MS;
- continue;
- }
-
- _ERRNO(errno, _E, "Failed to send(%d, %p, %u, %u) = %d",
- get_fd(), buffer, total_size, size - total_size, len);
- return -errno;
- }
-
- total_size += len;
- } while (total_size < size);
-
- return total_size;
-}
-
-ssize_t stream_socket::on_recv(void *buffer, size_t size) const
-{
- ssize_t len = 0;
- size_t total_size = 0;
-
- do {
- len = ::recv(get_fd(),
- reinterpret_cast<char *>(buffer) + total_size,
- size - total_size,
- socket::get_mode());
-
- if (len == 0) {
- _E("Failed to recv(%d, %p + %x, %u) = %d, because the peer performed shutdown",
- get_fd(), buffer, total_size, size - total_size, len);
- return -1;
- }
-
- if (len < 0) {
- if ((errno == EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK)) {
- SLEEP_10_MS;
- continue;
- }
-
- _ERRNO(errno, _E, "Failed to recv(%d, %p, %u, %u) = %d",
- get_fd(), buffer, total_size, size - total_size, len);
- return -errno;
- }
-
- total_size += len;
- } while (total_size < size);
-
- return total_size;
-}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __STREAM_SOCKET_H__
-#define __STREAM_SOCKET_H__
-
-#include "socket.h"
-
-namespace ipc {
-
-class stream_socket : public socket {
-public:
- stream_socket();
- ~stream_socket();
-
- bool create(const std::string &path);
-
-private:
- ssize_t on_send(const void *buffer, size_t size) const;
- ssize_t on_recv(void *buffer, size_t size) const;
-};
-
-}
-
-#endif /* __STREAM_SOCKET_H__ */