if (source_ > 0)
g_source_remove(source_);
-
- if (channel_ != nullptr)
- g_io_channel_unref(channel_);
}
int Proxy::ProxyPort::Watch(bool receive) {
- channel_ = g_io_channel_unix_new(GetFd());
- if (channel_ == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- return -1;
- }
-
- disconn_source_ = g_io_add_watch(channel_,
- static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
+ disconn_source_ = g_unix_fd_add(
+ GetFd(), static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
Proxy::ProxyPort::OnSocketDisconnected, parent_);
if (disconn_source_ == 0) {
- _E("g_io_add_watch() is failed");
+ _E("g_unix_fd_add() is failed");
return -1;
}
if (!receive)
return 0;
- source_ = g_io_add_watch(channel_, static_cast<GIOCondition>(G_IO_IN),
- Proxy::ProxyPort::OnDataReceived, parent_);
+ source_ = g_unix_fd_add(GetFd(), static_cast<GIOCondition>(G_IO_IN),
+ Proxy::ProxyPort::OnDataReceived, parent_);
if (source_ == 0) {
- _E("g_io_add_watch() is failed");
+ _E("g_unix_fd_add() is failed");
return -1;
}
source_ = source_id;
}
-gboolean Proxy::ProxyPort::OnSocketDisconnected(GIOChannel* channel,
- GIOCondition cond, gpointer user_data) {
+gboolean Proxy::ProxyPort::OnSocketDisconnected(gint fd, GIOCondition cond,
+ gpointer user_data) {
auto* proxy = static_cast<Proxy*>(user_data);
std::lock_guard<std::recursive_mutex> lock(proxy->GetMutex());
auto* listener = proxy->listener_;
return G_SOURCE_REMOVE;
}
- int fd = g_io_channel_unix_get_fd(channel);
_W("Socket was disconnected. fd(%d)", fd);
if (proxy->main_port_.get() != nullptr &&
proxy->main_port_->GetFd() == fd) {
return G_SOURCE_REMOVE;;
}
-gboolean Proxy::ProxyPort::OnDataReceived(GIOChannel* channel,
- GIOCondition cond, gpointer user_data) {
+gboolean Proxy::ProxyPort::OnDataReceived(gint fd, GIOCondition cond,
+ gpointer user_data) {
auto* proxy = static_cast<Proxy*>(user_data);
std::lock_guard<std::recursive_mutex> lock(proxy->GetMutex());
auto* listener = proxy->listener_;
return G_SOURCE_REMOVE;
}
- int fd = g_io_channel_unix_get_fd(channel);
if (proxy->delegate_port_->GetFd() == fd) {
char buffer[4];
if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) {
}
Proxy::Client::~Client() {
- if (channel_)
- g_io_channel_unref(channel_);
-
if (disconn_source_ > 0)
g_source_remove(disconn_source_);
}
int Proxy::Client::Watch() {
- channel_ = g_io_channel_unix_new(GetFd());
- if (channel_ == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- return -1;
- }
-
- source_ = g_io_add_watch(channel_, static_cast<GIOCondition>(G_IO_IN),
- Proxy::Client::OnResponseReceived, parent_);
+ source_ = g_unix_fd_add(GetFd(), static_cast<GIOCondition>(G_IO_IN),
+ Proxy::Client::OnResponseReceived, parent_);
if (source_ == 0) {
- _E("g_io_add_watch() is failed");
+ _E("g_unix_fd_add() is failed");
return -1;
}
- disconn_source_ = g_io_add_watch(channel_,
- static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
+ disconn_source_ = g_unix_fd_add(
+ GetFd(), static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
Proxy::Client::OnSocketDisconnected, parent_);
if (disconn_source_ == 0) {
- _E("g_io_add_watch() is failed");
+ _E("g_unix_fd_add() is failed");
return -1;
}
source_ = source;
}
-gboolean Proxy::Client::OnSocketDisconnected(GIOChannel* channel,
- GIOCondition cond, gpointer user_data) {
+gboolean Proxy::Client::OnSocketDisconnected(gint fd, GIOCondition cond,
+ gpointer user_data) {
auto* proxy = static_cast<Proxy*>(user_data);
std::lock_guard<std::recursive_mutex> lock(proxy->GetMutex());
proxy->UnsetConnTimer();
return G_SOURCE_REMOVE;
}
- int fd = g_io_channel_unix_get_fd(channel);
_W("Socket was disconnected. fd(%d)", fd);
if (proxy->main_client_.get() != nullptr &&
proxy->main_client_->GetFd() == fd) {
return G_SOURCE_REMOVE;
}
-gboolean Proxy::Client::OnResponseReceived(GIOChannel* channel,
- GIOCondition cond, gpointer user_data) {
+gboolean Proxy::Client::OnResponseReceived(gint fd, GIOCondition cond,
+ gpointer user_data) {
auto* proxy = static_cast<Proxy*>(user_data);
std::lock_guard<std::recursive_mutex> lock(proxy->GetMutex());
proxy->UnsetConnTimer();
bool is_delegate = false;
std::unique_ptr<Client> client;
- int fd = g_io_channel_unix_get_fd(channel);
if (proxy->main_client_.get() != nullptr &&
proxy->main_client_->GetFd() == fd) {
client.reset(proxy->main_client_.release());
proxy->main_client_.reset();
proxy->delegate_client_.reset();
listener->OnRejected(proxy->target_appid_,
- RPC_PORT_ERROR_PERMISSION_DENIED);
+ RPC_PORT_ERROR_PERMISSION_DENIED);
return G_SOURCE_REMOVE;
}
proxy->delegate_port_.reset(
new ProxyPort(proxy, proxy->fds_[1], proxy->target_appid_));
DebugPort::AddSession(proxy->port_name_, proxy->target_appid_,
- proxy->fds_[0], proxy->fds_[1]);
+ proxy->fds_[0], proxy->fds_[1]);
listener->OnConnected(proxy->target_appid_, proxy->main_port_.get());
_W("target_appid(%s), port_name(%s), main_fd(%d), delegate_fd(%d)",
- proxy->target_appid_.c_str(), proxy->port_name_.c_str(),
- proxy->fds_[0], proxy->fds_[1]);
+ proxy->target_appid_.c_str(), proxy->port_name_.c_str(), proxy->fds_[0],
+ proxy->fds_[1]);
} else {
proxy->fds_[0] = client_fd;
proxy->main_port_.reset(
}
}
-gboolean Stub::AcceptedPort::OnDataReceived(GIOChannel* channel,
- GIOCondition cond, gpointer user_data) {
+gboolean Stub::AcceptedPort::OnDataReceived(gint fd, GIOCondition cond,
+ gpointer user_data) {
auto* stub = static_cast<Stub*>(user_data);
std::lock_guard<std::recursive_mutex> lock(stub->GetMutex());
auto* listener = stub->listener_;
return G_SOURCE_REMOVE;
}
- int fd = g_io_channel_unix_get_fd(channel);
for (auto& p : stub->ports_) {
if (p->GetFd() == fd && !p->IsDelegate()) {
char buffer[4];
return G_SOURCE_CONTINUE;
}
-gboolean Stub::AcceptedPort::OnSocketDisconnected(GIOChannel* channel,
- GIOCondition cond, gpointer user_data) {
+gboolean Stub::AcceptedPort::OnSocketDisconnected(gint fd, GIOCondition cond,
+ gpointer user_data) {
auto* stub = static_cast<Stub*>(user_data);
std::lock_guard<std::recursive_mutex> lock(stub->GetMutex());
auto* listener = stub->listener_;
return G_SOURCE_REMOVE;
}
- int fd = g_io_channel_unix_get_fd(channel);
_W("Socket was disconnected. fd(%d)", fd);
for (auto& p : stub->ports_) {
if (p->GetFd() == fd) {
if (source_ > 0)
g_source_remove(source_);
-
- if (channel_ != nullptr)
- g_io_channel_unref(channel_);
}
int Stub::AcceptedPort::Watch(bool receive) {
- channel_ = g_io_channel_unix_new(GetFd());
- if (channel_ == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- return -1;
- }
-
- disconn_source_ = g_io_add_watch(channel_,
- static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
+ disconn_source_ = g_unix_fd_add(
+ GetFd(), static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
OnSocketDisconnected, parent_);
if (disconn_source_ == 0) {
- _E("g_io_add_watch() is failed");
+ _E("g_unix_fd_add() is failed");
return -1;
}
if (!receive)
return 0;
- source_ = g_io_add_watch(channel_, static_cast<GIOCondition>(G_IO_IN),
- OnDataReceived, parent_);
+ source_ = g_unix_fd_add(GetFd(), static_cast<GIOCondition>(G_IO_IN),
+ OnDataReceived, parent_);
if (source_ == 0) {
- _E("g_io_add_watch() is failed");
+ _E("g_unix_fd_add() is failed");
return -1;
}
}
Stub::Server::~Server() {
- if (channel_)
- g_io_channel_unref(channel_);
-
- if (source_ > 0)
- g_source_remove(source_);
+ if (source_ > 0) g_source_remove(source_);
}
int Stub::Server::Listen() {
- channel_ = g_io_channel_unix_new(GetFd());
- if (channel_ == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- return -1;
- }
-
- source_ = g_io_add_watch(channel_, static_cast<GIOCondition>(G_IO_IN),
- OnRequestReceived, parent_);
+ source_ = g_unix_fd_add(GetFd(), static_cast<GIOCondition>(G_IO_IN),
+ OnRequestReceived, parent_);
if (source_ == 0) {
- _E("g_io_add_watch() is failed");
+ _E("g_unix_fd_add() is failed");
return -1;
}
return 0;
}
-gboolean Stub::Server::OnRequestReceived(GIOChannel* channel, GIOCondition cond,
+gboolean Stub::Server::OnRequestReceived(gint fd, GIOCondition cond,
gpointer user_data) {
auto* stub = static_cast<Stub*>(user_data);
std::lock_guard<std::recursive_mutex> lock(stub->GetMutex());