From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Baines Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Define SO_RCVTIMEO and SO_SNDTIMEO. Date: Sat, 17 Sep 2022 10:05:12 +0200 Message-ID: <20220917080512.17824-1-mail@cbaines.net> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34969"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Sep 17 10:11:09 2022 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oZSuq-0008zY-QA for guile-devel@m.gmane-mx.org; Sat, 17 Sep 2022 10:11:08 +0200 Original-Received: from localhost ([::1]:46568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZSup-0005rN-O8 for guile-devel@m.gmane-mx.org; Sat, 17 Sep 2022 04:11:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZSpE-0002mU-Hi for guile-devel@gnu.org; Sat, 17 Sep 2022 04:05:20 -0400 Original-Received: from mira.cbaines.net ([212.71.252.8]:36730) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZSpB-00014n-6D for guile-devel@gnu.org; Sat, 17 Sep 2022 04:05:19 -0400 Original-Received: from localhost (unknown [134.157.22.165]) by mira.cbaines.net (Postfix) with ESMTPSA id BE5D027BBE9 for ; Sat, 17 Sep 2022 09:05:14 +0100 (BST) Original-Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id c581a91a for ; Sat, 17 Sep 2022 08:05:12 +0000 (UTC) X-Mailer: git-send-email 2.37.3 Received-SPF: pass client-ip=212.71.252.8; envelope-from=mail@cbaines.net; helo=mira.cbaines.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:21350 Archived-At: These are important for reliable networking, since they prevent network operations from hanging indefinitely. * libguile/socket.c (scm_init_socket): Define SO_RCVTIMEO and SO_SNDTIMEO. (scm_getsockopt): Include SO_RCVTIMEO and SO_SNDTIMEO in docstring. (scm_setsockopt): Include SO_RCVTIMEO and SO_SNDTIMEO in docstring and handle these operations. * doc/ref/posix.texi (Network Sockets and Communication): Document them. --- doc/ref/posix.texi | 2 ++ libguile/socket.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index 19911a427..5c7dce90d 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -3229,6 +3229,8 @@ Manual}, or @command{man 7 socket}. @defvarx SO_NO_CHECK @defvarx SO_PRIORITY @defvarx SO_REUSEPORT +@defvarx SO_RCVTIMEO +@defvarx SO_SNDTIMEO The @var{value} taken or returned is an integer. @end defvar diff --git a/libguile/socket.c b/libguile/socket.c index b3482c8f3..547dd1d83 100644 --- a/libguile/socket.c +++ b/libguile/socket.c @@ -35,6 +35,7 @@ #endif #include #include +#include #ifdef HAVE_WINSOCK2_H #include @@ -493,6 +494,8 @@ SCM_DEFINE (scm_getsockopt, "getsockopt", 3, 0, 0, "@defvarx SO_NO_CHECK\n" "@defvarx SO_PRIORITY\n" "@defvarx SO_REUSEPORT\n" + "@defvarx SO_RCVTIMEO\n" + "@defvarx SO_SNDTIMEO\n" "The value returned is an integer.\n" "@end defvar\n" "\n" @@ -581,6 +584,8 @@ SCM_DEFINE (scm_setsockopt, "setsockopt", 4, 0, 0, "@defvarx SO_NO_CHECK\n" "@defvarx SO_PRIORITY\n" "@defvarx SO_REUSEPORT\n" + "@defvarx SO_RCVTIMEO\n" + "@defvarx SO_SNDTIMEO\n" "@var{value} is an integer.\n" "@end defvar\n" "\n" @@ -633,6 +638,8 @@ SCM_DEFINE (scm_setsockopt, "setsockopt", 4, 0, 0, struct ip_mreq opt_mreq; #endif + struct timeval opt_time; + const void *optval = NULL; socklen_t optlen = 0; @@ -682,6 +689,17 @@ SCM_DEFINE (scm_setsockopt, "setsockopt", 4, 0, 0, } #endif + if (ioptname == SO_RCVTIMEO || ioptname == SO_SNDTIMEO) + { + SCM_ASSERT (scm_is_pair (value), value, SCM_ARG4, FUNC_NAME); + + opt_time.tv_sec = scm_to_ulong (SCM_CAR (value)); + opt_time.tv_usec = scm_to_ulong (SCM_CDR (value)); + + optlen = sizeof (opt_time); + optval = &opt_time; + } + if (optval == NULL) { /* Most options take an int. */ @@ -1768,6 +1786,12 @@ scm_init_socket () #ifdef SO_REUSEPORT /* new in Linux 3.9 */ scm_c_define ("SO_REUSEPORT", scm_from_int (SO_REUSEPORT)); #endif +#ifdef SO_RCVTIMEO + scm_c_define ("SO_RCVTIMEO", scm_from_int (SO_RCVTIMEO)); +#endif +#ifdef SO_SNDTIMEO + scm_c_define ("SO_SNDTIMEO", scm_from_int (SO_SNDTIMEO)); +#endif /* recv/send options. */ #ifdef MSG_DONTWAIT -- 2.37.3