summaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authortfarina <tfarina@chromium.org>2016-03-14 13:00:24 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-14 20:01:32 +0000
commit3b10a1079a38beda8b73f86352d5867d60d6e6f6 (patch)
treebd26c1ab7d55661ceeefc390ab23d01e22832325 /ipc
parentad879442a66b0b7d1500dd8df0a2d027602c358a (diff)
downloadchromium_src-3b10a1079a38beda8b73f86352d5867d60d6e6f6.zip
chromium_src-3b10a1079a38beda8b73f86352d5867d60d6e6f6.tar.gz
chromium_src-3b10a1079a38beda8b73f86352d5867d60d6e6f6.tar.bz2
ipc: change CreateUnixDomainSocket() to return a bool type
The idea here is that by returning a boolean type, it makes easier for the callers to figure out if the function succeeded or not. By doing this, it also avoids calling is_valid() twice, one in the function and one in the callsites. It also makes it aligned with how we check the other functions: CreateServerUnixDomainSocket() and CreateClientUnixDomainSocket(), as both return bool. It is also clear than checking is_valid() in the callsite rather than checking the return value of the function itself. BUG=None TEST=ipc_tests R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1781423002 Cr-Commit-Position: refs/heads/master@{#381050}
Diffstat (limited to 'ipc')
-rw-r--r--ipc/unix_domain_socket_util.cc27
1 files changed, 16 insertions, 11 deletions
diff --git a/ipc/unix_domain_socket_util.cc b/ipc/unix_domain_socket_util.cc
index 414674c..ee82560 100644
--- a/ipc/unix_domain_socket_util.cc
+++ b/ipc/unix_domain_socket_util.cc
@@ -55,22 +55,27 @@ bool MakeUnixAddrForPath(const std::string& socket_name,
}
// This functions creates a unix domain socket, and set it as non-blocking.
-// Returns a valid socket descriptor on success, or an invalid one otherwise.
-base::ScopedFD CreateUnixDomainSocket() {
- // Create socket.
+// If successful, |out_fd| will be set to the new file descriptor, and the
+// function will return true. Otherwise returns false.
+bool CreateUnixDomainSocket(base::ScopedFD* out_fd) {
+ DCHECK(out_fd);
+
+ // Create the unix domain socket.
base::ScopedFD fd(socket(AF_UNIX, SOCK_STREAM, 0));
if (!fd.is_valid()) {
PLOG(ERROR) << "Failed to create AF_UNIX socket.";
- return base::ScopedFD();
+ return false;
}
- // Make socket non-blocking.
+ // Now set it as non-blocking.
if (!base::SetNonBlocking(fd.get())) {
PLOG(ERROR) << "base::SetNonBlocking() failed " << fd.get();
- return base::ScopedFD();
+ return false;
}
- return fd;
+ fd.swap(*out_fd);
+
+ return true;
}
bool IsRecoverableError() {
@@ -104,8 +109,8 @@ bool CreateServerUnixDomainSocket(const base::FilePath& socket_path,
if (!MakeUnixAddrForPath(socket_name, &unix_addr, &unix_addr_len))
return false;
- base::ScopedFD fd(CreateUnixDomainSocket());
- if (!fd.is_valid())
+ base::ScopedFD fd;
+ if (!CreateUnixDomainSocket(&fd))
return false;
// Bind the socket.
@@ -135,8 +140,8 @@ bool CreateClientUnixDomainSocket(const base::FilePath& socket_path,
if (!MakeUnixAddrForPath(socket_path.value(), &unix_addr, &unix_addr_len))
return false;
- base::ScopedFD fd(CreateUnixDomainSocket());
- if (!fd.is_valid())
+ base::ScopedFD fd;
+ if (!CreateUnixDomainSocket(&fd))
return false;
if (HANDLE_EINTR(connect(fd.get(), reinterpret_cast<sockaddr*>(&unix_addr),