* [PATCH] Define SO_RCVTIMEO and SO_SNDTIMEO.
@ 2022-09-17 8:05 Christopher Baines
2022-09-17 9:40 ` Maxime Devos
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Christopher Baines @ 2022-09-17 8:05 UTC (permalink / raw)
To: guile-devel
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 <unistd.h>
#include <sys/types.h>
+#include <sys/time.h>
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
@@ -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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Define SO_RCVTIMEO and SO_SNDTIMEO.
2022-09-17 8:05 [PATCH] Define SO_RCVTIMEO and SO_SNDTIMEO Christopher Baines
@ 2022-09-17 9:40 ` Maxime Devos
2022-09-18 14:11 ` Christopher Baines
2022-09-18 13:56 ` [PATCH v2] " Christopher Baines
2022-09-18 14:17 ` [PATCH v3] " Christopher Baines
2 siblings, 1 reply; 7+ messages in thread
From: Maxime Devos @ 2022-09-17 9:40 UTC (permalink / raw)
To: Christopher Baines, guile-devel
[-- Attachment #1.1.1: Type: text/plain, Size: 1450 bytes --]
On 17-09-2022 10:05, Christopher Baines wrote:
> + if (ioptname == SO_RCVTIMEO || ioptname == SO_SNDTIMEO)
> + {
> + SCM_ASSERT (scm_is_pair (value), value, SCM_ARG4, FUNC_NAME);
How about using SCM_ASSERT_TYPE instead to improve the error message a
little?
> + opt_time.tv_sec = scm_to_ulong (SCM_CAR (value));
> + opt_time.tv_usec = scm_to_ulong (SCM_CDR (value));
I think it needs to be documented how to actually use SO_RCVTIMEO /
SO_SNDTIMEO (more specifically, the types). For example, the user might
expect to enter flonums 1.567 as time durations (in seconds) instead, or
a duration from SRFI 19. How is the user supposed to know the
appropriate type, aside from experimenting and reading the source code?
Also, it is not documented there is a maximum on the number of seconds,
I recommend to document that there is some limit, or alternatively clip
numbers to the maximum.
> + optlen = sizeof (opt_time);
> + optval = &opt_time;
> + }
> +
I think this needs a #if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO),
for systems that don't have those. Alternatively, if all systems have
those, it seems to me that the #ifdef in
> +#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
can be removed.
Greetings,
Maxime.
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] Define SO_RCVTIMEO and SO_SNDTIMEO.
2022-09-17 8:05 [PATCH] Define SO_RCVTIMEO and SO_SNDTIMEO Christopher Baines
2022-09-17 9:40 ` Maxime Devos
@ 2022-09-18 13:56 ` Christopher Baines
2022-09-18 14:17 ` [PATCH v3] " Christopher Baines
2 siblings, 0 replies; 7+ messages in thread
From: Christopher Baines @ 2022-09-18 13:56 UTC (permalink / raw)
To: guile-devel
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 | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 36 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..0c6e1078e 100644
--- a/libguile/socket.c
+++ b/libguile/socket.c
@@ -35,6 +35,7 @@
#endif
#include <unistd.h>
#include <sys/types.h>
+#include <sys/time.h>
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
@@ -502,6 +503,12 @@ SCM_DEFINE (scm_getsockopt, "getsockopt", 3, 0, 0,
"timeout support (ie.@: without @code{struct linger}), only\n"
"@var{enable} has an effect but the value in Guile is always a\n"
"pair.\n"
+ "@end defvar"
+ "\n"
+ "@defvar SO_RCVTIMEO\n"
+ "@defvarx SO_SNDTIMEO\n"
+ "@var{value} is a pair of integers @code{(@var{SECONDS}\n"
+ ". @var{MICROSECONDS})}.\n"
"@end defvar")
#define FUNC_NAME s_scm_getsockopt
{
@@ -590,6 +597,12 @@ SCM_DEFINE (scm_setsockopt, "setsockopt", 4, 0, 0,
"(ie.@: without @code{struct linger}), only @var{ENABLE} has an\n"
"effect but the value in Guile is always a pair.\n"
"@end defvar\n"
+ "\n"
+ "@defvar SO_RCVTIMEO\n"
+ "@defvarx SO_SNDTIMEO\n"
+ "@var{value} is a pair of integers @code{(@var{SECONDS}\n"
+ ". @var{MICROSECONDS})}.\n"
+ "@end defvar\n"
"\n"
"@c Note that we refer only to ``man ip'' here. On GNU/Linux it's\n"
"@c ``man 7 ip'' but on NetBSD it's ``man 4 ip''.\n"
@@ -633,6 +646,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 +697,19 @@ SCM_DEFINE (scm_setsockopt, "setsockopt", 4, 0, 0,
}
#endif
+#if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO)
+ if (ioptname == SO_RCVTIMEO || ioptname == SO_SNDTIMEO)
+ {
+ SCM_ASSERT_TYPE (scm_is_pair (value), value, SCM_ARG4, FUNC_NAME,
+ "value");
+ 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;
+ }
+#endif
+
if (optval == NULL)
{
/* Most options take an int. */
@@ -1768,6 +1796,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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Define SO_RCVTIMEO and SO_SNDTIMEO.
2022-09-17 9:40 ` Maxime Devos
@ 2022-09-18 14:11 ` Christopher Baines
0 siblings, 0 replies; 7+ messages in thread
From: Christopher Baines @ 2022-09-18 14:11 UTC (permalink / raw)
To: Maxime Devos; +Cc: guile-devel
[-- Attachment #1: Type: text/plain, Size: 1825 bytes --]
Thanks for the feedback Maxime, I obviously lost track of some things
after letting this patch languish for a while.
Maxime Devos <maximedevos@telenet.be> writes:
> On 17-09-2022 10:05, Christopher Baines wrote:
>> + if (ioptname == SO_RCVTIMEO || ioptname == SO_SNDTIMEO)
>> + {
>> + SCM_ASSERT (scm_is_pair (value), value, SCM_ARG4, FUNC_NAME);
>
> How about using SCM_ASSERT_TYPE instead to improve the error message a
> little?
I've switched to using SCM_ASSERT_TYPE now.
>> + opt_time.tv_sec = scm_to_ulong (SCM_CAR (value));
>> + opt_time.tv_usec = scm_to_ulong (SCM_CDR (value));
> I think it needs to be documented how to actually use SO_RCVTIMEO /
> SO_SNDTIMEO (more specifically, the types). For example, the user
> might expect to enter flonums 1.567 as time durations (in seconds)
> instead, or a duration from SRFI 19. How is the user supposed to know
> the appropriate type, aside from experimenting and reading the source
> code?
>
> Also, it is not documented there is a maximum on the number of
> seconds, I recommend to document that there is some limit, or
> alternatively clip numbers to the maximum.
I've added some documentation now, I'm not sure the interface is
perfect, but it should work.
>> + optlen = sizeof (opt_time);
>> + optval = &opt_time;
>> + }
>> +
>
> I think this needs a #if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO),
> for systems that don't have those. Alternatively, if all systems have
> those, it seems to me that the #ifdef in
I guess it should be conditional, so I've added the if in to getsockopt
and setsockopt.
>> +#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
>
> can be removed.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] Define SO_RCVTIMEO and SO_SNDTIMEO.
2022-09-17 8:05 [PATCH] Define SO_RCVTIMEO and SO_SNDTIMEO Christopher Baines
2022-09-17 9:40 ` Maxime Devos
2022-09-18 13:56 ` [PATCH v2] " Christopher Baines
@ 2022-09-18 14:17 ` Christopher Baines
2022-10-12 20:28 ` Ludovic Courtès
2 siblings, 1 reply; 7+ messages in thread
From: Christopher Baines @ 2022-09-18 14:17 UTC (permalink / raw)
To: guile-devel
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, scm_setsockopt): Include SO_RCVTIMEO and SO_SNDTIMEO in
docstring and handle them.
* doc/ref/posix.texi (Network Sockets and Communication): Document them.
---
doc/ref/posix.texi | 2 ++
libguile/socket.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 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..8451aadac 100644
--- a/libguile/socket.c
+++ b/libguile/socket.c
@@ -35,6 +35,7 @@
#endif
#include <unistd.h>
#include <sys/types.h>
+#include <sys/time.h>
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
@@ -502,6 +503,12 @@ SCM_DEFINE (scm_getsockopt, "getsockopt", 3, 0, 0,
"timeout support (ie.@: without @code{struct linger}), only\n"
"@var{enable} has an effect but the value in Guile is always a\n"
"pair.\n"
+ "@end defvar"
+ "\n"
+ "@defvar SO_RCVTIMEO\n"
+ "@defvarx SO_SNDTIMEO\n"
+ "@var{value} is a pair of integers @code{(@var{SECONDS}\n"
+ ". @var{MICROSECONDS})}.\n"
"@end defvar")
#define FUNC_NAME s_scm_getsockopt
{
@@ -522,6 +529,16 @@ SCM_DEFINE (scm_getsockopt, "getsockopt", 3, 0, 0,
if (getsockopt (fd, ilevel, ioptname, (void *) &optval, &optlen) == -1)
SCM_SYSERROR;
+#if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO)
+ if (ioptname == SO_RCVTIMEO || ioptname == SO_SNDTIMEO)
+ {
+ struct timeval *opt_time = (struct timeval *) &optval;
+
+ return scm_cons (scm_from_long (opt_time->tv_sec),
+ scm_from_long (opt_time->tv_usec));
+ }
+#endif
+
if (ilevel == SOL_SOCKET)
{
#ifdef SO_LINGER
@@ -590,6 +607,12 @@ SCM_DEFINE (scm_setsockopt, "setsockopt", 4, 0, 0,
"(ie.@: without @code{struct linger}), only @var{ENABLE} has an\n"
"effect but the value in Guile is always a pair.\n"
"@end defvar\n"
+ "\n"
+ "@defvar SO_RCVTIMEO\n"
+ "@defvarx SO_SNDTIMEO\n"
+ "@var{value} is a pair of integers @code{(@var{SECONDS}\n"
+ ". @var{MICROSECONDS})}.\n"
+ "@end defvar\n"
"\n"
"@c Note that we refer only to ``man ip'' here. On GNU/Linux it's\n"
"@c ``man 7 ip'' but on NetBSD it's ``man 4 ip''.\n"
@@ -633,6 +656,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 +707,19 @@ SCM_DEFINE (scm_setsockopt, "setsockopt", 4, 0, 0,
}
#endif
+#if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO)
+ if (ioptname == SO_RCVTIMEO || ioptname == SO_SNDTIMEO)
+ {
+ SCM_ASSERT_TYPE (scm_is_pair (value), value, SCM_ARG4, FUNC_NAME,
+ "value");
+ 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;
+ }
+#endif
+
if (optval == NULL)
{
/* Most options take an int. */
@@ -1768,6 +1806,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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3] Define SO_RCVTIMEO and SO_SNDTIMEO.
2022-09-18 14:17 ` [PATCH v3] " Christopher Baines
@ 2022-10-12 20:28 ` Ludovic Courtès
2022-10-13 10:28 ` Christopher Baines
0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2022-10-12 20:28 UTC (permalink / raw)
To: guile-devel
Hi,
Christopher Baines <mail@cbaines.net> skribis:
> 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, scm_setsockopt): Include SO_RCVTIMEO and SO_SNDTIMEO in
> docstring and handle them.
> * doc/ref/posix.texi (Network Sockets and Communication): Document them.
Applied, thanks!
Ludo’.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] Define SO_RCVTIMEO and SO_SNDTIMEO.
2022-10-12 20:28 ` Ludovic Courtès
@ 2022-10-13 10:28 ` Christopher Baines
0 siblings, 0 replies; 7+ messages in thread
From: Christopher Baines @ 2022-10-13 10:28 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
[-- Attachment #1: Type: text/plain, Size: 533 bytes --]
Ludovic Courtès <ludo@gnu.org> writes:
> Christopher Baines <mail@cbaines.net> skribis:
>
>> 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, scm_setsockopt): Include SO_RCVTIMEO and SO_SNDTIMEO in
>> docstring and handle them.
>> * doc/ref/posix.texi (Network Sockets and Communication): Document them.
>
> Applied, thanks!
Awesome, thanks :)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-10-13 10:28 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-17 8:05 [PATCH] Define SO_RCVTIMEO and SO_SNDTIMEO Christopher Baines
2022-09-17 9:40 ` Maxime Devos
2022-09-18 14:11 ` Christopher Baines
2022-09-18 13:56 ` [PATCH v2] " Christopher Baines
2022-09-18 14:17 ` [PATCH v3] " Christopher Baines
2022-10-12 20:28 ` Ludovic Courtès
2022-10-13 10:28 ` Christopher Baines
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).