If the socket connection is invalid, the event may continue to occur.
In this case, the event handler is removed to prevent unnecessary event reception.
Change-Id: I63851ac57b6f0820229ae4c0548af88988915061
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
listener->OnSocketDisconnected(fd);
} else if (cond & G_IO_IN) {
- listener->OnDataReceived(fd);
+ if (!listener->OnDataReceived(fd)) {
+ accepted_port->source_ = nullptr;
+ return G_SOURCE_REMOVE;
+ }
}
return G_SOURCE_CONTINUE;
class IEvent {
public:
virtual ~IEvent() = default;
- virtual void OnDataReceived(int fd) = 0;
+ virtual bool OnDataReceived(int fd) = 0;
virtual void OnSocketDisconnected(int fd) = 0;
};
if (!channel->listener_) return G_SOURCE_REMOVE;
auto* listener = channel->listener_;
- if (cond & G_IO_IN)
- listener->OnResponseReceived(fd);
- else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
+ if (cond & G_IO_IN) {
+ if (!listener->OnResponseReceived(fd)) {
+ channel->source_ = nullptr;
+ return G_SOURCE_REMOVE;
+ }
+ } else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
listener->OnChannelDisconnected(fd);
+ }
return G_SOURCE_CONTINUE;
}
public:
virtual ~IEvent() = default;
virtual void OnChannelDisconnected(int fd) = 0;
- virtual void OnResponseReceived(int fd) = 0;
+ virtual bool OnResponseReceived(int fd) = 0;
};
explicit ClientChannel(IEvent* listener);
DebugPort::RemoveSession(fd);
}
-void Proxy::OnDataReceived(int fd) {
+bool Proxy::OnDataReceived(int fd) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
auto* listener = listener_;
if (listener == nullptr) {
// LCOV_EXCL_START
_E("Invalid context");
- return;
+ return false;
// LCOV_EXCL_STOP
}
- if (!delegate_port_ || delegate_port_->GetReadFd() != fd) return;
+ if (!delegate_port_ || delegate_port_->GetReadFd() != fd) return false;
char buffer[4];
if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) {
DebugPort::RemoveSession(fd);
main_port_.reset();
}
- return;
+ return true;
}
listener->OnReceived(target_appid_);
+ return true;
}
// LCOV_EXCL_START
}
// LCOV_EXCL_STOP
-void Proxy::OnResponseReceived(int fd) {
+bool Proxy::OnResponseReceived(int fd) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
UnsetConnTimer();
if (listener_ == nullptr) { // LCOV_EXCL_START
_E("Invalid context");
- return;
+ return false;
} // LCOV_EXCL_STOP
bool is_read = false;
std::unique_ptr<ClientChannel> client = GetClient(fd, &is_read, &is_delegate);
if (!client) { // LCOV_EXCL_START
_E("Unknown fd(%d)", fd);
- return;
+ return false;
} // LCOV_EXCL_STOP
Response response;
delegate_client_[0].reset();
delegate_client_[1].reset();
listener->OnRejected(target_appid_, RPC_PORT_ERROR_PERMISSION_DENIED);
- return;
+ return true;
}
client->SetNonblock();
int client_fd = client->RemoveFd();
SetPort(client_fd, is_read, is_delegate);
+ return true;
}
std::shared_ptr<Proxy> Proxy::GetSharedPtr() { return shared_from_this(); }
void OnFileCreated(const std::string& path) override;
void OnFileDeleted(const std::string& path) override;
void OnChannelDisconnected(int fd) override;
- void OnResponseReceived(int fd) override;
+ bool OnResponseReceived(int fd) override;
void OnSocketDisconnected(int fd) override;
- void OnDataReceived(int fd) override;
+ bool OnDataReceived(int fd) override;
static gboolean OnTimedOut(gpointer user_data);
static gboolean OnIdle(gpointer user_data);
if (!proxy_port->listener_) return G_SOURCE_REMOVE;
auto* listener = proxy_port->listener_;
- if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
+ if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
listener->OnSocketDisconnected(fd);
- else if (cond & G_IO_IN)
- listener->OnDataReceived(fd);
+ } else if (cond & G_IO_IN) {
+ if (!listener->OnDataReceived(fd)) {
+ proxy_port->source_ = nullptr;
+ return G_SOURCE_REMOVE;
+ }
+ }
return G_SOURCE_CONTINUE;
}
class IEvent {
public:
virtual ~IEvent() = default;
- virtual void OnDataReceived(int fd) = 0;
+ virtual bool OnDataReceived(int fd) = 0;
virtual void OnSocketDisconnected(int fd) = 0;
};
auto* stub = static_cast<::StubExt*>(h);
*has_request = stub->HasPendingRequest();
return RPC_PORT_ERROR_NONE;
-}
\ No newline at end of file
+}
gpointer user_data) {
auto* server = static_cast<Server*>(user_data);
auto* listener = server->listener_;
- if (listener) listener->OnRequestReceived(fd);
+ if (listener) {
+ bool ret = listener->OnRequestReceived(fd);
+ if (!ret) {
+ GLib::SourceDestroy(server->source_);
+ server->source_ = nullptr;
+ }
+ }
return G_SOURCE_CONTINUE;
}
class IEvent {
public:
virtual ~IEvent() = default;
- virtual void OnRequestReceived(int fd) = 0;
+ virtual bool OnRequestReceived(int fd) = 0;
};
Server(int fd, IEvent* listener);
GMainContext* Stub::GetMainContext() const { return context_; }
-void Stub::OnDataReceived(int fd) {
+bool Stub::OnDataReceived(int fd) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
if (listener_ == nullptr) {
// LCOV_EXCL_START
_E("Invalid context");
- return;
+ return false;
// LCOV_EXCL_STOP
}
listener_->OnDisconnected(p->GetId(), p->GetInstance());
RemoveAcceptedPorts(p->GetInstance());
Aul::NotifyRpcFinished();
- return;
+ return true;
}
int ret = listener_->OnReceived(p->GetId(), p->GetInstance(), p.get());
listener_->OnDisconnected(p->GetId(), p->GetInstance());
RemoveAcceptedPorts(p->GetInstance());
Aul::NotifyRpcFinished();
- return;
+ return true;
}
break;
}
}
+
+ return true;
}
void Stub::OnSocketDisconnected(gint fd) {
response_func(res);
}
-void Stub::OnRequestReceived(gint fd) {
+bool Stub::OnRequestReceived(gint fd) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
if (listener_ == nullptr) {
// LCOV_EXCL_START
_E("Invalid context");
- return;
+ return false;
// LCOV_EXCL_STOP
}
if (!client) {
// LCOV_EXCL_START
_E("Out of memory");
- return;
+ return false;
// LCOV_EXCL_STOP
}
auto request = std::make_shared<Request>();
int ret = client->Receive(request.get());
- if (ret != 0) return; // LCOV_EXCL_LINE
+ if (ret != 0) return false; // LCOV_EXCL_LINE
std::shared_ptr<PeerCred> cred(PeerCred::Get(client->GetFd()));
if (!cred) {
// LCOV_EXCL_START
_E("Failed to create peer credentials");
- return;
+ return false;
// LCOV_EXCL_STOP
}
CheckPermission(request, client, cred);
+ return true;
}
} // namespace internal
void CheckPermission(const std::shared_ptr<Request>& request,
const std::shared_ptr<ClientSocket>& client,
const std::shared_ptr<PeerCred>& cred);
- void OnRequestReceived(int fd) override;
+ bool OnRequestReceived(int fd) override;
void OnSocketDisconnected(int fd) override;
- void OnDataReceived(int fd) override;
+ bool OnDataReceived(int fd) override;
private:
std::shared_ptr<AccessController> access_controller_ =