From patchwork Wed Apr 21 05:57:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshiaki Tamura X-Patchwork-Id: 50626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BE2A4B7BEE for ; Wed, 21 Apr 2010 16:41:14 +1000 (EST) Received: from localhost ([127.0.0.1]:52714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4TcV-0004j9-8e for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2010 02:41:11 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4T0p-0003Iq-8J for qemu-devel@nongnu.org; Wed, 21 Apr 2010 02:02:15 -0400 Received: from [140.186.70.92] (port=36874 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4T0W-00037v-MW for qemu-devel@nongnu.org; Wed, 21 Apr 2010 02:02:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4T0B-0006h3-FY for qemu-devel@nongnu.org; Wed, 21 Apr 2010 02:01:53 -0400 Received: from sh.osrg.net ([192.16.179.4]:35925) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4T09-0006e1-A2 for qemu-devel@nongnu.org; Wed, 21 Apr 2010 02:01:33 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id o3L61QE1004098; Wed, 21 Apr 2010 15:01:26 +0900 Received: from localhost (hype-wd0.osrg.net [10.72.1.16]) by fs.osrg.net (Postfix) with ESMTP id 33C7E3E02F8; Wed, 21 Apr 2010 15:01:25 +0900 (JST) From: Yoshiaki Tamura To: kvm@vger.kernel.org, qemu-devel@nongnu.org Date: Wed, 21 Apr 2010 14:57:16 +0900 Message-Id: <1271829445-5328-12-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.0.31.g1df487 In-Reply-To: <1271829445-5328-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1271829445-5328-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 97 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Wed, 21 Apr 2010 15:01:26 +0900 (JST) X-Virus-Scanned: clamav-milter 0.95.3 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: aliguori@us.ibm.com, ohmura.kei@lab.ntt.co.jp, mtosatti@redhat.com, Yoshiaki Tamura , yoshikawa.takuya@oss.ntt.co.jp, avi@redhat.com Subject: [Qemu-devel] [RFC PATCH 11/20] Introduce some socket util functions. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Yoshiaki Tamura --- osdep.c | 13 +++++++++++++ qemu-char.c | 25 ++++++++++++++++++++++++- qemu_socket.h | 4 ++++ 3 files changed, 41 insertions(+), 1 deletions(-) diff --git a/osdep.c b/osdep.c index 3bab79a..63444e7 100644 --- a/osdep.c +++ b/osdep.c @@ -201,6 +201,12 @@ void socket_set_nonblock(int fd) ioctlsocket(fd, FIONBIO, &opt); } +void socket_set_block(int fd) +{ + unsigned long opt = 0; + ioctlsocket(fd, FIONBIO, &opt); +} + int inet_aton(const char *cp, struct in_addr *ia) { uint32_t addr = inet_addr(cp); @@ -223,6 +229,13 @@ void socket_set_nonblock(int fd) fcntl(fd, F_SETFL, f | O_NONBLOCK); } +void socket_set_block(int fd) +{ + int f; + f = fcntl(fd, F_GETFL); + fcntl(fd, F_SETFL, f & ~O_NONBLOCK); +} + void qemu_set_cloexec(int fd) { int f; diff --git a/qemu-char.c b/qemu-char.c index 4169492..ccdf394 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2092,12 +2092,35 @@ static void tcp_chr_telnet_init(int fd) send(fd, (char *)buf, 3, 0); } -static void socket_set_nodelay(int fd) +void socket_set_delay(int fd) +{ + int val = 0; + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val)); +} + +void socket_set_nodelay(int fd) { int val = 1; setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val)); } +void socket_set_timeout(int fd, int s) +{ + struct timeval tv = { + .tv_sec = s, + .tv_usec = 0 + }; + /* Set socket_timeout */ + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, + &tv, sizeof(tv)) < 0) { + fprintf(stderr, "failed to set SO_RCVTIMEO\n"); + } + if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, + &tv, sizeof(tv)) < 0) { + fprintf(stderr, "fialed to set SO_SNDTIMEO\n"); + } +} + static void tcp_chr_accept(void *opaque) { CharDriverState *chr = opaque; diff --git a/qemu_socket.h b/qemu_socket.h index 7ee46ac..8eae465 100644 --- a/qemu_socket.h +++ b/qemu_socket.h @@ -35,6 +35,10 @@ int inet_aton(const char *cp, struct in_addr *ia); int qemu_socket(int domain, int type, int protocol); int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); void socket_set_nonblock(int fd); +void socket_set_block(int fd); +void socket_set_nodelay(int fd); +void socket_set_delay(int fd); +void socket_set_timeout(int fd, int s); int send_all(int fd, const void *buf, int len1); /* New, ipv6-ready socket helper functions, see qemu-sockets.c */