diff options
author | 2016-01-26 12:01:18 +0000 | |
---|---|---|
committer | 2016-01-26 13:06:28 +0000 | |
commit | 96d3b9682e3313c5fdc1e575c22aa286336fb2b2 (patch) | |
tree | 5d87b0dc4833db95e13df90fc3fa9994c00d8926 /src | |
parent | 546c265ba453008d302a6c73acefc22dbcd6d6e1 (diff) |
cpp: make callsites of Connect() function more readable
The consumers of Connect() function are just interested in knowning if
it has connected or not ("Did we connect?"). Leave the check for zero as
implementation detail of this function, making the callsites not having
to repeat the condition themselves.
--
Change-Id: Idc327c681c5defbb27039cd170f32d5ebd0e0a32
Reviewed-on: https://bazel-review.googlesource.com/#/c/2750/
MOS_MIGRATED_REVID=113040325
Diffstat (limited to 'src')
-rw-r--r-- | src/main/cpp/blaze.cc | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index e29790cee0..4a4c19988e 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -531,7 +531,8 @@ static void StartStandalone() { // resolving symbolic links. (The server may make "socket_file" a // symlink, to avoid ENAMETOOLONG, in which case the client must // resolve it in userspace before connecting.) -static int Connect(int socket, const string &socket_file) { +// Returns true on success, false otherwise. +static bool Connect(int socket, const string &socket_file) { struct sockaddr_un addr; addr.sun_family = AF_UNIX; @@ -541,14 +542,14 @@ static int Connect(int socket, const string &socket_file) { addr.sun_path[sizeof addr.sun_path - 1] = '\0'; free(resolved_path); sockaddr *paddr = reinterpret_cast<sockaddr *>(&addr); - return connect(socket, paddr, sizeof addr); + return connect(socket, paddr, sizeof addr) == 0; } else if (errno == ENOENT) { // No socket means no server to connect to errno = ECONNREFUSED; - return -1; + return false; } else { pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "realpath('%s') failed", socket_file.c_str()); - return -1; + return false; } } @@ -612,7 +613,7 @@ static int ConnectToServer(bool start) { string pid_file = server_dir + "/server.pid"; globals->server_pid = 0; - if (Connect(s, socket_file) == 0) { + if (Connect(s, socket_file)) { GetServerPid(s, pid_file); return s; } @@ -628,13 +629,13 @@ static int ConnectToServer(bool start) { // Give the server one minute to start up. for (int ii = 0; ii < 600; ++ii) { // 60s; enough time to connect // with debugger - if (Connect(s, socket_file) == 0) { - if (ii) { - fputc('\n', stderr); - fflush(stderr); - } - GetServerPid(s, pid_file); - return s; + if (Connect(s, socket_file)) { + if (ii) { + fputc('\n', stderr); + fflush(stderr); + } + GetServerPid(s, pid_file); + return s; } fputc('.', stderr); fflush(stderr); |