From b0e98718f5b167ea6cc421859a6ec2df4a530dc6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 24 Apr 2016 00:42:11 +0900 Subject: [PATCH] src: Handle return value of getsockopt --- src/util.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/util.cc b/src/util.cc index 9139872d..c17f04ae 100644 --- a/src/util.cc +++ b/src/util.cc @@ -882,12 +882,11 @@ int create_nonblock_socket(int family) { bool check_socket_connected(int fd) { int error; socklen_t len = sizeof(error); - if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) == 0) { - if (error != 0) { - return false; - } + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0) { + return false; } - return true; + + return error == 0; } bool ipv6_numeric_addr(const char *host) {