From patchwork Wed Aug 24 09:40:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12953215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 818B1C00140 for ; Wed, 24 Aug 2022 10:31:20 +0000 (UTC) Received: from localhost ([::1]:56818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQnfL-0001HW-Ee for qemu-devel@archiver.kernel.org; Wed, 24 Aug 2022 06:31:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQmuP-00046t-O0 for qemu-devel@nongnu.org; Wed, 24 Aug 2022 05:42:50 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:41956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQmuO-0001bT-0Y for qemu-devel@nongnu.org; Wed, 24 Aug 2022 05:42:49 -0400 Received: by mail-pg1-x533.google.com with SMTP id 202so14542886pgc.8 for ; Wed, 24 Aug 2022 02:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=IfI/qWhUWiZQhG5XwWjV6xjarmHg12V73Blb6zZFpuQ=; b=lgIvNYS2uxagdXZauE9C99i9XdDYqd8KPAc1aWEHEl3QH9uGAj8wgzNykpP7DX0YqY 2dE5eJBC9O5CBWv7EJpLMcAVgqCbzQ8bz3m4MEiqbBr1KnkOwxT3sz8Yw70UJ7WNtsSz 31CuFlzqfgxQkQ6jdHUxfZhQmwkGiLyBdnezlzyDeJoNIwFRQHoyUd3zfAbwPmyqcEjJ D+dAeGva2CA5hZ54wRfOunVGapRIkhtNzrzB8QgAE+tQu2/SPMk9R1fR4hfB0uGFBw2t lAndgigtdIBo24kYN/5FxUZQpu/VAXhH1/lLRswBCZTFuy0fgFUAf4hXiuBk2X77xKTn j3Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=IfI/qWhUWiZQhG5XwWjV6xjarmHg12V73Blb6zZFpuQ=; b=kP4xGPpnuDqoy3H3j1rpXPV49UrjfS/rjeaLbi9HGv31ehdDKfi/pGrqy+yJBvy2Cn 0AqPha+yZ2RZ9SFnpACRxpPXzptitilGJLns+qk3T5D7mi9YNBd1kcCNBXkNx0E9YVKf b7LR4DgrIbKyvHJ/J4p2Yd5eFhD11s/5VcT8pQnp24py/pOFGf1NgFp3tSa3QlSUARvm ili3KJQ6ZZkK/qryVHjyCalVXA1lZuXoTwgGnwez1u/7rUM/yQuA4o3nISRkgWvqJ7/J Z7yHKkWGaqUnAtiDUHDPe0ut2oFyMVLgo1a316IsButDkMOcHSIlbZkPapxIpLhmHmXF 0Odg== X-Gm-Message-State: ACgBeo0O4eFTyluYeXR9Om9vTZR78TaLZB32yovel4Y6O6GcLeduztxN 0uGCRyE+fWPoB/B86bKBbWOgmrLfBVM= X-Google-Smtp-Source: AA6agR5sJ9C0HFPuKJAG/c6z7BkLhItFVTK2K80PhDjyHaoJLFMEwWfHP7cOEBwuVq2W0Jw+keLmNw== X-Received: by 2002:a05:6a00:1410:b0:528:5a5a:d846 with SMTP id l16-20020a056a00141000b005285a5ad846mr29523999pfu.9.1661334166406; Wed, 24 Aug 2022 02:42:46 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id b14-20020a170903228e00b001728eb339e2sm12165972plh.286.2022.08.24.02.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 02:42:46 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org Cc: Xuzhou Cheng , Bin Meng , Laurent Vivier , Paolo Bonzini , Thomas Huth Subject: [PATCH 27/51] tests/qtest: Use send/recv for socket communication Date: Wed, 24 Aug 2022 17:40:05 +0800 Message-Id: <20220824094029.1634519-28-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220824094029.1634519-1-bmeng.cn@gmail.com> References: <20220824094029.1634519-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Xuzhou Cheng Socket communication in the libqtest and libqmp codes uses read() and write() which work on any file descriptor on *nix, and sockets in *nix are an example of a file descriptor. However sockets on Windows do not use *nix-style file descriptors, so read() and write() cannot be used on sockets on Windows. Switch over to use send() and recv() instead which work on both Windows and *nix. Signed-off-by: Xuzhou Cheng Signed-off-by: Bin Meng --- tests/qtest/libqmp.c | 4 ++-- tests/qtest/libqtest.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c index ade26c15f0..995a39c1f8 100644 --- a/tests/qtest/libqmp.c +++ b/tests/qtest/libqmp.c @@ -36,7 +36,7 @@ typedef struct { static void socket_send(int fd, const char *buf, size_t size) { - size_t res = qemu_write_full(fd, buf, size); + ssize_t res = send(fd, buf, size, 0); assert(res == size); } @@ -69,7 +69,7 @@ QDict *qmp_fd_receive(int fd) ssize_t len; char c; - len = read(fd, &c, 1); + len = recv(fd, &c, 1, 0); if (len == -1 && errno == EINTR) { continue; } diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 909583dad3..b7b7c9c541 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -438,7 +438,7 @@ void qtest_quit(QTestState *s) static void socket_send(int fd, const char *buf, size_t size) { - size_t res = qemu_write_full(fd, buf, size); + ssize_t res = send(fd, buf, size, 0); assert(res == size); } @@ -470,7 +470,7 @@ static GString *qtest_client_socket_recv_line(QTestState *s) ssize_t len; char buffer[1024]; - len = read(s->fd, buffer, sizeof(buffer)); + len = recv(s->fd, buffer, sizeof(buffer), 0); if (len == -1 && errno == EINTR) { continue; }