From patchwork Fri Dec 22 13:45:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10130515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 63F7E60318 for ; Fri, 22 Dec 2017 13:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 567E229415 for ; Fri, 22 Dec 2017 13:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B5AA2953B; Fri, 22 Dec 2017 13:47:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E18C429415 for ; Fri, 22 Dec 2017 13:47:28 +0000 (UTC) Received: from localhost ([::1]:51152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSNfc-0007Xe-50 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Dec 2017 08:47:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSNe2-0006Eq-TN for qemu-devel@nongnu.org; Fri, 22 Dec 2017 08:45:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSNe2-0002nQ-0x for qemu-devel@nongnu.org; Fri, 22 Dec 2017 08:45:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33524) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSNe1-0002mS-QW for qemu-devel@nongnu.org; Fri, 22 Dec 2017 08:45:49 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E60EC72D88 for ; Fri, 22 Dec 2017 13:45:48 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 202A117CF4; Fri, 22 Dec 2017 13:45:46 +0000 (UTC) From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 13:45:21 +0000 Message-Id: <20171222134527.14467-3-berrange@redhat.com> In-Reply-To: <20171222134527.14467-1-berrange@redhat.com> References: <20171222134527.14467-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 22 Dec 2017 13:45:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/8] sockets: move fd_is_socket() into common sockets code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Dr. David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The fd_is_socket() helper method is useful in a few places, so put it in the common sockets code. Make the code more compact while moving it. Signed-off-by: Daniel P. Berrange Reviewed-by: Marc-André Lureau --- include/qemu/sockets.h | 1 + io/channel-util.c | 13 ------------- util/qemu-sockets.c | 8 ++++++++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 4f7311b52a..5680880f5a 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -12,6 +12,7 @@ int inet_aton(const char *cp, struct in_addr *ia); #include "qapi-types.h" /* misc helpers */ +bool fd_is_socket(int fd); int qemu_socket(int domain, int type, int protocol); int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int socket_set_cork(int fd, int v); diff --git a/io/channel-util.c b/io/channel-util.c index 0fb4bd0837..423d79845a 100644 --- a/io/channel-util.c +++ b/io/channel-util.c @@ -24,19 +24,6 @@ #include "io/channel-socket.h" -static bool fd_is_socket(int fd) -{ - int optval; - socklen_t optlen; - optlen = sizeof(optval); - return qemu_getsockopt(fd, - SOL_SOCKET, - SO_TYPE, - (char *)&optval, - &optlen) == 0; -} - - QIOChannel *qio_channel_new_fd(int fd, Error **errp) { diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index af4f01211a..5e42f6d88d 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -91,6 +91,14 @@ NetworkAddressFamily inet_netfamily(int family) return NETWORK_ADDRESS_FAMILY_UNKNOWN; } +bool fd_is_socket(int fd) +{ + int optval; + socklen_t optlen = sizeof(optval); + return !qemu_getsockopt(fd, SOL_SOCKET, SO_TYPE, &optval, &optlen); +} + + /* * Matrix we're trying to apply *