From: Hwankyu Jhun Date: Thu, 4 Apr 2024 07:24:32 +0000 (+0900) Subject: Change socket mode before watching it X-Git-Tag: accepted/tizen/8.0/unified/20240405.142121~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ba4ea6e6650b8b0e40c3e89b8ef6fd39d0a13d9;p=platform%2Fcore%2Fappfw%2Frpc-port.git Change socket mode before watching it Before watching the fd, the fd should be non-blocking mode. If it's not, it can make blocking the thread. Change-Id: I46c2f7e094228b239dd193cf2dd04cfe2b926637 Signed-off-by: Hwankyu Jhun --- diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index c35ff8c..265a010 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -70,23 +70,33 @@ int SendRequest(ClientSocket* client, const Request& request) { } int ReceiveResponse(ClientSocket* client, Response** response) { + int flags = fcntl(client->GetFd(), F_GETFL, 0); + fcntl(client->GetFd(), F_SETFL, flags & ~O_NONBLOCK); + size_t size = 0; int ret = client->Receive(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { - _E("Receive() is failed. error(%d)", ret); // LCOV_EXCL_LINE - return -1; // LCOV_EXCL_LINE + // LCOV_EXCL_START + _E("Receive() is failed. error(%d)", ret); + fcntl(client->GetFd(), F_SETFL, flags); + return -1; + // LCOV_EXCL_STOP } uint8_t* buf = static_cast(malloc(size)); if (buf == nullptr) { - _E("Out of memory"); // LCOV_EXCL_LINE - return -1; // LCOV_EXCL_LINE + // LCOV_EXCL_START + _E("Out of memory"); + fcntl(client->GetFd(), F_SETFL, flags); + return -1; + // LCOV_EXCL_STOP } ret = client->Receive(buf, size); if (ret != 0) { // LCOV_EXCL_START _E("Receive() is failed. error(%d)", ret); + fcntl(client->GetFd(), F_SETFL, flags); free(buf); return -1; // LCOV_EXCL_STOP @@ -95,10 +105,14 @@ int ReceiveResponse(ClientSocket* client, Response** response) { tizen_base::Parcel parcel(buf, size, false); *response = new (std::nothrow) Response(); if (*response == nullptr) { - _E("Out of memory"); // LCOV_EXCL_LINE - return -1; // LCOV_EXCL_LINE + // LCOV_EXCL_START + _E("Out of memory"); + fcntl(client->GetFd(), F_SETFL, flags); + return -1; + // LCOV_EXCL_STOP } + fcntl(client->GetFd(), F_SETFL, flags); parcel.ReadParcelable(*response); return 0; } @@ -155,6 +169,7 @@ int Proxy::Connect(bool sync) { main_client_->SetNonblock(); fds_[0] = main_client_->RemoveFd(); } else { + main_client_->SetNonblock(); ret = main_client_->Watch(); if (ret != 0) return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE @@ -185,6 +200,7 @@ int Proxy::Connect(bool sync) { delegate_client_->SetNonblock(); fds_[1] = delegate_client_->RemoveFd(); } else { + delegate_client_->SetNonblock(); ret = delegate_client_->Watch(); if (ret != 0) return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE